Skip to content

Commit 8912e32

Browse files
authored
Merge pull request #748 from cv-on-hub/cv-spacing-hack
Update music_spacing_hack.lua
2 parents 386ce6d + 9e90d68 commit 8912e32

File tree

1 file changed

+77
-58
lines changed

1 file changed

+77
-58
lines changed
Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,51 @@ 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.10"
8-
finaleplugin.Date = "2024/05/03"
9-
finaleplugin.MinJWLuaVersion = 0.62
7+
finaleplugin.Version = "0.14"
8+
finaleplugin.Date = "2024/07/21"
9+
finaleplugin.MinJWLuaVersion = 0.70
1010
finaleplugin.Notes = [[
11-
There's a couple of __Music Spacing__ options that I
12-
change frequently for different spacing scenarios.
13-
This little hack uses a couple of hotkeys
14-
to do that very quickly, without a mouse and without navigating
15-
the whole __Document__ → __Document Options__ →
16-
__Music Spacing__ → __Avoid Collision of__ → menu/dialog system.
11+
Quickly change __music spacing__ options (with optional hotkeys).
12+
These options are otherwise only available using the messy combined
13+
menu/dialog/menu process of
14+
__Document__ → __Document Options__ → __Music Spacing__ → __Avoid Collision of__...
15+
16+
It also offers easy access to the __Automatic Music Spacing__ option
17+
which is otherwise only available at
18+
__Finale__ → __Settings__ → __Edit__ → __Automatic Music Spacing__.
1719
]]
18-
return "Music Spacing Hack...",
19-
"Music Spacing Hack",
20-
"A keyboard hack to quickly change music spacing options"
20+
return "Music Spacing Options...",
21+
"Music Spacing Options",
22+
"Quickly change music spacing options (with optional hotkeys)"
2123
end
2224

2325
local config = {
26+
dummy = "dummy",
2427
window_pos_x = false,
2528
window_pos_y = false,
2629
measurement_unit = finale.MEASUREMENTUNIT_DEFAULT,
2730
}
28-
local checks = { -- prefs Property key; hotkey; text description; type
31+
local checks = { -- spacing_prefs Property key; hotkey; text description; type
2932
{ "AvoidArticulations", "A", "Articulations" },
30-
{ "AvoidChords", "S", "Chords" },
31-
{ "AvoidClefs", "D", "Clefs" },
32-
{ "AvoidHiddenNotes", "W", "Hidden Notes" },
33-
{ "AvoidLedgerLines", "E", "Ledger Lines" },
34-
{ "AvoidLyrics", "R", "Lyrics" },
33+
{ "AvoidChords", "S", "Chords" },
34+
{ "AvoidClefs", "D", "Clefs" },
35+
{ "AvoidHiddenNotes", "W", "Hidden Notes" },
36+
{ "AvoidLedgerLines", "E", "Ledger Lines" },
37+
{ "AvoidLyrics", "R", "Lyrics" },
3538
}
3639
local unisons = {
37-
{ finale.UNISSPACE_NONE, "X", "None" },
38-
{ finale.UNISSPACE_DIFFERENTNOTEHEADS, "V", "Different Noteheads" },
39-
{ finale.UNISSPACE_ALLNOTEHEADS, "B", "All Noteheads" },
40+
{ finale.UNISSPACE_NONE, "V", "None" },
41+
{ finale.UNISSPACE_DIFFERENTNOTEHEADS, "B", "Different Noteheads" },
42+
{ finale.UNISSPACE_ALLNOTEHEADS, "N", "All Noteheads" },
4043
}
4144
local others = {
42-
{"change_hotkeys", "H", "Change Hotkeys"},
43-
{"AutomaticMusicSpacing", "Z", "Automatic Music Spacing"},
44-
{"script_info", "Q", "Show Script Info"}
45+
{ "change_hotkeys", "H", "Change Hotkeys" },
46+
{ "auto_spacing", "Z", "Automatic Music Spacing" },
47+
{ "script_info", "Q", "Show Script Info" },
48+
{ "manual_pos", "X", "Manual Positioning" }
4549
}
50+
local manual_pos = { "Clear", "Incorporate", "Ignore" } -- 0 .. 1 .. 2 popup
51+
4652
-- copy hotkeys to config
4753
for _, t in ipairs{checks, unisons, others} do
4854
for _, v in ipairs(t) do
@@ -57,9 +63,9 @@ local library = require("library.general_library")
5763
local script_name = library.calc_script_name()
5864
local name = plugindef():gsub("%.%.%.", "")
5965
local refocus_document = false
60-
local prefs = finale.FCMusicSpacingPrefs()
66+
local spacing_prefs = finale.FCMusicSpacingPrefs()
67+
spacing_prefs:LoadFirst()
6168
local gen_prefs = finale.FCGeneralPrefs()
62-
prefs:LoadFirst()
6369
gen_prefs:LoadFirst()
6470
configuration.get_user_settings(script_name, config)
6571

@@ -160,12 +166,12 @@ local function run_the_dialog()
160166
local m_offset = finenv.UI():IsOnMac() and 3 or 0
161167
local saved
162168

163-
local dialog = mixin.FCXCustomLuaWindow():SetTitle(name:sub(1, -5))
169+
local dialog = mixin.FCXCustomLuaWindow():SetTitle(name:sub(1, 13))
164170
dialog:SetMeasurementUnit(config.measurement_unit)
165171
-- local functions
166172
local function dy(diff) y = y + (diff and diff or 17) end
167173
local function show_info()
168-
utils.show_notes_dialog(dialog, "About " .. name, 300, 150)
174+
utils.show_notes_dialog(dialog, "About " .. name, 300, 175)
169175
refocus_document = true
170176
end
171177
local function cstat(cx, cy, ctext, cwide, cname)
@@ -175,14 +181,22 @@ local function run_the_dialog()
175181
dialog:CreateCheckbox(cx, cy, cname):SetText(ctext):SetWidth(cwide):SetCheck(check)
176182
end
177183
local function toggle_check(id)
178-
local ctl = dialog:GetControl(id)
179-
ctl:SetCheck((ctl:GetCheck() + 1) % 2)
184+
local c = dialog:GetControl(id)
185+
c:SetCheck((c:GetCheck() + 1) % 2)
180186
end
181187
local function toggle_unison(id)
182188
for i = unisons[1][1], unisons[3][1] do
183189
dialog:GetControl(tostring(i)):SetCheck(i == id and 1 or 0)
184190
end
185191
end
192+
local function fill_pos_popup()
193+
local popup = dialog:GetControl(others[4][1])
194+
popup:Clear()
195+
for _, v in ipairs(manual_pos) do
196+
popup:AddString(v .. " (" .. config.manual_pos .. ")")
197+
end
198+
popup:SetSelectedItem(spacing_prefs.ManualPositioning) -- 0, 1 or 2
199+
end
186200
local function change_keys()
187201
local ok, is_duplicate = true, true
188202
while ok and is_duplicate do -- wait for good choice in reassign()
@@ -191,109 +205,114 @@ local function run_the_dialog()
191205
if ok then
192206
for _, t in ipairs{checks, unisons, others} do
193207
for _, v in ipairs(t) do
194-
if v[1] ~= "script_info" then
208+
if v[1] ~= "script_info" and v[1] ~= "manual_pos" then
195209
dialog:GetControl("T" .. v[1]):SetText(config[tostring(v[1])])
196210
end
197211
end
198212
end
199213
else -- re-seed hotkeys from user config
200214
configuration.get_user_settings(script_name, config)
201215
end
216+
fill_pos_popup()
202217
dialog:GetControl("max_width"):SetKeyboardFocus()
203218
end
204219
local function key_check(ctl)
205220
local s = ctl:GetText():upper()
206-
if s:find("[^.P0-9]") then
207-
if s:find(config.change_hotkeys) then
208-
change_keys()
209-
elseif s:find(config.AutomaticMusicSpacing) then
210-
toggle_check("AutomaticMusicSpacing")
221+
if s:find("[^ .P0-9]") then
222+
if s:find(config.change_hotkeys) then change_keys()
223+
elseif s:find(config.auto_spacing) then toggle_check("auto_spacing")
211224
elseif s:find(config.script_info) then show_info()
225+
elseif s:find(config.manual_pos) then -- toggle ManPosn Popup
226+
local c = dialog:GetControl(others[4][1])
227+
c:SetSelectedItem((c:GetSelectedItem() + 1) % 3)
212228
else
213229
local matched = false
214-
for _, array in ipairs{{checks, toggle_check}, {unisons, toggle_unison}} do
230+
for _, t in ipairs{{checks, toggle_check}, {unisons, toggle_unison}} do
215231
if not matched then
216-
for _, v in ipairs(array[1]) do
232+
for _, v in ipairs(t[1]) do
217233
if s:find(config[tostring(v[1])]) then
218-
array[2](v[1])
234+
t[2](v[1]) -- run the matching toggle subroutine
219235
matched = true
220236
break
221237
end
222238
end
223239
end
224240
end
225241
end
226-
else -- save new "clean" numnber
242+
else -- save new "clean" number
227243
saved = s:sub(1, 8):lower() -- 8-chars max
228244
end
229245
ctl:SetText(saved)
230246
end
231-
cstat(0, y, "THE " .. name:upper(), 160, "title")
247+
cstat(10, y, name:upper(), 155, "title")
232248
dy(25)
233249
cstat(0, y, "Avoid Collisions of:", x[3])
234250
dialog:CreateButton(x[2] + x[3] - 50, y, "q"):SetText("?"):SetWidth(20)
235251
:AddHandleCommand(function() show_info() end)
236252
dy()
237253
for _, v in ipairs(checks) do
238254
cstat(0, y, config[v[1]], x[1], "T" .. v[1])
239-
ccheck(x[1], y, v[1], v[3], x[3], (prefs[v[1]] and 1 or 0))
255+
ccheck(x[1], y, v[1], v[3], x[3], (spacing_prefs[v[1]] and 1 or 0))
240256
dy()
241257
end
242258
cstat(x[1], y, "Unison Noteheads:", x[3])
243259
dy()
244260
for _, v in ipairs(unisons) do
245261
local id = tostring(v[1])
246262
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)
249-
:AddHandleCommand(function() toggle_unison(v[1]) end)
263+
ccheck(x[2], y, id, v[3], x[3] - x[1], (spacing_prefs.UnisonsMode == v[1]) and 1 or 0)
264+
dialog:GetControl(id):AddHandleCommand(function() toggle_unison(v[1]) end)
250265
dy()
251266
end
252267
dy(8)
253268
cstat(0, y, "Max Width:", x[2] + 25)
254-
dialog:CreateMeasurementEdit(x[2] + 27, y - m_offset, "max_width")
255-
:SetWidth(90):SetMeasurementInteger(prefs.MaxMeasureWidth)
269+
dialog:CreateMeasurementEdit(x[2] + 27, y - m_offset, "max_width"):SetWidth(105)
270+
:SetMeasurementInteger(spacing_prefs.MaxMeasureWidth)
256271
:AddHandleCommand(function(self) key_check(self) end)
257272
saved = dialog:GetControl("max_width"):GetText()
258273
dy(25)
259274
cstat(x[2] - 10, y, "Units:", 37)
260-
dialog:CreateMeasurementUnitPopup(x[2] + 27, y, "popup"):SetWidth(90)
275+
dialog:CreateMeasurementUnitPopup(x[2] + 27, y, "popup"):SetWidth(105)
261276
:AddHandleCommand(function()
262277
saved = dialog:GetControl("max_width"):GetText()
263278
end)
264279
dy(25)
280+
cstat(3, y, "Man. Posn:", x[2] + 27) -- "Manual Positioning" popup
281+
local manpos = dialog:CreatePopup(x[2] + 27, y, others[4][1]):SetWidth(105)
282+
fill_pos_popup() -- add menu items
283+
dy(25)
265284
cstat(0, y, config.change_hotkeys, x[2], "Tchange_hotkeys")
266285
dialog:CreateButton(x[1], y):SetText("Change Hotkeys"):SetWidth(100)
267286
:AddHandleCommand(function() change_keys() end)
268287
dy(22)
269-
local val = others[2]
288+
local val = others[2] -- AUTOMATIC MUSIC SPACING
270289
cstat(0, y, config[val[1]], x[1], "T" .. val[1])
271-
ccheck(x[1], y, val[1], val[3], x[3], (gen_prefs[val[1]] and 1 or 0))
290+
ccheck(x[1], y, val[1], val[3], x[3], (gen_prefs.AutomaticMusicSpacing and 1 or 0))
272291

273292
dialog:CreateOkButton()
274293
dialog:CreateCancelButton()
275294
dialog_set_position(dialog)
276295
dialog:RegisterInitWindow(function(self)
277296
self:GetControl("max_width"):SetKeyboardFocus()
278-
local q = self:GetControl("q")
279-
local bold = q:CreateFontInfo():SetBold(true)
280-
q:SetFont(bold)
297+
local bold = self:GetControl("q"):CreateFontInfo():SetBold(true)
298+
self:GetControl("q"):SetFont(bold)
281299
self:GetControl("title"):SetFont(bold)
282300
end)
283301
dialog:RegisterHandleOkButtonPressed(function(self)
284302
for _, v in ipairs(checks) do
285-
prefs[v[1]] = (self:GetControl(v[1]):GetCheck() == 1)
303+
spacing_prefs[v[1]] = (self:GetControl(v[1]):GetCheck() == 1)
286304
end
287305
for _, v in ipairs(unisons) do
288306
if (self:GetControl(tostring(v[1])):GetCheck() == 1) then
289-
prefs.UnisonsMode = v[1] -- matched the active Mode setting
307+
spacing_prefs.UnisonsMode = v[1] -- matched the active Mode setting
290308
break
291309
end
292310
end
293311
local n = self:GetControl("max_width"):GetMeasurementInteger()
294-
prefs.MaxMeasureWidth = math.max(n, 50)
295-
prefs:Save()
296-
gen_prefs.AutomaticMusicSpacing = (self:GetControl("AutomaticMusicSpacing"):GetCheck() == 1)
312+
spacing_prefs.MaxMeasureWidth = math.max(n, 50)
313+
spacing_prefs.ManualPositioning = manpos:GetSelectedItem()
314+
spacing_prefs:Save()
315+
gen_prefs.AutomaticMusicSpacing = (self:GetControl("auto_spacing"):GetCheck() == 1)
297316
gen_prefs:Save()
298317
config.measurement_unit = self:GetMeasurementUnit()
299318
end)

0 commit comments

Comments
 (0)