@@ -4,15 +4,15 @@ function plugindef()
44 finaleplugin .Author = " Carl Vine"
55 finaleplugin .AuthorURL = " https://carlvine.com/lua"
66 finaleplugin .Copyright = " https://creativecommons.org/licenses/by/4.0/"
7- finaleplugin .Version = " 0.10 "
7+ finaleplugin .Version = " 0.11 "
88 finaleplugin .Date = " 2024/07/17"
99 finaleplugin .MinJWLuaVersion = 0.70
1010 finaleplugin .Notes = [[
11- Make dynamic marks in the selection louder or softer in stages.
12- This functionality is buried within __JWChange__ but is useful
13- enough to bring closer to the surface .
11+ Make dynamic marks in the selection louder or softer by stages.
12+ This functionality is buried within the __JW Change__ plugin
13+ but is useful enough to make it accessible more easily .
1414 This script works similarly but allows jumping up to 9 _levels_ at once.
15- The dynamic range is from __pppppp__ to __ffffff__, though scores using
15+ Dynamics range from __pppppp__ to __ffffff__, though scores using
1616 older (non-__SMuFL__) fonts are restricted to the range __pppp__-__ffff__.
1717
1818 To repeat the previous level shift without a confirmation dialog
@@ -32,7 +32,6 @@ local config = {
3232 direction = 0 , -- 0 == "Louder", 1 = "Softer"
3333 levels = 1 , -- how many "levels" louder or softer
3434 create_new = false , -- don't create new dynamics without permission
35- timer_id = 1 , -- timer to track selected region changes (always Modeless)
3635 window_pos_x = false ,
3736 window_pos_y = false ,
3837}
@@ -44,7 +43,6 @@ local library = require("library.general_library")
4443local script_name = library .calc_script_name ()
4544local name = plugindef ():gsub (" %.%.%." , " " )
4645local selection
47- local saved_bounds = {}
4846local dyn_char = library .is_font_smufl_font () and
4947 { -- char numbers for SMuFL dynamics (1-14)
5048 0xe527 , 0xe528 , 0xe529 , 0xe52a , 0xe52b , 0xe520 , 0xe52c , -- pppppp -> mp
@@ -79,16 +77,8 @@ local function get_staff_name(staff_num)
7977 return str
8078end
8179
82- local function set_bounds ()
83- local bounds = { -- primary region selection boundaries
84- " StartStaff" , " StartMeasure" , " StartMeasurePos" ,
85- " EndStaff" , " EndMeasure" , " EndMeasurePos" ,
86- }
80+ local function update_selection ()
8781 local rgn = finenv .Region ()
88- for _ , property in ipairs (bounds ) do
89- saved_bounds [property ] = rgn [property ]
90- end
91- -- update selection
9282 selection = " no staff, no selection" -- default
9383 if not rgn :IsEmpty () then
9484 selection = get_staff_name (rgn .StartStaff )
@@ -147,7 +137,7 @@ local function change_dynamics(dialog)
147137 if config .direction == 1 then shift = - shift end -- softer not louder
148138 local dyn_len = library .is_font_smufl_font () and 3 or 2 -- dynamic max string length
149139
150- -- match all target dynamics from existing expressions
140+ -- match all target dynamics within existing dynamic expressions
151141 local function match_dynamics (hidden ) -- hidden is true or false
152142 local mode = hidden and " hide" or " show"
153143 local exp_defs = mixin .FCMTextExpressionDefs ()
@@ -170,10 +160,12 @@ local function change_dynamics(dialog)
170160 end
171161 match_dynamics (true )
172162 match_dynamics (false )
173- -- scan the selection for dynamics and change them
163+ -- start
164+ update_selection () -- update current score selection
174165 finenv .StartNewUndoBlock (string.format (" Dynamics %s%d %s" ,
175166 (config .direction == 0 and " +" or " -" ), config .levels , selection )
176167 )
168+ -- scan the selection for dynamics and change them
177169 for e in loadallforregion (mixin .FCMExpressions (), finenv .Region ()) do
178170 if expression .is_dynamic (e ) then
179171 local exp_def = e :CreateTextExpressionDef ()
@@ -196,7 +188,7 @@ local function change_dynamics(dialog)
196188 if dialog then -- update checkbox condition
197189 dialog :GetControl (" create_new" ):SetCheck (1 )
198190 end
199- local t = utf8.char (dyn_char [target ])
191+ local t = utf8.char (dyn_char [target ]) -- dynamic text char
200192 found [mode ][target ] = create_dynamic_def (t , hidden )
201193 e :SetID (found [mode ][target ]):Save ()
202194 end
@@ -225,32 +217,22 @@ local function run_the_dialog()
225217 local function cstat (horiz , vert , wide , str ) -- dialog static text
226218 return dialog :CreateStatic (horiz , vert ):SetWidth (wide ):SetText (str )
227219 end
228- local function flip_direction ()
229- local n = ctl .direction :GetSelectedItem ()
230- ctl .direction :SetSelectedItem ((n + 1 ) % 2 )
231- end
232220 local function key_subs ()
233221 local s = ctl .levels :GetText ():lower ()
234222 if s :find (" [^1-9]" ) then
235223 if s :find (hotkey .show_info ) then show_info ()
236- elseif s :find (hotkey .direction ) then flip_direction ()
224+ elseif s :find (hotkey .direction ) then
225+ local n = ctl .direction :GetSelectedItem ()
226+ ctl .direction :SetSelectedItem ((n + 1 ) % 2 )
237227 elseif s :find (hotkey .create_new ) then
238- local c = ctl .create_new
239- c :SetCheck ((c : GetCheck () + 1 ) % 2 )
228+ local n = ctl .create_new : GetCheck ()
229+ ctl . create_new :SetCheck ((n + 1 ) % 2 )
240230 end
241231 else
242232 save = s :sub (- 1 ) -- save last entered char only
243233 end
244234 ctl .levels :SetText (save )
245235 end
246- local function on_timer () -- track changes in selected region
247- for k , v in pairs (saved_bounds ) do
248- if finenv .Region ()[k ] ~= v then -- selection changed
249- set_bounds () -- update selection tracker
250- break -- all done
251- end
252- end
253- end
254236 ctl .title = cstat (10 , y , 120 , name :upper ())
255237 yd ()
256238 -- RadioButtonGroup
@@ -265,33 +247,31 @@ local function run_the_dialog()
265247 cstat (65 , y , 55 , " Levels:" )
266248 ctl .levels = dialog :CreateEdit (110 , y - m_offset ):SetText (config .levels ):SetWidth (20 )
267249 :AddHandleCommand (function () key_subs () end )
268- yd (21 )
250+ yd ()
269251 ctl .q = dialog :CreateButton (110 , y ):SetText (" ?" ):SetWidth (20 )
270252 :AddHandleCommand (function () show_info () end )
271- yd (21 )
253+ yd (23 )
272254 ctl .create_new = dialog :CreateCheckbox (0 , y , " create_new" )
273- :SetText (" Enable creation of new\n dynamic expressions" )
274- :SetWidth (150 ):SetCheck (config .create_new and 1 or 0 )
275- :SetHeight (30 )
255+ :SetWidth (145 ):SetCheck (config .create_new and 1 or 0 )
256+ :SetText (" Enable Creation of New" )
257+ yd (13 )
258+ cstat (13 , y , 135 , " Dynamic Expressions (" .. hotkey .create_new .. " )" )
276259 -- wrap it up
277260 dialog :CreateOkButton () :SetText (" Apply" )
278261 dialog :CreateCancelButton ():SetText (" Close" )
279- dialog :RegisterInitWindow (function (self )
280- self :SetTimer (config .timer_id , 125 )
262+ dialog :RegisterInitWindow (function ()
281263 local bold = ctl .q :CreateFontInfo ():SetBold (true )
282264 ctl .q :SetFont (bold )
283265 ctl .title :SetFont (bold )
284266 end )
285267 dialog_set_position (dialog )
286- dialog :RegisterHandleTimer (on_timer )
287268 dialog :RegisterHandleOkButtonPressed (function ()
288269 config .direction = ctl .direction :GetSelectedItem ()
289270 config .levels = ctl .levels :GetInteger ()
290271 config .create_new = (ctl .create_new :GetCheck () == 1 )
291272 change_dynamics (dialog )
292273 end )
293274 dialog :RegisterCloseWindow (function (self )
294- self :StopTimer (config .timer_id )
295275 dialog_save_position (self )
296276 end )
297277 dialog :RunModeless ()
@@ -301,8 +281,7 @@ local function dynamic_levels()
301281 configuration .get_user_settings (script_name , config , true )
302282 local qim = finenv .QueryInvokedModifierKeys
303283 local mod_key = qim and (qim (finale .CMDMODKEY_ALT ) or qim (finale .CMDMODKEY_SHIFT ))
304- set_bounds () -- track current selected region
305- --
284+
306285 if mod_key then
307286 change_dynamics (nil )
308287 else
0 commit comments