Skip to content

Commit bde59d0

Browse files
committed
Update dynamic_levels.lua
Added checking for nil selection.
1 parent a647a21 commit bde59d0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/dynamic_levels.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ function plugindef()
22
finaleplugin.RequireSelection = false
33
finaleplugin.HandlesUndo = true
44
finaleplugin.Author = "Carl Vine"
5-
finaleplugin.AuthorURL = "https://carlvine.com/lua/"
6-
finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/"
7-
finaleplugin.Version = "0.08"
8-
finaleplugin.Date = "2024/06/08"
5+
finaleplugin.AuthorURL = "https://carlvine.com/lua"
6+
finaleplugin.Copyright = "https://creativecommons.org/licenses/by/4.0/"
7+
finaleplugin.Version = "0.09"
8+
finaleplugin.Date = "2024/06/19"
99
finaleplugin.MinJWLuaVersion = 0.70
1010
finaleplugin.Notes = [[
1111
Make dynamic marks in the selection louder or softer by stages.
1212
This functionality is buried within __JWChange__ but is useful
1313
and I thought was worth bringing nearer the surface.
1414
This script works similarly but allows jumping up to 9 _levels_ at once.
15-
The dynamic range is from __pppppp__ to __ffffff__, though
15+
The dynamic range is 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
@@ -105,10 +105,8 @@ local function create_dynamics_alert(dialog)
105105
local msg = "Do you want this script to create "
106106
.. "additional dynamic expressions as required? "
107107
.. "(A positive reply will be saved and used if this question arises again)."
108-
local ok = dialog and
109-
dialog:CreateChildUI():AlertYesNo(msg, nil)
110-
or finenv.UI():AlertYesNo(msg, nil)
111-
return ok == finale.YESRETURN
108+
local ui = dialog and dialog:CreateChildUI() or finenv.UI()
109+
return ui:AlertYesNo(msg, name) == finale.YESRETURN
112110
end
113111

114112
local function create_dyn_def(expression_text)
@@ -130,6 +128,11 @@ local function create_dyn_def(expression_text)
130128
end
131129

132130
local function change_dynamics(dialog)
131+
if finenv.Region():IsEmpty() then
132+
local ui = dialog and dialog:CreateChildUI() or finenv.UI()
133+
ui:AlertError("Please select some music\nbefore running this script", name)
134+
return
135+
end
133136
local found = {} -- collate matched dynamic expressions
134137
local match_count = 0
135138
local shift = config.levels -- how many dynamic levels to move?
@@ -191,13 +194,13 @@ end
191194

192195
local function run_the_dialog()
193196
local y, m_offset = 0, finenv.UI():IsOnMac() and 3 or 0
194-
local save
197+
local save = config.levels
195198
local ctl = {}
196199
local dialog = mixin.FCXCustomLuaWindow():SetTitle(name:sub(1, 7))
197200
-- local functions
198201
local function yd(diff) y = y + (diff or 20) end
199202
local function show_info()
200-
utils.show_notes_dialog(dialog, "About " .. name, 300, 200)
203+
utils.show_notes_dialog(dialog, "About " .. name, 330, 160)
201204
end
202205
local function cstat(horiz, vert, wide, str) -- dialog static text
203206
return dialog:CreateStatic(horiz, vert):SetWidth(wide):SetText(str)
@@ -237,7 +240,6 @@ local function run_the_dialog()
237240
cstat(23, y + 11, 25, "(" .. hotkey.direction .. ")")
238241
-- levels
239242
cstat(65, y, 55, "Levels:")
240-
save = config.levels
241243
ctl.levels = dialog:CreateEdit(110, y - m_offset):SetText(config.levels):SetWidth(20)
242244
:AddHandleCommand(function() key_subs() end)
243245
yd(21)

0 commit comments

Comments
 (0)