Skip to content

Commit c515e00

Browse files
committed
Update music_spacing_hack.lua
Minor amendments: keymap for script_info; neatened key matching routine; single primary function.
1 parent 4d1bd2b commit c515e00

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

src/music_spacing_hack.lua

+27-36
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function plugindef()
44
finaleplugin.Author = "Carl Vine"
55
finaleplugin.AuthorURL = "http://carlvine.com/lua/"
66
finaleplugin.Copyright = "https://creativecommons.org/licenses/by/4.0/"
7-
finaleplugin.Version = "0.06"
8-
finaleplugin.Date = "2024/04/26"
7+
finaleplugin.Version = "0.10"
8+
finaleplugin.Date = "2024/05/03"
99
finaleplugin.MinJWLuaVersion = 0.62
1010
finaleplugin.Notes = [[
1111
There's a couple of __Music Spacing__ options that I
@@ -21,7 +21,6 @@ function plugindef()
2121
end
2222

2323
local config = {
24-
change_hotkeys = "H",
2524
window_pos_x = false,
2625
window_pos_y = false,
2726
measurement_unit = finale.MEASUREMENTUNIT_DEFAULT,
@@ -41,7 +40,8 @@ local unisons = {
4140
}
4241
local others = {
4342
{"change_hotkeys", "H", "Change Hotkeys"},
44-
{"AutomaticMusicSpacing", "Z", "Automatic Music Spacing"}
43+
{"AutomaticMusicSpacing", "Z", "Automatic Music Spacing"},
44+
{"script_info", "Q", "Show Script Info"}
4545
}
4646
-- copy hotkeys to config
4747
for _, t in ipairs{checks, unisons, others} do
@@ -164,13 +164,13 @@ local function run_the_dialog()
164164
dialog:SetMeasurementUnit(config.measurement_unit)
165165
-- local functions
166166
local function dy(diff) y = y + (diff and diff or 17) end
167-
local function cstat(cx, cy, ctext, cwide, cname)
168-
dialog:CreateStatic(cx, cy, cname):SetText(ctext):SetWidth(cwide)
169-
end
170167
local function show_info()
171168
utils.show_notes_dialog(dialog, "About " .. name, 300, 150)
172169
refocus_document = true
173170
end
171+
local function cstat(cx, cy, ctext, cwide, cname)
172+
dialog:CreateStatic(cx, cy, cname):SetText(ctext):SetWidth(cwide)
173+
end
174174
local function ccheck(cx, cy, cname, ctext, cwide, check)
175175
dialog:CreateCheckbox(cx, cy, cname):SetText(ctext):SetWidth(cwide):SetCheck(check)
176176
end
@@ -183,19 +183,18 @@ local function run_the_dialog()
183183
dialog:GetControl(tostring(i)):SetCheck(i == id and 1 or 0)
184184
end
185185
end
186-
local function rename_checkboxes(array)
187-
for _, v in ipairs(array) do
188-
dialog:GetControl("T" .. v[1]):SetText(config[tostring(v[1])])
189-
end
190-
end
191186
local function change_keys()
192187
local ok, is_duplicate = true, true
193188
while ok and is_duplicate do -- wait for good choice in reassign()
194189
ok, is_duplicate = reassign_keys(dialog)
195190
end
196191
if ok then
197192
for _, t in ipairs{checks, unisons, others} do
198-
rename_checkboxes(t)
193+
for _, v in ipairs(t) do
194+
if v[1] ~= "script_info" then
195+
dialog:GetControl("T" .. v[1]):SetText(config[tostring(v[1])])
196+
end
197+
end
199198
end
200199
else -- re-seed hotkeys from user config
201200
configuration.get_user_settings(script_name, config)
@@ -209,21 +208,17 @@ local function run_the_dialog()
209208
change_keys()
210209
elseif s:find(config.AutomaticMusicSpacing) then
211210
toggle_check("AutomaticMusicSpacing")
212-
elseif s:find("?") then show_info()
211+
elseif s:find(config.script_info) then show_info()
213212
else
214-
local got = false
215-
for _, v in ipairs(checks) do
216-
if s:find(config[v[1]]) then
217-
toggle_check(v[1])
218-
got = true
219-
break
220-
end
221-
end
222-
if not got then
223-
for _, v in ipairs(unisons) do
224-
if s:find(config[tostring(v[1])]) then
225-
toggle_unison(v[1])
226-
break
213+
local matched = false
214+
for _, array in ipairs{{checks, toggle_check}, {unisons, toggle_unison}} do
215+
if not matched then
216+
for _, v in ipairs(array[1]) do
217+
if s:find(config[tostring(v[1])]) then
218+
array[2](v[1])
219+
matched = true
220+
break
221+
end
227222
end
228223
end
229224
end
@@ -247,10 +242,10 @@ local function run_the_dialog()
247242
cstat(x[1], y, "Unison Noteheads:", x[3])
248243
dy()
249244
for _, v in ipairs(unisons) do
250-
cstat(x[1], y, config[tostring(v[1])], x[2], "T" .. v[1])
251-
local check = (prefs.UnisonsMode == v[1]) and 1 or 0
252-
ccheck(x[2], y, tostring(v[1]), v[3], x[3] - x[1], check)
253-
dialog:GetControl(tostring(v[1]))
245+
local id = tostring(v[1])
246+
cstat(x[1], y, config[id], x[2], "T" .. v[1])
247+
ccheck(x[2], y, id, v[3], x[3] - x[1], (prefs.UnisonsMode == v[1]) and 1 or 0)
248+
dialog:GetControl(id)
254249
:AddHandleCommand(function() toggle_unison(v[1]) end)
255250
dy()
256251
end
@@ -304,11 +299,7 @@ local function run_the_dialog()
304299
end)
305300
dialog:RegisterCloseWindow(function(self) dialog_save_position(self) end)
306301
dialog:ExecuteModal()
307-
end
308-
309-
local function spacing_hack()
310-
while run_the_dialog() do end
311302
if refocus_document then finenv.UI():ActivateDocumentWindow() end
312303
end
313304

314-
spacing_hack()
305+
run_the_dialog()

0 commit comments

Comments
 (0)