Skip to content

Commit 46fbe36

Browse files
committed
incorporate latest style changes for 4.6.
1 parent 1de1141 commit 46fbe36

File tree

1 file changed

+127
-39
lines changed

1 file changed

+127
-39
lines changed

src/document_options_to_musescore.lua

Lines changed: 127 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ local enigma_string = require("library.enigma_string")
5959
local utils = require("library.utils")
6060
local client = require("library.client")
6161
local score = require("library.score")
62+
local library = require("library.general_library")
6263

6364
do_folder = do_folder or false
6465

@@ -68,7 +69,7 @@ local MUSX_EXTENSION <const> = ".musx"
6869
local MUS_EXTENSION <const> = ".mus"
6970
local TEXT_EXTENSION <const> = ".mss"
7071
local PART_EXTENSION <const> = ".part" .. TEXT_EXTENSION
71-
local MSS_VERSION <const> = "4.50"
72+
local MSS_VERSION <const> = "4.60"
7273

7374
-- hard-coded scaling values
7475
local EVPU_PER_INCH <const> = 288
@@ -77,6 +78,8 @@ local EVPU_PER_SPACE <const> = 24
7778
local EFIX_PER_EVPU <const> = 64
7879
local EFIX_PER_SPACE <const> = EVPU_PER_SPACE * EFIX_PER_EVPU
7980
local MUSE_FINALE_SCALE_DIFFERENTIAL <const> = 20 / 24
81+
local MUSE_NUMERIC_PRECISION <const> = 5
82+
local NORMAL_STAFF_HEIGHT_SP <const> = 4
8083

8184
-- Current state
8285
local TIMER_ID <const> = 1 -- value that identifies our timer
@@ -179,13 +182,17 @@ function open_current_prefs()
179182
end
180183
end
181184

185+
local function format_muse_float(value)
186+
return string.format("%" .. "." .. tostring(MUSE_NUMERIC_PRECISION) .. "g", value)
187+
end
188+
182189
function set_element_text(style_element, name, value)
183190
local setter_func = "SetText"
184191
if type(value) == "nil" then
185192
log_message("incorrect property for " .. name, true)
186193
elseif type(value) == "number" then
187194
if math.type(value) == "float" then
188-
value = string.format("%.5g", value)
195+
value = format_muse_float(value)
189196
setter_func = "SetText"
190197
else
191198
setter_func = "SetIntText"
@@ -202,6 +209,30 @@ function set_element_text(style_element, name, value)
202209
return element
203210
end
204211

212+
local function set_point_element(style_element, name, x, y)
213+
local element = style_element:FirstChildElement(name)
214+
if not element then
215+
element = style_element:InsertNewChildElement(name)
216+
end
217+
element:SetText("")
218+
element:SetAttribute("x", format_muse_float(x))
219+
element:SetAttribute("y", format_muse_float(y))
220+
return element
221+
end
222+
223+
local function calc_font_height_in_spaces(font_info)
224+
if not font_info then
225+
return 0
226+
end
227+
local text_metrics = finale.FCTextMetrics()
228+
local test_string = finale.FCString()
229+
test_string.LuaString = "0123456789"
230+
if not text_metrics:LoadString(test_string, font_info, 100) then
231+
return 0
232+
end
233+
return text_metrics:CalcHeightEVPUs() / EVPU_PER_SPACE
234+
end
235+
205236
function muse_font_efx(font_info)
206237
local retval = 0
207238
if font_info.Bold then
@@ -452,57 +483,114 @@ function write_measure_number_prefs(style_element)
452483
set_element_text(style_element, "showMeasureNumber", meas_num_regions:LoadAll() > 0)
453484
if meas_num_regions.Count > 0 then
454485
local meas_nums = meas_num_regions:GetItemAt(0)
455-
set_element_text(style_element, "showMeasureNumberOne", not meas_nums:GetHideFirstNumber(current_is_part))
456-
set_element_text(style_element, "measureNumberInterval", meas_nums:GetMultipleValue(current_is_part))
457-
set_element_text(style_element, "measureNumberSystem", meas_nums:GetShowOnSystemStart(current_is_part) and not meas_nums:GetShowMultiples(current_is_part))
458-
local function process_segment(font_info, enclosure, use_enclosure, justification, alignment, vertical, prefix)
459-
local function justification_string(justi)
460-
if justi == finale.MNJUSTIFY_LEFT then
461-
return "left,baseline"
462-
elseif justi == finale.MNJUSTIFY_CENTER then
463-
return "center,baseline"
464-
else
465-
return "right,baseline"
466-
end
486+
local parts_val = library.calc_parts_boolean_for_measure_number_region(meas_nums, current_is_part)
487+
set_element_text(style_element, "showMeasureNumberOne", not meas_nums:GetHideFirstNumber(parts_val))
488+
set_element_text(style_element, "measureNumberInterval", meas_nums:GetMultipleValue(parts_val))
489+
set_element_text(style_element, "measureNumberSystem", meas_nums:GetShowOnSystemStart(parts_val) and not meas_nums:GetShowMultiples(parts_val))
490+
491+
local function justification_string(justi)
492+
if justi == finale.MNJUSTIFY_LEFT then
493+
return "left,baseline"
494+
elseif justi == finale.MNJUSTIFY_CENTER then
495+
return "center,baseline"
467496
end
468-
local function horz_alignment(align) -- MuseScore 4.6 changes this to "left", "center", "right"
469-
if align == finale.MNALIGN_LEFT then
470-
return 0
471-
elseif align == finale.MNALIGN_CENTER then
472-
return 1
473-
else
474-
return 2
475-
end
476-
end
477-
local function vert_alignment(vert)
478-
return vert >= 0 and 0 or 1
497+
return "right,baseline"
498+
end
499+
500+
local function align_string(align)
501+
if align == finale.MNALIGN_LEFT then
502+
return "left"
503+
elseif align == finale.MNALIGN_CENTER then
504+
return "center"
479505
end
506+
return "right"
507+
end
508+
509+
local function vert_alignment(vert)
510+
return vert >= 0 and 0 or 1
511+
end
512+
513+
local function process_segment(font_info, enclosure, use_enclosure, justification, alignment, horizontal, vertical, prefix)
514+
horizontal = horizontal or 0
515+
vertical = vertical or 0
480516
write_font_pref(style_element, prefix, font_info)
481517
set_element_text(style_element, prefix .. "VPlacement", vert_alignment(vertical))
482-
set_element_text(style_element, prefix .. "HPlacement", horz_alignment(alignment))
518+
set_element_text(style_element, prefix .. "HPlacement", align_string(alignment))
483519
set_element_text(style_element, prefix .. "Align", justification_string(justification))
520+
set_element_text(style_element, prefix .. "Position", align_string(justification))
521+
local horizontal_sp = horizontal / EVPU_PER_SPACE
522+
local vertical_sp = vertical / EVPU_PER_SPACE
523+
local text_height_sp = calc_font_height_in_spaces(font_info)
524+
set_point_element(style_element, prefix .. "PosAbove", horizontal_sp, math.min(-vertical_sp, 0))
525+
set_point_element(style_element, prefix .. "PosBelow", horizontal_sp,
526+
math.max(-(vertical_sp + NORMAL_STAFF_HEIGHT_SP) - text_height_sp, 0))
484527
write_frame_prefs(style_element, prefix, use_enclosure and enclosure or nil)
485528
end
486-
local font_info = meas_nums:GetShowOnSystemStart(current_is_part) and meas_nums:CreateStartFontInfo(current_is_part) or meas_nums:CreateMultipleFontInfo(current_is_part)
487-
local enclosure = meas_nums:GetShowOnSystemStart(current_is_part) and meas_nums:GetEnclosureStart(current_is_part) or meas_nums:GetEnclosureMultiple(current_is_part)
488-
local use_enclosure = meas_nums:GetShowOnSystemStart(current_is_part) and meas_nums:GetUseEnclosureStart(current_is_part) or meas_nums:GetUseEnclosureMultiple(current_is_part)
489-
local justification = meas_nums:GetShowMultiples(current_is_part) and meas_nums:GetMultipleJustification(current_is_part) or meas_nums:GetStartJustification(current_is_part)
490-
local alignment = meas_nums:GetShowMultiples(current_is_part) and meas_nums:GetMultipleAlignment(current_is_part) or meas_nums:GetStartAlignment(current_is_part)
491-
local vertical = meas_nums:GetShowOnSystemStart(current_is_part) and meas_nums:GetStartVerticalPosition(current_is_part) or meas_nums:GetMultipleVerticalPosition(current_is_part)
529+
530+
local scroll_view = finale.FCSystemStaves()
531+
scroll_view:LoadScrollView()
532+
local staff = finale.FCStaff()
533+
local top_on = false
534+
local bottom_on = false
535+
local any_interior_on = false
536+
local all_staves_on = scroll_view.Count > 0
537+
for index = 0, scroll_view.Count - 1 do
538+
local staff_id = scroll_view:GetItemAt(index).Staff
539+
local shows = false
540+
if staff:Load(staff_id) then
541+
shows = staff.ShowMeasureNumbers
542+
end
543+
all_staves_on = all_staves_on and shows
544+
if index == 0 then
545+
top_on = shows
546+
elseif index == scroll_view.Count - 1 then
547+
bottom_on = shows
548+
elseif shows then
549+
any_interior_on = true
550+
end
551+
end
552+
553+
local placement_mode = "on-so-staves"
554+
local show_top = meas_nums:GetShowOnTopStaff(parts_val)
555+
local show_bottom = meas_nums:GetShowOnBottomStaff(parts_val)
556+
local exclude_others = meas_nums:GetExcludeOtherStaves(parts_val)
557+
local use_above = exclude_others or (not any_interior_on and not bottom_on)
558+
local use_below = exclude_others or (not any_interior_on and not top_on)
559+
if use_above and show_top then
560+
placement_mode = "above-system"
561+
elseif use_below and show_bottom then
562+
placement_mode = "below-system"
563+
elseif all_staves_on then
564+
placement_mode = "on-all-staves"
565+
elseif show_bottom and not use_below then
566+
log_message("Show on Bottom not supported when other staves also show measure numbers.")
567+
end
568+
set_element_text(style_element, "measureNumberPlacementMode", placement_mode)
569+
570+
local font_info = meas_nums:GetShowOnSystemStart(parts_val) and meas_nums:CreateStartFontInfo(parts_val) or meas_nums:CreateMultipleFontInfo(parts_val)
571+
local enclosure = meas_nums:GetShowOnSystemStart(parts_val) and meas_nums:GetEnclosureStart(parts_val) or meas_nums:GetEnclosureMultiple(parts_val)
572+
local use_enclosure = meas_nums:GetShowOnSystemStart(parts_val) and meas_nums:GetUseEnclosureStart(parts_val) or meas_nums:GetUseEnclosureMultiple(parts_val)
573+
local justification = meas_nums:GetShowMultiples(parts_val) and meas_nums:GetMultipleJustification(parts_val) or meas_nums:GetStartJustification(parts_val)
574+
local alignment = meas_nums:GetShowMultiples(parts_val) and meas_nums:GetMultipleAlignment(parts_val) or meas_nums:GetStartAlignment(parts_val)
575+
local vertical = meas_nums:GetShowOnSystemStart(parts_val) and meas_nums:GetStartVerticalPosition(parts_val) or meas_nums:GetMultipleVerticalPosition(parts_val)
576+
local horizontal = meas_nums:GetShowOnSystemStart(parts_val) and meas_nums:GetStartHorizontalPosition(parts_val) or meas_nums:GetMultipleHorizontalPosition(parts_val)
577+
set_element_text(style_element, "measureNumberAlignToBarline", alignment == finale.MNALIGN_LEFT)
492578
set_element_text(style_element, "measureNumberOffsetType", 1)
493-
process_segment(font_info, enclosure, use_enclosure, justification, alignment, vertical, "measureNumber")
494-
set_element_text(style_element, "mmRestShowMeasureNumberRange", meas_nums:GetShowMultiMeasureRange(current_is_part))
495-
local left_char = meas_nums:GetMultiMeasureBracketLeft(current_is_part)
579+
process_segment(font_info, enclosure, use_enclosure, justification, alignment, horizontal, vertical, "measureNumber")
580+
process_segment(font_info, enclosure, use_enclosure, justification, alignment, horizontal, vertical, "measureNumberAlternate")
581+
582+
set_element_text(style_element, "mmRestShowMeasureNumberRange", meas_nums:GetShowMultiMeasureRange(parts_val))
583+
local left_char = meas_nums:GetMultiMeasureBracketLeft(parts_val)
496584
if left_char == 0 then
497585
set_element_text(style_element, "mmRestRangeBracketType", 2)
498-
elseif left_char == '(' then
586+
elseif left_char == string.byte('(') then
499587
set_element_text(style_element, "mmRestRangeBracketType", 1)
500588
else
501589
set_element_text(style_element, "mmRestRangeBracketType", 0)
502590
end
503-
process_segment(meas_nums:CreateMultiMeasureFontInfo(current_is_part), meas_nums:GetEnclosureMultiple(current_is_part), meas_nums:GetUseEnclosureMultiple(current_is_part),
504-
meas_nums:GetMultiMeasureJustification(current_is_part), meas_nums:GetMultiMeasureAlignment(current_is_part),
505-
meas_nums:GetMultiMeasureVerticalPosition(current_is_part), "mmRestRange")
591+
process_segment(meas_nums:CreateMultiMeasureFontInfo(parts_val), meas_nums:GetEnclosureMultiple(parts_val), meas_nums:GetUseEnclosureMultiple(parts_val),
592+
meas_nums:GetMultiMeasureJustification(parts_val), meas_nums:GetMultiMeasureAlignment(parts_val),
593+
meas_nums:GetMultiMeasureHorizontalPosition(parts_val), meas_nums:GetMultiMeasureVerticalPosition(parts_val), "mmRestRange")
506594
end
507595
set_element_text(style_element, "createMultiMeasureRests", current_is_part)
508596
set_element_text(style_element, "minEmptyMeasures", mmrest_prefs.StartNumberingAt)

0 commit comments

Comments
 (0)