@@ -4,8 +4,8 @@ function plugindef()
4
4
finaleplugin .Author = " Carl Vine after Michael McClennan & Jacob Winkler"
5
5
finaleplugin .AuthorURL = " https://carlvine.com/lua/"
6
6
finaleplugin .Copyright = " https://creativecommons.org/licenses/by/4.0/"
7
- finaleplugin .Version = " v0.13 "
8
- finaleplugin .Date = " 2024/01/15 "
7
+ finaleplugin .Version = " v0.19 "
8
+ finaleplugin .Date = " 2024/01/31 "
9
9
finaleplugin .MinJWLuaVersion = 0.62
10
10
finaleplugin .Notes = [[
11
11
Copy the current selection and paste it consecutively
@@ -57,24 +57,25 @@ Key Commands:
57
57
info_notes = info_notes :gsub (" \n %s*" , " " ):gsub (" *" , " \n " ):gsub (" @t" , " \t " )
58
58
.. " \n (" .. finaleplugin .Version .. " )"
59
59
60
- -- luacheck: ignore 11./global_dialog 11./global_selection
61
- global_timer_id = 1
62
-
63
60
local configuration = require (" library.configuration" )
64
61
local mixin = require (" library.mixin" )
65
- local script_name = " ostinato_maker"
62
+ local library = require (" library.general_library" )
63
+ local script_name = library .calc_script_name ()
64
+ local dialog , current_selection
66
65
67
66
local config = {
68
- num_repeats = 1 ,
67
+ num_repeats = 1 ,
68
+ timer_id = 1 ,
69
69
window_pos_x = false ,
70
70
window_pos_y = false ,
71
71
}
72
72
local dialog_options = { -- and populate config values (unchecked)
73
- " copy_articulations" , " copy_expressions" , " copy_smartshapes" , " copy_lyrics" , " copy_chords"
73
+ " copy_articulations" , " copy_expressions" , " copy_smartshapes" ,
74
+ " copy_lyrics" , " copy_chords"
74
75
}
75
76
for _ , v in ipairs (dialog_options ) do config [v ] = 0 end -- (default unchecked)
76
77
77
- local bounds = { -- primary region selection boundary
78
+ local bounds = { -- primary region selection boundary properties
78
79
" StartStaff" , " StartMeasure" , " StartMeasurePos" ,
79
80
" EndStaff" , " EndMeasure" , " EndMeasurePos" ,
80
81
}
@@ -87,15 +88,15 @@ local function copy_region_bounds()
87
88
return copy
88
89
end
89
90
90
- function dialog_set_position (dialog )
91
+ local function dialog_set_position ()
91
92
if config .window_pos_x and config .window_pos_y then
92
93
dialog :StorePosition ()
93
94
dialog :SetRestorePositionOnlyData (config .window_pos_x , config .window_pos_y )
94
95
dialog :RestorePosition ()
95
96
end
96
97
end
97
98
98
- function dialog_save_position (dialog )
99
+ local function dialog_save_position ()
99
100
dialog :StorePosition ()
100
101
config .window_pos_x = dialog .StoredX
101
102
config .window_pos_y = dialog .StoredY
@@ -276,8 +277,9 @@ local function paste_many_copies()
276
277
local undo_str = " Ostinato Maker " .. selection_id ()
277
278
finenv .StartNewUndoBlock (undo_str , false )
278
279
-- ---- DO THE WORK
279
- if rgn .EndMeasurePos >= measure_duration (rgn .EndMeasure ) then
280
- rgn .EndMeasurePos = measure_duration (rgn .EndMeasure ) - 1
280
+ local m_d = measure_duration (rgn .EndMeasure )
281
+ if rgn .EndMeasurePos >= m_d then
282
+ rgn .EndMeasurePos = m_d - 1
281
283
end
282
284
rgn :CopyMusic () -- save a copy of the current selection
283
285
local duration = region_duration (rgn )
@@ -309,35 +311,36 @@ end
309
311
local function on_timer ()
310
312
local changed = false
311
313
for _ , v in ipairs (bounds ) do
312
- if global_selection [v ] ~= finenv .Region ()[v ] then
314
+ if current_selection [v ] ~= finenv .Region ()[v ] then
313
315
changed = true
314
316
break
315
317
end
316
318
end
317
319
if changed then
318
- global_selection = copy_region_bounds ()
319
- global_dialog :GetControl (" info" )
320
+ current_selection = copy_region_bounds ()
321
+ dialog :GetControl (" info" )
320
322
:SetText (" Selection " .. selection_id () .. " \n " .. staff_id ())
321
323
end
322
324
end
323
325
324
- local function create_dialog_box ()
326
+ local function create_dialog ()
325
327
local edit_x , e_wide , y_step = 110 , 40 , 18
326
328
local y_offset = finenv .UI ():IsOnMac () and 3 or 0
327
- local save_rpt , answer = config .num_repeats , {}
328
- local dialog = mixin .FCXCustomLuaWindow ():SetTitle (plugindef ())
329
+ local save_rpt = config .num_repeats
330
+ local name = plugindef ():gsub (" %.%.%." , " " )
331
+ dialog = mixin .FCXCustomLuaWindow ():SetTitle (name )
329
332
local y = 0
330
333
local function flip_check (id )
331
- local ctl = answer [ dialog_options [id ]]
334
+ local ctl = dialog : GetControl ( dialog_options [id ])
332
335
ctl :SetCheck ((ctl :GetCheck () + 1 ) % 2 )
333
336
end
334
337
local function check_all_state (state )
335
338
for _ , v in ipairs (dialog_options ) do
336
- answer [ v ] :SetCheck (state )
339
+ dialog : GetControl ( v ) :SetCheck (state )
337
340
end
338
341
end
339
342
local function info_dialog ()
340
- finenv .UI ():AlertInfo (info_notes , " About " .. plugindef () )
343
+ finenv .UI ():AlertInfo (info_notes , " About " .. name )
341
344
end
342
345
local function key_check (ctl ) -- some stray key commands
343
346
local s = ctl :GetText ():lower ()
@@ -370,40 +373,39 @@ local function create_dialog_box()
370
373
:AddHandleCommand (function (self ) key_check (self ) end )
371
374
dialog :CreateStatic (e_wide , y + 2 ):SetText (" times" ):SetWidth (edit_x )
372
375
for _ , v in ipairs (dialog_options ) do
373
- answer [ v ] = dialog :CreateCheckbox (edit_x , y ):SetCheck (config [v ])
376
+ dialog :CreateCheckbox (edit_x , y , v ):SetCheck (config [v ])
374
377
:SetText (v :sub (6 , - 1 ):gsub (" ^%l" , string.upper )):SetWidth (90 )
375
378
y = y + y_step
376
379
end
377
380
local q = dialog :CreateButton (0 , y - 19 ):SetText (" ?" ):SetWidth (20 )
378
381
:AddHandleCommand (function () info_dialog () end )
379
382
dialog :CreateOkButton ()
380
383
dialog :CreateCancelButton ()
381
- dialog_set_position (dialog )
384
+ dialog_set_position ()
382
385
dialog :RegisterHandleTimer (on_timer )
383
386
dialog :RegisterInitWindow (function ()
384
387
q :SetFont (q :CreateFontInfo ():SetBold (true ))
385
388
num_repeats :SetKeyboardFocus ()
386
- dialog :SetTimer (global_timer_id , 125 )
389
+ dialog :SetTimer (config . timer_id , 125 )
387
390
end )
388
391
dialog :RegisterCloseWindow (function ()
389
- dialog_save_position (dialog )
390
- dialog :StopTimer (global_timer_id )
392
+ dialog_save_position ()
393
+ dialog :StopTimer (config . timer_id )
391
394
end )
392
395
dialog :RegisterHandleOkButtonPressed (function ()
393
396
config .num_repeats = num_repeats :GetInteger ()
394
397
for _ , v in ipairs (dialog_options ) do
395
- config [v ] = answer [ v ] :GetCheck ()
398
+ config [v ] = dialog : GetControl ( v ) :GetCheck ()
396
399
end
397
400
paste_many_copies ()
398
401
end )
399
- return dialog
400
402
end
401
403
402
404
local function make_ostinato ()
403
405
configuration .get_user_settings (script_name , config , true )
404
- global_selection = global_selection or copy_region_bounds ()
405
- global_dialog = global_dialog or create_dialog_box ()
406
- global_dialog :RunModeless ()
406
+ current_selection = copy_region_bounds ()
407
+ create_dialog ()
408
+ dialog :RunModeless ()
407
409
end
408
410
409
411
make_ostinato ()
0 commit comments