@@ -4,8 +4,8 @@ function plugindef()
44 finaleplugin .Author = " Carl Vine"
55 finaleplugin .AuthorURL = " https://carlvine.com/lua/"
66 finaleplugin .Copyright = " CC0 https://creativecommons.org/publicdomain/zero/1.0/"
7- finaleplugin .Version = " 0.07 "
8- finaleplugin .Date = " 2024/06/04 "
7+ finaleplugin .Version = " 0.08 "
8+ finaleplugin .Date = " 2024/06/08 "
99 finaleplugin .MinJWLuaVersion = 0.70
1010 finaleplugin .Notes = [[
1111 Make dynamic marks in the selection louder or softer by stages.
@@ -31,7 +31,7 @@ local config = {
3131 direction = 0 , -- 0 == "Louder", 1 = "Softer"
3232 levels = 1 , -- how many "levels" louder or softer
3333 create_new = false , -- don't create new dynamics without permission
34- timer_id = 1 ,
34+ timer_id = 1 , -- timer to track selected region changes (always Modeless)
3535 window_pos_x = false ,
3636 window_pos_y = false ,
3737}
@@ -45,11 +45,11 @@ local name = plugindef():gsub("%.%.%.", "")
4545local selection
4646local saved_bounds = {}
4747local dyn_char = library .is_font_smufl_font () and
48- { -- char number for SMuFL dynamics (1-14)
48+ { -- char numbers for SMuFL dynamics (1-14)
4949 0xe527 , 0xe528 , 0xe529 , 0xe52a , 0xe52b , 0xe520 , 0xe52c , -- pppppp -> mp
5050 0xe52d , 0xe522 , 0xe52f , 0xe530 , 0xe531 , 0xe532 , 0xe533 , -- mf -> ffffff
5151 } or
52- { -- char number for non-SMuFL dynamics (1-10)
52+ { -- char numbers for non-SMuFL dynamics (1-10)
5353 175 , 184 , 185 , 112 , 80 , -- pppp -> mp
5454 70 , 102 , 196 , 236 , 235 -- mf -> ffff
5555 }
@@ -102,23 +102,24 @@ local function track_selection()
102102end
103103
104104local function create_dynamics_alert (dialog )
105- local msg = " Do you want this script to create additional dynamic expressions "
106- .. " as required? (A positive reply will be saved and used if this question arises again)."
105+ local msg = " Do you want this script to create "
106+ .. " additional dynamic expressions as required? "
107+ .. " (A positive reply will be saved and used if this question arises again)."
107108 local ok = dialog and
108109 dialog :CreateChildUI ():AlertYesNo (msg , nil )
109110 or finenv .UI ():AlertYesNo (msg , nil )
110111 return ok == finale .YESRETURN
111112end
112113
113- local function create_exp_def ( exp_name )
114+ local function create_dyn_def ( expression_text )
114115 local cat_def = finale .FCCategoryDef ()
115116 cat_def :Load (1 ) -- default "DYNAMIC" category
116117 local finfo = finale .FCFontInfo ()
117118 cat_def :GetMusicFontInfo (finfo )
118119 local str = finale .FCString ()
119120 str .LuaString = " ^fontMus"
120121 .. finfo :CreateEnigmaString (finale .FCString ()).LuaString
121- .. exp_name
122+ .. expression_text
122123 local ted = mixin .FCMTextExpressionDef ()
123124 ted :SaveNewTextBlock (str )
124125 :AssignToCategory (cat_def )
@@ -130,27 +131,27 @@ end
130131
131132local function change_dynamics (dialog )
132133 local found = {} -- collate matched dynamic expressions
133- local matches = 0 -- count successes
134+ local match_count = 0
134135 local shift = config .levels -- how many dynamic levels to move?
135- if config .direction == 1 then shift = - shift end -- getting softer not louder
136- local dyn_len = library .is_font_smufl_font () and 3 or 2 -- max length of dynamic string
136+ if config .direction == 1 then shift = - shift end -- softer not louder
137+ local dyn_len = library .is_font_smufl_font () and 3 or 2 -- dynamic max string length
137138 -- match all target dynamics from existing expressions
138139 local exp_defs = mixin .FCMTextExpressionDefs ()
139140 exp_defs :LoadAll ()
140141 for exp_def in each (exp_defs ) do
141142 if exp_def .CategoryID == 1 and exp_def .UseCategoryFont then -- "standard" dynamic?
142143 local str = exp_def :CreateTextString ()
143144 str :TrimEnigmaTags ()
144- if str .LuaString :len () <= dyn_len then -- dynamic length
145- for i , v in ipairs (dyn_char ) do -- match all required characters
145+ if str .LuaString :len () <= dyn_len then -- within max dynamic length
146+ for i , v in ipairs (dyn_char ) do -- check all dynamic glyphs
146147 if not found [i ] and str .LuaString == utf8.char (v ) then
147148 found [i ] = exp_def .ItemNo -- matched char
148- matches = matches + 1
149+ match_count = match_count + 1
149150 end
150151 end
151152 end
152- if matches >= # dyn_char then break end
153153 end
154+ if match_count >= # dyn_char then break end -- all collected
154155 end
155156 -- scan the selection for dynamics and change them
156157 finenv .StartNewUndoBlock (string.format (" %s %s%d %s" , name ,
@@ -173,11 +174,11 @@ local function change_dynamics(dialog)
173174 config .create_new = create_dynamics_alert (dialog )
174175 end
175176 if config .create_new then -- create missing dynamic exp_def
176- found [target ] = create_exp_def (utf8.char (dyn_char [target ]))
177+ found [target ] = create_dyn_def (utf8.char (dyn_char [target ]))
177178 e :SetID (found [target ]):Save ()
178179 end
179180 end
180- break
181+ break -- all done for this target dynamic
181182 end
182183 end
183184 end
@@ -212,7 +213,7 @@ local function run_the_dialog()
212213 elseif s :find (hotkey .direction ) then flip_direction ()
213214 end
214215 else
215- save = s :sub (- 1 )
216+ save = s :sub (- 1 ) -- save last entered char only
216217 end
217218 ctl .levels :SetText (save )
218219 end
0 commit comments