Skip to content

Commit 2adc008

Browse files
carl vine edits integrated
1 parent 350e51d commit 2adc008

File tree

1 file changed

+89
-107
lines changed

1 file changed

+89
-107
lines changed

src/articulation_expression_swap.lua

Lines changed: 89 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,113 +2,110 @@ function plugindef()
22
finaleplugin.RequireSelection = false
33
finaleplugin.Author = "CJ Garcia"
44
finaleplugin.Copyright = "2024 MuseCraft Studio"
5-
finaleplugin.Version = "1.0"
6-
finaleplugin.Date = "5/27/2024"
5+
finaleplugin.Version = "1.1"
6+
finaleplugin.Date = "7/20/2024"
7+
finaleplugin.MinJWLuaVersion = 0.66
78
finaleplugin.RevisionNotes = [[
89
May 27, 2024: Script work began with idea from Burt Goldstein
910
May 28, 2024: Version 1.0
11+
July 20, 2024: Carl Vine edits integrated
1012
]]
1113
finaleplugin.CategoryTags = "Articulation, Expression"
12-
return "Articulation and Expression Swap", "Articulation and Expression Swap",
14+
return "Articulation and Expression Swap...", "Articulation and Expression Swap",
1315
"Replaces the selected articulation with the selected expression (or vice versa) for the full document if a region is not selected."
1416
end
1517

16-
SelectedItem = nil
17-
18-
local function assignExpression(exp_id, entry)
18+
local config = {
19+
art_id = 0,
20+
exp_id = 0,
21+
show_result = true,
22+
}
23+
local configuration = require("library.configuration")
24+
local library = require("library.general_library")
25+
local script_name = library.calc_script_name()
26+
local name = plugindef():gsub("%.%.%.", "")
27+
configuration.get_user_settings(script_name, config, true)
28+
29+
local function assign_expression(exp_id, entry)
1930
local exp = finale.FCExpression()
2031
exp:SetStaff(entry.Staff)
2132
exp:SetVisible(true)
2233
exp:SetMeasurePos(entry:GetMeasurePos())
2334
exp:SetScaleWithEntry(true)
2435
exp:SetLayerAssignment(entry.LayerNumber)
2536
exp:SetID(exp_id)
37+
exp:SaveNewToCell(finale.FCCell(entry.Measure, entry.Staff))
38+
end
2639

27-
local note_cell = finale.FCCell(entry.Measure, entry.Staff)
28-
exp:SaveNewToCell(note_cell)
40+
local function show_the_results(type, count, id)
41+
if config.show_result then
42+
if count ~= 0 then
43+
local msg = count > 1 and " occurances of " or " occurance of "
44+
msg = msg .. type .. " ID " .. id
45+
finenv.UI():AlertInfo("Replaced " .. count .. msg, name .. ": Success")
46+
else
47+
finenv.UI():AlertInfo("No occurances of " .. type .. " ID " .. id .. " were found",
48+
name .. ": Not found")
49+
end
50+
end
2951
end
3052

31-
local function run(art_id, exp_id)
32-
if (art_id == nil) and (exp_id ~= nil) then
33-
finenv.UI():AlertInfo("Articulation ID must be a number. Exiting process", "Articulation entry error")
34-
return
35-
elseif (art_id ~= nil) and (exp_id == nil) then
36-
finenv.UI():AlertInfo("Expression ID must be a number. Exiting process", "Expression entry error")
37-
return
38-
elseif (art_id == nil) and (exp_id == nil) then
39-
finenv.UI():AlertInfo("The articulation ID and expression ID must both be a number. Exiting process",
40-
"Entry error")
53+
local function run(art_id, exp_id, selected_item)
54+
local msg = {}
55+
if art_id == nil or art_id < 1 then
56+
table.insert(msg, "The Articulation ID must be a digit > 0")
57+
end
58+
if exp_id == nil or exp_id < 1 then
59+
table.insert(msg, "The Expression ID must be a digit > 0")
60+
end
61+
if #msg > 0 then
62+
table.insert(msg, "Exiting process.")
63+
finenv.UI():AlertInfo(table.concat(msg, "\n\n"), name .. ": Entry Error")
4164
return
4265
end
4366

44-
local art_defs = finale.FCArticulationDefs()
45-
art_defs:LoadAll()
46-
local has_art = false
47-
for art in each(art_defs) do
48-
if art:GetItemNo() == art_id then
49-
has_art = true
50-
break
67+
local function match_item(fc_defs, id)
68+
fc_defs:LoadAll()
69+
for a in each(fc_defs) do
70+
if a:GetItemNo() == id then return true end
5171
end
72+
return false
5273
end
53-
54-
local exp_defs = finale.FCTextExpressionDefs()
55-
exp_defs:LoadAll()
56-
local has_exp = false
57-
for ted in each(exp_defs) do
58-
if ted:GetItemNo() == exp_id then
59-
has_exp = true
60-
break
61-
end
74+
local has_art = match_item(finale.FCArticulationDefs(), art_id)
75+
local has_exp = match_item(finale.FCTextExpressionDefs(), exp_id)
76+
msg = {}
77+
if not has_art then
78+
table.insert(msg, "Articulation ID " .. art_id .. " could not be found.")
6279
end
63-
64-
if (has_art ~= true) and (has_exp == true) then
65-
finenv.UI():AlertInfo("The articulation with ID " .. art_id .. " could not be found. Exiting process",
66-
"Unable to find articulation")
67-
return
68-
elseif (has_art == true) and (has_exp ~= true) then
69-
finenv.UI():AlertInfo("The expression with ID " .. exp_id .. " could not be found. Exiting process",
70-
"Unable to find expression")
71-
return
72-
elseif (has_art ~= true) and (has_exp ~= true) then
73-
finenv.UI():AlertInfo(
74-
"Neither the articulation with ID " ..
75-
art_id .. " nor the expression with ID " .. exp_id .. " could not be found. Exiting process",
76-
"Unable to find items")
80+
if not has_exp then
81+
table.insert(msg, "Expression ID " .. exp_id .. " could not be found.")
82+
end
83+
if #msg > 0 then
84+
table.insert(msg, "Exiting process.")
85+
finenv.UI():AlertInfo(table.concat(msg, "\n\n"), name .. ": Items not found")
7786
return
7887
end
7988

8089
local music_region = finenv.Region()
81-
if music_region:IsEmpty() == true then
90+
if music_region:IsEmpty() then
8291
music_region = finale.FCMusicRegion()
8392
music_region:SetFullDocument()
8493
end
8594

8695
local count = 0
87-
88-
if SelectedItem == 0 then
96+
if selected_item == 0 then
8997
-- replace articulation with expression
9098
for noteentry in eachentrysaved(music_region) do
9199
local arts = noteentry:CreateArticulations()
92100
for a in eachbackwards(arts) do
93101
if a:GetID() == art_id then
94102
count = count + 1
95103
a:DeleteData()
96-
assignExpression(exp_id, noteentry)
104+
assign_expression(exp_id, noteentry)
97105
end
98106
end
99107
end
100-
if count ~= 0 then
101-
if count > 1 then
102-
finenv.UI():AlertInfo("Replaced " .. count .. " occurances of articulation with the ID of " .. art_id,
103-
"Success")
104-
else
105-
finenv.UI():AlertInfo("Replaced " .. count .. " occurance of articulation with the ID of " .. art_id,
106-
"Success")
107-
end
108-
else
109-
finenv.UI():AlertInfo("No occurances of articulation with the ID of " .. art_id .. " was found.",
110-
"Nothing found")
111-
end
108+
show_the_results("articulation", count, art_id)
112109
else
113110
-- replace expression with articulation
114111
for noteentry in eachentrysaved(music_region) do
@@ -134,74 +131,59 @@ local function run(art_id, exp_id)
134131
end
135132
end
136133
end
137-
if count ~= 0 then
138-
if count > 1 then
139-
finenv.UI():AlertInfo("Replaced " .. count .. " occurances of expression with the ID of " .. exp_id,
140-
"Success")
141-
else
142-
finenv.UI():AlertInfo("Replaced " .. count .. " occurance of expression with the ID of " .. exp_id,
143-
"Success")
144-
end
145-
else
146-
finenv.UI():AlertInfo("No occurances of expression with the ID of " .. exp_id .. " was found.",
147-
"Nothing found")
148-
end
134+
show_the_results("expression", count, exp_id)
149135
end
150136
end
151137

152-
local str = finale.FCString()
153-
str.LuaString = "Articulation Replacement"
138+
local fs = finale.FCString
154139
local dialog = finale.FCCustomLuaWindow()
155-
dialog:SetTitle(str)
140+
dialog:SetTitle(fs(name))
156141

157142
local art_button = dialog:CreateButton(0, 45)
158-
str.LuaString = "Select..."
159-
art_button:SetText(str)
160-
143+
art_button:SetText(fs("Select..."))
161144
local exp_button = dialog:CreateButton(150, 45)
162-
str.LuaString = "Select..."
163-
exp_button:SetText(str)
145+
exp_button:SetText(fs("Select..."))
164146

165147
local art_text = dialog:CreateStatic(0, 0)
166-
str.LuaString = "Articulation ID"
167-
art_text:SetText(str)
148+
art_text:SetText(fs("Articulation ID"))
168149
local art_box = dialog:CreateEdit(0, 16)
169-
local art_str = finale.FCString()
170-
art_str.LuaString = ""
150+
art_box:SetInteger(config.art_id)
171151

172152
local exp_text = dialog:CreateStatic(150, 0)
173-
str.LuaString = "Expression ID"
174-
exp_text:SetText(str)
153+
exp_text:SetText(fs("Expression ID"))
175154
local exp_box = dialog:CreateEdit(150, 16)
176-
local exp_str = finale.FCString()
177-
exp_str.LuaString = ""
155+
exp_box:SetInteger(config.exp_id)
178156

179-
local radio_group = dialog:CreateRadioButtonGroup(0, 100, 2)
157+
local radio_group = dialog:CreateRadioButtonGroup(0, 70, 2)
180158
local strs = finale.FCStrings()
181-
strs:AddCopy(finale.FCString("Find articulation, replace with expression."))
182-
strs:AddCopy(finale.FCString("Find expression, replace with articulation."))
159+
strs:CopyFromStringTable{
160+
"Find Articulation, Replace With Expression",
161+
"Find Expression, Replace With Articulation"
162+
}
183163
radio_group:SetText(strs)
184-
radio_group:SetWidth(225)
164+
radio_group:SetWidth(240)
165+
local show_result = dialog:CreateCheckbox(0, 105)
166+
show_result:SetWidth(150)
167+
show_result:SetText(fs("Show Results"))
168+
show_result:SetCheck(config.show_result and 1 or 0)
185169

186170
dialog:CreateOkButton()
187-
188171
dialog:CreateCancelButton()
189172

190-
local function getUserSelection(controller)
173+
local function get_user_selection(controller)
191174
if controller:GetControlID() == art_button:GetControlID() then
192-
local art_select = finenv.UI():DisplayArticulationDialog(0)
193-
art_box:SetText(finale.FCString(tostring(art_select)))
175+
art_box:SetInteger(finenv.UI():DisplayArticulationDialog(art_box:GetInteger()))
194176
elseif controller:GetControlID() == exp_button:GetControlID() then
195-
local art_select = finenv.UI():DisplayExpressionDialog(0, false)
196-
exp_box:SetText(finale.FCString(tostring(art_select)))
177+
exp_box:SetInteger(finenv.UI():DisplayExpressionDialog(exp_box:GetInteger(), false))
197178
end
198179
end
199180

200-
dialog:RegisterHandleCommand(getUserSelection)
181+
dialog:RegisterHandleCommand(get_user_selection)
201182

202183
if dialog:ExecuteModal(nil) == finale.EXECMODAL_OK then
203-
art_box:GetText(art_str)
204-
exp_box:GetText(exp_str)
205-
SelectedItem = radio_group:GetSelectedItem()
206-
run(tonumber(art_str.LuaString), tonumber(exp_str.LuaString))
184+
config.art_id = art_box:GetInteger()
185+
config.exp_id = exp_box:GetInteger()
186+
config.show_result = (show_result:GetCheck() == 1)
187+
configuration.save_user_settings(script_name, config)
188+
run(config.art_id, config.exp_id, radio_group:GetSelectedItem())
207189
end

0 commit comments

Comments
 (0)