Skip to content

Commit 9374e44

Browse files
authored
Merge pull request #657 from jwink75/master
Fix to Page Format Wizard
2 parents 05a57a1 + dcf5967 commit 9374e44

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/page_format_wizard.lua

+26-29
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ function plugindef()
33
finaleplugin.Author = "Jacob Winkler"
44
finaleplugin.Copyright = "©2024 Jacob Winkler"
55
finaleplugin.AuthorEmail = "[email protected]"
6-
finaleplugin.Date = "2024/1/21"
7-
finaleplugin.Version = "1.1"
6+
finaleplugin.Date = "2024/1/25"
7+
finaleplugin.Version = "1.2"
88
finaleplugin.HandlesUndo = true
99
finaleplugin.NoStore = false
1010
finaleplugin.MinJWLuaVersion = 0.70 -- https://robertgpatterson.com/-fininfo/-rgplua/rgplua.html
@@ -83,13 +83,14 @@ function bold_control(control)
8383
control:SetFont(font)
8484
end
8585

86-
function math.sign(number)
86+
function math_sign(number)
8787
return (number >= 0 and 1) or -1
8888
end
8989

90-
function math.round(number, round_to)
90+
function math_round(number, round_to)
91+
number = number or 0
9192
round_to = round_to or 1
92-
return math.floor(number/round_to + math.sign(number) * 0.5) * round_to
93+
return math.floor(math.abs(number)/round_to + 0.5) * round_to * math_sign(number)
9394
end
9495

9596
local function mm_to_efix(mm)
@@ -111,7 +112,7 @@ local function efix_to_mm_string(efix)
111112
str:SetMeasurement(efix/64*10, finale.MEASUREMENTUNIT_CENTIMETERS)
112113
-- str.LuaString = efix * (25.4 / 18432)
113114
local temp = str.LuaString
114-
temp = math.round(tonumber(temp), .1)
115+
temp = math_round(tonumber(temp), .1)
115116
str.LuaString = tostring(temp)
116117
return str
117118
end
@@ -188,8 +189,8 @@ local special_ctrls = {}
188189
local special_ctrls_collection = {}
189190

190191
local function match_page(w, h)
191-
w = math.round(w, 1)
192-
h = math.round(h, 1)
192+
w = math_round(w, 1)
193+
h = math_round(h, 1)
193194
local matched = -1
194195
local landscape = 0
195196
for k, v in pairs(page_sizes) do
@@ -258,11 +259,6 @@ local function orientation_set(w, h, mode) -- mode 0 is portrait, mode 1 is land
258259
else
259260
return h, w
260261
end
261-
if mode == 1 and w > h then
262-
return w, h
263-
else
264-
return h, w
265-
end
266262
end
267263

268264
local function orientation_set_popup(w, h, popup)
@@ -536,7 +532,7 @@ local function format_wizard()
536532
controls.first_system_left_edit:SetMeasurement(page_settings.first_system_left_margin, page_settings.system_units)
537533
controls.system_bottom_edit:SetMeasurement(page_settings.system_bottom_margin-96, page_settings.system_units) -- bottom margin is offset by 4 spaces (96 EVPUs) because Finale...
538534
--[[ STAFF HEIGHT ]]
539-
temp = math.round(efix_to_mm(page_settings.staff_h)*10, 1)
535+
temp = math_round(efix_to_mm(page_settings.staff_h)*10, 1)
540536
controls.staff_h_invisible:SetInteger(temp)
541537
controls.staff_h_updown:SetValue(temp)
542538
controls.staff_h_edit:SetText(efix_to_mm_string(page_settings.staff_h))
@@ -652,7 +648,6 @@ local function format_wizard()
652648

653649
local function format_pages_and_save()
654650
local controls = {}
655-
local page_settings = {}
656651

657652
local score_format_prefs = finale.FCPageFormatPrefs()
658653
local parts_format_prefs = finale.FCPageFormatPrefs()
@@ -730,7 +725,7 @@ local function format_wizard()
730725

731726
local function check_for_special(part_num)
732727
for i = 0, special_ctrls.parts_datalist:GetCount()-1 do
733-
local row = special_ctrls.parts_datalist:GetItemAt(i)
728+
row = special_ctrls.parts_datalist:GetItemAt(i)
734729
str = row:GetItemAt(1)
735730
if part_num == tonumber(str.LuaString) then
736731
if row:GetCheck() then
@@ -834,9 +829,7 @@ local function format_wizard()
834829
--
835830
staff_height_set(system, page_settings.staff_h)
836831

837-
if controls.staff_spacing_popup:GetSelectedItem() == 0 then
838-
-- Do nothing!
839-
else
832+
if controls.staff_spacing_popup:GetSelectedItem() > 0 then
840833
local sysstaves = finale.FCSystemStaves()
841834
sysstaves:LoadAllForItem(system:GetItemNo())
842835

@@ -993,7 +986,7 @@ local function format_wizard()
993986
local special_static = add_ctrl(dialog, "static", "SPECIAL PARTS", x + 12, 0, col_w, row_h)
994987

995988

996-
local function section_create(controls, page_settings, ctrls_collection, section_n)
989+
local function section_create(controls, page_settings, ctrls_collection)
997990
row = 1
998991
y = row*row_h
999992
x = section_n*section_w
@@ -1240,7 +1233,7 @@ local function format_wizard()
12401233
controls.staff_h_updown:ConnectIntegerEdit(controls.staff_h_invisible, 30, 100)
12411234
controls.staff_h_mm_static = add_ctrl(dialog, "static", "mm", x+col[4]+12, y, 20, row_h)
12421235
-- Initialize the staff height edit boxes, starting with the invisible one connected to the UpDown
1243-
temp = math.round(efix_to_mm(page_settings.staff_h)*10, .1)
1236+
temp = math_round(efix_to_mm(page_settings.staff_h)*10, .1)
12441237
controls.staff_h_invisible:SetInteger(temp ,1)
12451238
controls.staff_h_edit:SetText(efix_to_mm_string(page_settings.staff_h))
12461239
controls.staff_h_updown:SetValue(controls.staff_h_invisible:GetInteger())
@@ -1311,7 +1304,7 @@ local function format_wizard()
13111304
for part in each(parts) do
13121305
if part:IsPart() then
13131306
part:GetName(str)
1314-
local row = controls.parts_datalist:CreateRow()
1307+
row = controls.parts_datalist:CreateRow()
13151308
row:GetItemAt(0).LuaString = str.LuaString
13161309
row:GetItemAt(1).LuaString = part:GetItemNo()
13171310
end
@@ -1400,10 +1393,15 @@ local function format_wizard()
14001393
return controls, page_settings, ctrls_collection
14011394
end -- section_create()
14021395

1403-
score_ctrls, score_settings, score_ctrls_collection = section_create(score_ctrls, score_settings, score_ctrls_collection, 0)
1404-
parts_ctrls, parts_settings, parts_ctrls_collection = section_create(parts_ctrls, parts_settings, parts_ctrls_collection, 1)
1405-
special_ctrls, special_settings, special_ctrls_collection = section_create(special_ctrls, special_settings, special_ctrls_collection, 2)
1406-
1396+
section_n = 0
1397+
score_ctrls, score_settings, score_ctrls_collection = section_create(score_ctrls, score_settings, score_ctrls_collection)
1398+
section_n = 1
1399+
--
1400+
parts_ctrls, parts_settings, parts_ctrls_collection = section_create(parts_ctrls, parts_settings, parts_ctrls_collection)
1401+
section_n = 2
1402+
--
1403+
special_ctrls, special_settings, special_ctrls_collection = section_create(special_ctrls, special_settings, special_ctrls_collection)
1404+
--
14071405
section_enable(score_enable_checkbox, score_ctrls, score_settings, score_ctrls_collection)
14081406
section_enable(parts_enable_checkbox, parts_ctrls, parts_settings, parts_ctrls_collection)
14091407
section_enable(special_enable_checkbox, special_ctrls, special_settings, special_ctrls_collection)
@@ -1677,7 +1675,7 @@ local function format_wizard()
16771675
if not hold then
16781676
hold = true
16791677
page_settings.staff_h = mm_to_efix(controls.staff_h_edit:GetMeasurement(finale.MEASUREMENTUNIT_MILLIMETERS))
1680-
temp = math.round(controls.staff_h_edit:GetMeasurement(finale.MEASUREMENTUNIT_MILLIMETERS)*10, 1)
1678+
temp = math_round(controls.staff_h_edit:GetMeasurement(finale.MEASUREMENTUNIT_MILLIMETERS)*10, 1)
16811679
controls.staff_h_invisible:SetInteger(temp)
16821680
controls.staff_h_updown:SetValue(temp)
16831681
hold = false
@@ -1766,7 +1764,7 @@ local function format_wizard()
17661764

17671765
dialog:RegisterHandleControlEvent (controls.clear_datalist_button, function(control)
17681766
for i = 0, controls.parts_datalist:GetCount()-1 do
1769-
local row = controls.parts_datalist:GetItemAt(i)
1767+
row = controls.parts_datalist:GetItemAt(i)
17701768
row:SetCheck(false)
17711769
end
17721770
end)
@@ -1858,7 +1856,6 @@ local function format_wizard()
18581856
bold_control(score_ctrls.staff_settings)
18591857
bold_control(parts_ctrls.staff_settings)
18601858
bold_control(special_ctrls.staff_settings)
1861-
-- finale.FCFileSaveAsDialog(finenv.UI()):GetFileName(str)
18621859
end
18631860

18641861
format_wizard()

0 commit comments

Comments
 (0)