From 23550951499c0d1f87c0e8af183064755ef81df9 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Sun, 22 May 2022 09:24:35 -0500 Subject: [PATCH 1/7] transpose_by_step plus mixin fixes --- src/mixin/FCMCtrlPopup.lua | 8 +++- src/mixin/FCXCustomLuaWindow.lua | 2 +- src/transpose_by_step.lua | 79 ++++++++------------------------ 3 files changed, 26 insertions(+), 63 deletions(-) diff --git a/src/mixin/FCMCtrlPopup.lua b/src/mixin/FCMCtrlPopup.lua index cd9de7b8..90b08dac 100644 --- a/src/mixin/FCMCtrlPopup.lua +++ b/src/mixin/FCMCtrlPopup.lua @@ -143,17 +143,21 @@ end Adds multiple strings to the popup. @ self (FCMCtrlPopup) -@ ... (FCStrings|FCString|string|number) +@ ... (FCStrings|FCString|table|string|number) ]] function props:AddStrings(...) for i = 1, select("#", ...) do local v = select(i, ...) - mixin.assert_argument(v, {"string", "number", "FCString", "FCStrings"}, i + 1) + mixin.assert_argument(v, {"string", "number", "FCString", "FCStrings", "table"}, i + 1) if type(v) == "userdata" and v:ClassName() == "FCStrings" then for str in each(v) do mixin.FCMCtrlPopup.AddString(self, str) end + elseif type(v) == "table" then + for _, str in pairsbykeys(v) do + mixin.FCMCtrlPopup.AddString(self, str) + end else mixin.FCMCtrlPopup.AddString(self, v) end diff --git a/src/mixin/FCXCustomLuaWindow.lua b/src/mixin/FCXCustomLuaWindow.lua index 41258fc0..d11c336d 100644 --- a/src/mixin/FCXCustomLuaWindow.lua +++ b/src/mixin/FCXCustomLuaWindow.lua @@ -257,7 +257,7 @@ Automatically registers the dialog with `finenv.RegisterModelessDialog`. @ self (FCXCustomLuaWindow) : (boolean) ]] -props:ShowModeless() +function props:ShowModeless() finenv.RegisterModelessDialog(self) return mixin.FCMCustomLuaWindow.ShowModeless(self) end diff --git a/src/transpose_by_step.lua b/src/transpose_by_step.lua index 431c6474..77f33397 100644 --- a/src/transpose_by_step.lua +++ b/src/transpose_by_step.lua @@ -1,6 +1,6 @@ function plugindef() finaleplugin.RequireSelection = false - finaleplugin.HandlesUndo = true -- not recognized by JW Lua or RGP Lua v0.55 + finaleplugin.HandlesUndo = true -- not recognized by JW Lua or RGP Lua v0.55 finaleplugin.Author = "Robert Patterson" finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/" finaleplugin.Version = "1.1" @@ -30,24 +30,11 @@ function plugindef() Later versions of RGP Lua (0.58 or higher) ignore this configuration file (if it exists) and read the correct information from the Finale document. ]] - return "Transpose By Steps...", "Transpose By Steps", - "Transpose by the number of steps given, simplifying spelling as needed." + return "Transpose By Steps...", "Transpose By Steps", "Transpose by the number of steps given, simplifying spelling as needed." end -global_dialog = nil -global_number_of_steps_edit = nil - local modifier_keys_on_invoke = false -if not finenv.RetainLuaState then - context = - { - number_of_steps = nil, - window_pos_x = nil, - window_pos_y = nil - } -end - if not finenv.IsRGPLua then local path = finale.FCString() path:SetRunningLuaFolderPath() @@ -55,6 +42,7 @@ if not finenv.IsRGPLua then end local transposition = require("library.transposition") +local mixin = require("library.mixin") function do_transpose_by_step(global_number_of_steps_edit) if finenv.Region():IsEmpty() then @@ -85,73 +73,44 @@ function do_transpose_by_step(global_number_of_steps_edit) return success end +function on_ok() + do_transpose_by_step(global_dialog:GetControl("num_steps"):GetInteger()) +end + function create_dialog_box() - local str = finale.FCString() - local dialog = finale.FCCustomLuaWindow() - str.LuaString = "Transpose By Steps" - dialog:SetTitle(str) + local dialog = mixin.FCXCustomLuaWindow():SetTitle("Transpose By Steps") local current_y = 0 local x_increment = 105 -- number of steps - local static = dialog:CreateStatic(0, current_y + 2) - str.LuaString = "Number Of Steps:" - static:SetText(str) + dialog:CreateStatic(0, current_y + 2):SetText("Number Of Steps:") local edit_x = x_increment if finenv.UI():IsOnMac() then edit_x = edit_x + 4 end - global_number_of_steps_edit = dialog:CreateEdit(edit_x, current_y) - if context.number_of_steps and 0 ~= context.number_of_steps then - local str = finale.FCString() - str:AppendInteger(context.number_of_steps) - global_number_of_steps_edit:SetText(str) - end + dialog:CreateEdit(edit_x, current_y, "num_steps"):SetText("") -- ok/cancel dialog:CreateOkButton() dialog:CreateCancelButton() - if dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - dialog.OkButtonCanClose = modifier_keys_on_invoke - end + dialog:RegisterHandleOkButtonPressed(on_ok) return dialog end -function on_ok() - do_transpose_by_step(global_number_of_steps_edit:GetInteger()) -end - -function on_close() - if global_dialog:QueryLastCommandModifierKeys(finale.CMDMODKEY_ALT) or global_dialog:QueryLastCommandModifierKeys(finale.CMDMODKEY_SHIFT) then - finenv.RetainLuaState = false - else - context.number_of_steps = global_number_of_steps_edit:GetInteger() - global_dialog:StorePosition() - context.window_pos_x = global_dialog.StoredX - context.window_pos_y = global_dialog.StoredY - end -end - function transpose_by_step() modifier_keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if modifier_keys_on_invoke and context.number_of_steps then - do_transpose_by_step(context.number_of_steps) + if modifier_keys_on_invoke and global_dialog then + on_ok() return end - global_dialog = create_dialog_box() - if nil ~= context.window_pos_x and nil ~= context.window_pos_y then - global_dialog:StorePosition() - global_dialog:SetRestorePositionOnlyData(context.window_pos_x, context.window_pos_y) - global_dialog:RestorePosition() - end - global_dialog:RegisterHandleOkButtonPressed(on_ok) - if global_dialog.RegisterCloseWindow then - global_dialog:RegisterCloseWindow(on_close) + if not global_dialog then + global_dialog = create_dialog_box() end if finenv.IsRGPLua then - if nil ~= finenv.RetainLuaState then + if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after + global_dialog.OkButtonCanClose = modifier_keys_on_invoke + end + if global_dialog:ShowModeless() then finenv.RetainLuaState = true end - finenv.RegisterModelessDialog(global_dialog) - global_dialog:ShowModeless() else if finenv.Region():IsEmpty() then finenv.UI():AlertInfo("Please select a music region before running this script.", "Selection Required") From 6188b644796070d5dcbb0b3e37f7f7c26b9e6a30 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Sun, 22 May 2022 09:43:34 -0500 Subject: [PATCH 2/7] add transpose_chromatic --- src/transpose_chromatic.lua | 133 ++++++++---------------------------- 1 file changed, 27 insertions(+), 106 deletions(-) diff --git a/src/transpose_chromatic.lua b/src/transpose_chromatic.lua index 34eb8a0b..26133d8a 100644 --- a/src/transpose_chromatic.lua +++ b/src/transpose_chromatic.lua @@ -1,6 +1,6 @@ function plugindef() finaleplugin.RequireSelection = false - finaleplugin.HandlesUndo = true -- not recognized by JW Lua or RGP Lua v0.55 + finaleplugin.HandlesUndo = true -- not recognized by JW Lua or RGP Lua v0.55 finaleplugin.Author = "Robert Patterson" finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/" finaleplugin.Version = "1.1" @@ -29,8 +29,7 @@ function plugindef() Later versions of RGP Lua (0.58 or higher) ignore this configuration file (if it exists) and read the correct information from the Finale document. ]] - return "Transpose Chromatic...", "Transpose Chromatic", - "Chromatic transposition of selected region (supports microtone systems)." + return "Transpose Chromatic...", "Transpose Chromatic", "Chromatic transposition of selected region (supports microtone systems)." end if not finenv.RetainLuaState then @@ -74,27 +73,8 @@ if not finenv.RetainLuaState then {6,-2}, {6,-1}, {6,0}, {6,1}, -- 7ths {7,-1}, {7,0} -- octaves } - - context = - { - direction = nil, - interval_index = nil, - simplify = nil, - plus_octaves = nil, - preserve_originals = nil, - window_pos_x = nil, - window_pos_y = nil - } end --- global vars for modeless operation -direction_choice = nil -interval_choice = nil -do_simplify = nil -plus_octaves = nil -do_preserve = nil -global_dialog = nil - local modifier_keys_on_invoke = false if not finenv.IsRGPLua then @@ -105,84 +85,39 @@ end local transposition = require("library.transposition") local note_entry = require("library.note_entry") - -function add_strings_to_control(control, strings) - local str = finale.FCString() - for k, v in pairs(strings) do - str.LuaString = v - control:AddString(str) - end -end +local mixin = require("library.mixin") function create_dialog_box() - local str = finale.FCString() - local dialog = finale.FCCustomLuaWindow() -- global dialog for modeless operation - str.LuaString = "Transpose Chromatic" - dialog:SetTitle(str) + local dialog = mixin.FCXCustomLuaWindow():SetTitle("Transpose Chromatic") local current_y = 0 local y_increment = 26 local x_increment = 85 -- direction - local static = dialog:CreateStatic(0, current_y + 2) - str.LuaString = "Direction:" - static:SetText(str) - direction_choice = dialog:CreatePopup(x_increment, current_y) - add_strings_to_control(direction_choice, {"Up", "Down"}) - direction_choice:SetWidth(x_increment) - if context.direction and context.direction < 0 then - direction_choice:SetSelectedItem(1) - end + dialog:CreateStatic(0, current_y + 2):SetText("Direction:") + dialog:CreatePopup(x_increment, current_y, "direction_choice"):AddStrings("Up", "Down"):SetWidth(x_increment):SetSelectedItem(0) current_y = current_y + y_increment -- interval - static = dialog:CreateStatic(0, current_y + 2) - str.LuaString = "Interval:" - static:SetText(str) - interval_choice = dialog:CreatePopup(x_increment, current_y) - add_strings_to_control(interval_choice, interval_names) - interval_choice:SetWidth(140) - if context.interval_index then - interval_choice:SetSelectedItem(context.interval_index - 1) - end + static = dialog:CreateStatic(0, current_y + 2):SetText("Interval:") + dialog:CreatePopup(x_increment, current_y, "interval_choice"):AddStrings(interval_names):SetWidth(140):SetSelectedItem(0) current_y = current_y + y_increment -- simplify checkbox - do_simplify = dialog:CreateCheckbox(0, current_y + 2) - str.LuaString = "Simplify Spelling" - do_simplify:SetText(str) - do_simplify:SetWidth(140) - if context.simplify then - do_simplify:SetCheck(1) - end + dialog:CreateCheckbox(0, current_y + 2, "do_simplify"):SetText("Simplify Spelling"):SetWidth(140):SetCheck(0) current_y = current_y + y_increment -- plus octaves - static = dialog:CreateStatic(0, current_y + 2) - str.LuaString = "Plus Octaves:" - static:SetText(str) + dialog:CreateStatic(0, current_y + 2):SetText("Plus Octaves:") local edit_x = x_increment if finenv.UI():IsOnMac() then edit_x = edit_x + 4 end - plus_octaves = dialog:CreateEdit(edit_x, current_y) - if context.plus_octaves and 0 ~= context.plus_octaves then - str.LuaString = "" - str:AppendInteger(context.plus_octaves) - plus_octaves:SetText(str) - end + dialog:CreateEdit(edit_x, current_y, "plus_octaves"):SetText("") current_y = current_y + y_increment -- preserve existing notes - do_preserve = dialog:CreateCheckbox(0, current_y + 2) - str.LuaString = "Preserve Existing Notes" - do_preserve:SetText(str) - do_preserve:SetWidth(140) - if context.preserve_originals then - do_preserve:SetCheck(1) - end + dialog:CreateCheckbox(0, current_y + 2, "do_preserve"):SetText("Preserve Existing Notes"):SetWidth(140):SetCheck(0) current_y = current_y + y_increment -- OK/Cxl dialog:CreateOkButton() dialog:CreateCancelButton() - if dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - dialog.OkButtonCanClose = modifier_keys_on_invoke - end + dialog:RegisterHandleOkButtonPressed(on_ok) return dialog end @@ -233,11 +168,14 @@ end function get_values_from_dialog() local direction = 1 -- up - if direction_choice:GetSelectedItem() > 0 then + if global_dialog:GetControl("direction_choice"):GetSelectedItem() > 0 then direction = -1 -- down end - return direction, 1+interval_choice:GetSelectedItem(), (0 ~= do_simplify:GetCheck()), - plus_octaves:GetInteger(), (0 ~= do_preserve:GetCheck()) + local interval_choice = 1 + global_dialog:GetControl("interval_choice"):GetSelectedItem() + local do_simplify = (0 ~= global_dialog:GetControl("do_simplify"):GetCheck()) + local plus_octaves = global_dialog:GetControl("plus_octaves"):GetInteger() + local do_preserve = (0 ~= global_dialog:GetControl("do_preserve"):GetCheck()) + return direction, interval_choice, do_simplify, plus_octaves, do_preserve end function on_ok() @@ -245,39 +183,22 @@ function on_ok() do_transpose_chromatic(direction, interval_index, simplify, plus_octaves, preserve_originals) end -function on_close() - if global_dialog:QueryLastCommandModifierKeys(finale.CMDMODKEY_ALT) or global_dialog:QueryLastCommandModifierKeys(finale.CMDMODKEY_SHIFT) then - finenv.RetainLuaState = false - else - context.direction, context.interval_index, context.simplify, context.plus_octaves, context.preserve_originals = get_values_from_dialog() - global_dialog:StorePosition() - context.window_pos_x = global_dialog.StoredX - context.window_pos_y = global_dialog.StoredY - end -end - function transpose_chromatic() modifier_keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if modifier_keys_on_invoke and nil ~= context.interval_index then - do_transpose_chromatic(context.direction, context.interval_index, context.simplify, context.plus_octaves, context.preserve_originals) + if modifier_keys_on_invoke and global_dialog then + on_ok() return end - global_dialog = create_dialog_box() - if nil ~= context.window_pos_x and nil ~= context.window_pos_y then - global_dialog:StorePosition() - global_dialog:SetRestorePositionOnlyData(context.window_pos_x, context.window_pos_y) - global_dialog:RestorePosition() - end - global_dialog:RegisterHandleOkButtonPressed(on_ok) - if global_dialog.RegisterCloseWindow then - global_dialog:RegisterCloseWindow(on_close) + if not global_dialog then + global_dialog = create_dialog_box() end if finenv.IsRGPLua then - if nil ~= finenv.RetainLuaState then + if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after + global_dialog.OkButtonCanClose = modifier_keys_on_invoke + end + if global_dialog:ShowModeless() then finenv.RetainLuaState = true end - finenv.RegisterModelessDialog(global_dialog) - global_dialog:ShowModeless() else if finenv.Region():IsEmpty() then finenv.UI():AlertInfo("Please select a music region before running this script.", "Selection Required") From 8e548bc6313e33b127fd9858396858e9f9678da4 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Mon, 23 May 2022 09:56:17 -0500 Subject: [PATCH 3/7] leave anonymous funcs referring to `global_dialog` until the `self` issue is fixed. also revise table support to use ipairs (instead of pairsbykeys) in case we keep it. --- src/mixin/FCMCtrlPopup.lua | 2 +- src/transpose_by_step.lua | 24 ++++++++------------ src/transpose_chromatic.lua | 45 ++++++++++++++----------------------- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/src/mixin/FCMCtrlPopup.lua b/src/mixin/FCMCtrlPopup.lua index 90b08dac..6ab41b18 100644 --- a/src/mixin/FCMCtrlPopup.lua +++ b/src/mixin/FCMCtrlPopup.lua @@ -155,7 +155,7 @@ function props:AddStrings(...) mixin.FCMCtrlPopup.AddString(self, str) end elseif type(v) == "table" then - for _, str in pairsbykeys(v) do + for _, str in ipairs(v) do mixin.FCMCtrlPopup.AddString(self, str) end else diff --git a/src/transpose_by_step.lua b/src/transpose_by_step.lua index 77f33397..d00a52c9 100644 --- a/src/transpose_by_step.lua +++ b/src/transpose_by_step.lua @@ -33,8 +33,6 @@ function plugindef() return "Transpose By Steps...", "Transpose By Steps", "Transpose by the number of steps given, simplifying spelling as needed." end -local modifier_keys_on_invoke = false - if not finenv.IsRGPLua then local path = finale.FCString() path:SetRunningLuaFolderPath() @@ -73,32 +71,28 @@ function do_transpose_by_step(global_number_of_steps_edit) return success end -function on_ok() - do_transpose_by_step(global_dialog:GetControl("num_steps"):GetInteger()) -end - function create_dialog_box() local dialog = mixin.FCXCustomLuaWindow():SetTitle("Transpose By Steps") local current_y = 0 local x_increment = 105 -- number of steps dialog:CreateStatic(0, current_y + 2):SetText("Number Of Steps:") - local edit_x = x_increment - if finenv.UI():IsOnMac() then - edit_x = edit_x + 4 - end + local edit_x = x_increment + (finenv.UI():IsOnMac() and 4 or 0) dialog:CreateEdit(edit_x, current_y, "num_steps"):SetText("") -- ok/cancel dialog:CreateOkButton() dialog:CreateCancelButton() - dialog:RegisterHandleOkButtonPressed(on_ok) + function dialog:on_ok() + do_transpose_by_step(global_dialog:GetControl("num_steps"):GetInteger()) + end + dialog:RegisterHandleOkButtonPressed(dialog.on_ok) return dialog end function transpose_by_step() - modifier_keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if modifier_keys_on_invoke and global_dialog then - on_ok() + local keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) + if keys_on_invoke and global_dialog then + global_dialog:on_ok() return end if not global_dialog then @@ -106,7 +100,7 @@ function transpose_by_step() end if finenv.IsRGPLua then if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - global_dialog.OkButtonCanClose = modifier_keys_on_invoke + global_dialog.OkButtonCanClose = keys_on_invoke end if global_dialog:ShowModeless() then finenv.RetainLuaState = true diff --git a/src/transpose_chromatic.lua b/src/transpose_chromatic.lua index 26133d8a..95616a06 100644 --- a/src/transpose_chromatic.lua +++ b/src/transpose_chromatic.lua @@ -75,8 +75,6 @@ if not finenv.RetainLuaState then } end -local modifier_keys_on_invoke = false - if not finenv.IsRGPLua then local path = finale.FCString() path:SetRunningLuaFolderPath() @@ -105,10 +103,7 @@ function create_dialog_box() current_y = current_y + y_increment -- plus octaves dialog:CreateStatic(0, current_y + 2):SetText("Plus Octaves:") - local edit_x = x_increment - if finenv.UI():IsOnMac() then - edit_x = edit_x + 4 - end + local edit_x = x_increment + (finenv.UI():IsOnMac() and 4 or 0) dialog:CreateEdit(edit_x, current_y, "plus_octaves"):SetText("") current_y = current_y + y_increment -- preserve existing notes @@ -117,7 +112,18 @@ function create_dialog_box() -- OK/Cxl dialog:CreateOkButton() dialog:CreateCancelButton() - dialog:RegisterHandleOkButtonPressed(on_ok) + function dialog:on_ok() + local direction = 1 -- up + if global_dialog:GetControl("direction_choice"):GetSelectedItem() > 0 then + direction = -1 -- down + end + local interval_choice = 1 + global_dialog:GetControl("interval_choice"):GetSelectedItem() + local do_simplify = (0 ~= global_dialog:GetControl("do_simplify"):GetCheck()) + local plus_octaves = global_dialog:GetControl("plus_octaves"):GetInteger() + local preserve_originals = (0 ~= global_dialog:GetControl("do_preserve"):GetCheck()) + do_transpose_chromatic(direction, interval_choice, do_simplify, plus_octaves, preserve_originals) + end + dialog:RegisterHandleOkButtonPressed(dialog.on_ok) return dialog end @@ -166,27 +172,10 @@ function do_transpose_chromatic(direction, interval_index, simplify, plus_octave return success end -function get_values_from_dialog() - local direction = 1 -- up - if global_dialog:GetControl("direction_choice"):GetSelectedItem() > 0 then - direction = -1 -- down - end - local interval_choice = 1 + global_dialog:GetControl("interval_choice"):GetSelectedItem() - local do_simplify = (0 ~= global_dialog:GetControl("do_simplify"):GetCheck()) - local plus_octaves = global_dialog:GetControl("plus_octaves"):GetInteger() - local do_preserve = (0 ~= global_dialog:GetControl("do_preserve"):GetCheck()) - return direction, interval_choice, do_simplify, plus_octaves, do_preserve -end - -function on_ok() - local direction, interval_index, simplify, plus_octaves, preserve_originals = get_values_from_dialog() - do_transpose_chromatic(direction, interval_index, simplify, plus_octaves, preserve_originals) -end - function transpose_chromatic() - modifier_keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if modifier_keys_on_invoke and global_dialog then - on_ok() + local keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) + if keys_on_invoke and global_dialog then + global_dialog:on_ok() return end if not global_dialog then @@ -194,7 +183,7 @@ function transpose_chromatic() end if finenv.IsRGPLua then if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - global_dialog.OkButtonCanClose = modifier_keys_on_invoke + global_dialog.OkButtonCanClose = keys_on_invoke end if global_dialog:ShowModeless() then finenv.RetainLuaState = true From edaa6873a2960241ffa0b018823989a71fa32346 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Mon, 23 May 2022 11:11:22 -0500 Subject: [PATCH 4/7] incorporate ThistleSifter suggestions --- src/mixin/FCMCtrlPopup.lua | 6 +----- src/mixin/FCMCustomLuaWindow.lua | 2 +- src/transpose_by_step.lua | 2 +- src/transpose_chromatic.lua | 12 ++++++------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/mixin/FCMCtrlPopup.lua b/src/mixin/FCMCtrlPopup.lua index 6ab41b18..55ad1959 100644 --- a/src/mixin/FCMCtrlPopup.lua +++ b/src/mixin/FCMCtrlPopup.lua @@ -148,16 +148,12 @@ Adds multiple strings to the popup. function props:AddStrings(...) for i = 1, select("#", ...) do local v = select(i, ...) - mixin.assert_argument(v, {"string", "number", "FCString", "FCStrings", "table"}, i + 1) + mixin.assert_argument(v, {"string", "number", "FCString", "FCStrings"}, i + 1) if type(v) == "userdata" and v:ClassName() == "FCStrings" then for str in each(v) do mixin.FCMCtrlPopup.AddString(self, str) end - elseif type(v) == "table" then - for _, str in ipairs(v) do - mixin.FCMCtrlPopup.AddString(self, str) - end else mixin.FCMCtrlPopup.AddString(self, v) end diff --git a/src/mixin/FCMCustomLuaWindow.lua b/src/mixin/FCMCustomLuaWindow.lua index e0160340..def4b9cd 100644 --- a/src/mixin/FCMCustomLuaWindow.lua +++ b/src/mixin/FCMCustomLuaWindow.lua @@ -112,7 +112,7 @@ function props:Init() local function cb() local handlers = private[self][f] if handlers.Registered then - handlers.Registered() + handlers.Registered(self) end for _, v in ipairs(handlers.Added) do diff --git a/src/transpose_by_step.lua b/src/transpose_by_step.lua index d00a52c9..3182aaaf 100644 --- a/src/transpose_by_step.lua +++ b/src/transpose_by_step.lua @@ -83,7 +83,7 @@ function create_dialog_box() dialog:CreateOkButton() dialog:CreateCancelButton() function dialog:on_ok() - do_transpose_by_step(global_dialog:GetControl("num_steps"):GetInteger()) + do_transpose_by_step(self:GetControl("num_steps"):GetInteger()) end dialog:RegisterHandleOkButtonPressed(dialog.on_ok) return dialog diff --git a/src/transpose_chromatic.lua b/src/transpose_chromatic.lua index 95616a06..f2b8cd0b 100644 --- a/src/transpose_chromatic.lua +++ b/src/transpose_chromatic.lua @@ -96,7 +96,7 @@ function create_dialog_box() current_y = current_y + y_increment -- interval static = dialog:CreateStatic(0, current_y + 2):SetText("Interval:") - dialog:CreatePopup(x_increment, current_y, "interval_choice"):AddStrings(interval_names):SetWidth(140):SetSelectedItem(0) + dialog:CreatePopup(x_increment, current_y, "interval_choice"):AddStrings(table.unpack(interval_names)):SetWidth(140):SetSelectedItem(0) current_y = current_y + y_increment -- simplify checkbox dialog:CreateCheckbox(0, current_y + 2, "do_simplify"):SetText("Simplify Spelling"):SetWidth(140):SetCheck(0) @@ -114,13 +114,13 @@ function create_dialog_box() dialog:CreateCancelButton() function dialog:on_ok() local direction = 1 -- up - if global_dialog:GetControl("direction_choice"):GetSelectedItem() > 0 then + if self:GetControl("direction_choice"):GetSelectedItem() > 0 then direction = -1 -- down end - local interval_choice = 1 + global_dialog:GetControl("interval_choice"):GetSelectedItem() - local do_simplify = (0 ~= global_dialog:GetControl("do_simplify"):GetCheck()) - local plus_octaves = global_dialog:GetControl("plus_octaves"):GetInteger() - local preserve_originals = (0 ~= global_dialog:GetControl("do_preserve"):GetCheck()) + local interval_choice = 1 + self:GetControl("interval_choice"):GetSelectedItem() + local do_simplify = (0 ~= self:GetControl("do_simplify"):GetCheck()) + local plus_octaves = self:GetControl("plus_octaves"):GetInteger() + local preserve_originals = (0 ~= self:GetControl("do_preserve"):GetCheck()) do_transpose_chromatic(direction, interval_choice, do_simplify, plus_octaves, preserve_originals) end dialog:RegisterHandleOkButtonPressed(dialog.on_ok) From 8ae7a8ba1ea4bdd555681e401698632b547617f9 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Mon, 23 May 2022 11:12:13 -0500 Subject: [PATCH 5/7] revert comment --- src/mixin/FCMCtrlPopup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixin/FCMCtrlPopup.lua b/src/mixin/FCMCtrlPopup.lua index 55ad1959..cd9de7b8 100644 --- a/src/mixin/FCMCtrlPopup.lua +++ b/src/mixin/FCMCtrlPopup.lua @@ -143,7 +143,7 @@ end Adds multiple strings to the popup. @ self (FCMCtrlPopup) -@ ... (FCStrings|FCString|table|string|number) +@ ... (FCStrings|FCString|string|number) ]] function props:AddStrings(...) for i = 1, select("#", ...) do From b85e66854778203d1dbfbf049c74b357c78a23a5 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Sun, 29 May 2022 07:40:51 -0500 Subject: [PATCH 6/7] update to use new RunModeless function. --- src/transpose_by_step.lua | 32 ++--------- src/transpose_chromatic.lua | 108 +++++++++++++++--------------------- 2 files changed, 50 insertions(+), 90 deletions(-) diff --git a/src/transpose_by_step.lua b/src/transpose_by_step.lua index 3182aaaf..5470a248 100644 --- a/src/transpose_by_step.lua +++ b/src/transpose_by_step.lua @@ -82,36 +82,16 @@ function create_dialog_box() -- ok/cancel dialog:CreateOkButton() dialog:CreateCancelButton() - function dialog:on_ok() - do_transpose_by_step(self:GetControl("num_steps"):GetInteger()) - end - dialog:RegisterHandleOkButtonPressed(dialog.on_ok) + dialog:RegisterHandleOkButtonPressed(function(self) + do_transpose_by_step(self:GetControl("num_steps"):GetInteger()) + end + ) return dialog end function transpose_by_step() - local keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if keys_on_invoke and global_dialog then - global_dialog:on_ok() - return - end - if not global_dialog then - global_dialog = create_dialog_box() - end - if finenv.IsRGPLua then - if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - global_dialog.OkButtonCanClose = keys_on_invoke - end - if global_dialog:ShowModeless() then - finenv.RetainLuaState = true - end - else - if finenv.Region():IsEmpty() then - finenv.UI():AlertInfo("Please select a music region before running this script.", "Selection Required") - return - end - global_dialog:ExecuteModal(nil) - end + global_dialog = global_dialog or create_dialog_box() + global_dialog:RunModeless() end transpose_by_step() diff --git a/src/transpose_chromatic.lua b/src/transpose_chromatic.lua index f2b8cd0b..76a5a491 100644 --- a/src/transpose_chromatic.lua +++ b/src/transpose_chromatic.lua @@ -85,48 +85,6 @@ local transposition = require("library.transposition") local note_entry = require("library.note_entry") local mixin = require("library.mixin") -function create_dialog_box() - local dialog = mixin.FCXCustomLuaWindow():SetTitle("Transpose Chromatic") - local current_y = 0 - local y_increment = 26 - local x_increment = 85 - -- direction - dialog:CreateStatic(0, current_y + 2):SetText("Direction:") - dialog:CreatePopup(x_increment, current_y, "direction_choice"):AddStrings("Up", "Down"):SetWidth(x_increment):SetSelectedItem(0) - current_y = current_y + y_increment - -- interval - static = dialog:CreateStatic(0, current_y + 2):SetText("Interval:") - dialog:CreatePopup(x_increment, current_y, "interval_choice"):AddStrings(table.unpack(interval_names)):SetWidth(140):SetSelectedItem(0) - current_y = current_y + y_increment - -- simplify checkbox - dialog:CreateCheckbox(0, current_y + 2, "do_simplify"):SetText("Simplify Spelling"):SetWidth(140):SetCheck(0) - current_y = current_y + y_increment - -- plus octaves - dialog:CreateStatic(0, current_y + 2):SetText("Plus Octaves:") - local edit_x = x_increment + (finenv.UI():IsOnMac() and 4 or 0) - dialog:CreateEdit(edit_x, current_y, "plus_octaves"):SetText("") - current_y = current_y + y_increment - -- preserve existing notes - dialog:CreateCheckbox(0, current_y + 2, "do_preserve"):SetText("Preserve Existing Notes"):SetWidth(140):SetCheck(0) - current_y = current_y + y_increment - -- OK/Cxl - dialog:CreateOkButton() - dialog:CreateCancelButton() - function dialog:on_ok() - local direction = 1 -- up - if self:GetControl("direction_choice"):GetSelectedItem() > 0 then - direction = -1 -- down - end - local interval_choice = 1 + self:GetControl("interval_choice"):GetSelectedItem() - local do_simplify = (0 ~= self:GetControl("do_simplify"):GetCheck()) - local plus_octaves = self:GetControl("plus_octaves"):GetInteger() - local preserve_originals = (0 ~= self:GetControl("do_preserve"):GetCheck()) - do_transpose_chromatic(direction, interval_choice, do_simplify, plus_octaves, preserve_originals) - end - dialog:RegisterHandleOkButtonPressed(dialog.on_ok) - return dialog -end - function do_transpose_chromatic(direction, interval_index, simplify, plus_octaves, preserve_originals) if finenv.Region():IsEmpty() then return @@ -172,29 +130,51 @@ function do_transpose_chromatic(direction, interval_index, simplify, plus_octave return success end -function transpose_chromatic() - local keys_on_invoke = finenv.QueryInvokedModifierKeys and (finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_ALT) or finenv.QueryInvokedModifierKeys(finale.CMDMODKEY_SHIFT)) - if keys_on_invoke and global_dialog then - global_dialog:on_ok() - return - end - if not global_dialog then - global_dialog = create_dialog_box() - end - if finenv.IsRGPLua then - if global_dialog.OkButtonCanClose then -- OkButtonCanClose will be nil before 0.56 and true (the default) after - global_dialog.OkButtonCanClose = keys_on_invoke - end - if global_dialog:ShowModeless() then - finenv.RetainLuaState = true - end - else - if finenv.Region():IsEmpty() then - finenv.UI():AlertInfo("Please select a music region before running this script.", "Selection Required") - return +function create_dialog_box() + local dialog = mixin.FCXCustomLuaWindow():SetTitle("Transpose Chromatic") + local current_y = 0 + local y_increment = 26 + local x_increment = 85 + -- direction + dialog:CreateStatic(0, current_y + 2):SetText("Direction:") + dialog:CreatePopup(x_increment, current_y, "direction_choice"):AddStrings("Up", "Down"):SetWidth(x_increment):SetSelectedItem(0) + current_y = current_y + y_increment + -- interval + static = dialog:CreateStatic(0, current_y + 2):SetText("Interval:") + dialog:CreatePopup(x_increment, current_y, "interval_choice"):AddStrings(table.unpack(interval_names)):SetWidth(140):SetSelectedItem(0) + current_y = current_y + y_increment + -- simplify checkbox + dialog:CreateCheckbox(0, current_y + 2, "do_simplify"):SetText("Simplify Spelling"):SetWidth(140):SetCheck(0) + current_y = current_y + y_increment + -- plus octaves + dialog:CreateStatic(0, current_y + 2):SetText("Plus Octaves:") + local edit_x = x_increment + (finenv.UI():IsOnMac() and 4 or 0) + dialog:CreateEdit(edit_x, current_y, "plus_octaves"):SetText("") + current_y = current_y + y_increment + -- preserve existing notes + dialog:CreateCheckbox(0, current_y + 2, "do_preserve"):SetText("Preserve Existing Notes"):SetWidth(140):SetCheck(0) + current_y = current_y + y_increment + -- OK/Cxl + dialog:CreateOkButton() + dialog:CreateCancelButton() + dialog:RegisterHandleOkButtonPressed(function(self) + local direction = 1 -- up + if self:GetControl("direction_choice"):GetSelectedItem() > 0 then + direction = -1 -- down + end + local interval_choice = 1 + self:GetControl("interval_choice"):GetSelectedItem() + local do_simplify = (0 ~= self:GetControl("do_simplify"):GetCheck()) + local plus_octaves = self:GetControl("plus_octaves"):GetInteger() + local preserve_originals = (0 ~= self:GetControl("do_preserve"):GetCheck()) + do_transpose_chromatic(direction, interval_choice, do_simplify, plus_octaves, preserve_originals) end - global_dialog:ExecuteModal(nil) - end + ) + return dialog +end + +function transpose_chromatic() + global_dialog = global_dialog or create_dialog_box() + global_dialog:RunModeless() end transpose_chromatic() From 3542b6bf98e79289538f8c7b18d0fe9b73dd6523 Mon Sep 17 00:00:00 2001 From: Robert Patterson Date: Sun, 10 Jul 2022 19:53:24 -0500 Subject: [PATCH 7/7] update comments in `tie.lua` to produce better html. --- src/library/tie.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/library/tie.lua b/src/library/tie.lua index d1e75a95..a75038af 100644 --- a/src/library/tie.lua +++ b/src/library/tie.lua @@ -102,11 +102,11 @@ Calculates the (potential) start and end notes for a tie, given an input note. T input note can be from anywhere, including from the `eachentry()` iterator functions. The function returns 3 values: - - A FCNoteLayerEntry containing both the start and and notes (if they exist). - You must maintain the lifetime of this variable as long as you are referencing either - of the other two values. - - The potential or actual start note of the tie (taken from the FCNoteLayerEntry above). - - The potential or actual end note of the tie (taken from the FCNoteLayerEntry above). +- A FCNoteLayerEntry containing both the start and and notes (if they exist). +You must maintain the lifetime of this variable as long as you are referencing either +of the other two values. +- The potential or actual start note of the tie (taken from the FCNoteLayerEntry above). +- The potential or actual end note of the tie (taken from the FCNoteLayerEntry above). Be very careful about modifying the return values from this function. If you do it within an iterator loop from `eachentry()` or `eachentrysaved()` you could end up overwriting your changes @@ -114,8 +114,8 @@ with stale data from the iterator loop. You may discover that this function is m for gathering information than for modifying the values it returns. @ note (FCNote) the note for which to calculated the tie span -@ [for_tied_to] if true, searches for a note tying to the input note. Otherwise, searches for a note tying from the input note. -@ [tie_must_exist] if true, only returns notes for ties that already exist. +@ [for_tied_to] (boolean) if true, searches for a note tying to the input note. Otherwise, searches for a note tying from the input note. +@ [tie_must_exist] (boolean) if true, only returns notes for ties that already exist. : (FCNoteLayerEntry) A new FCNoteEntryLayer instance that contains both the following two return values. : (FCNote) The start note of the tie. : (FCNote) The end note of the tie.