Skip to content

Commit dd802c4

Browse files
authored
Merge pull request #790 from rpatters1/denigma-sync
Denigma support
2 parents 54d4411 + 96ae810 commit dd802c4

3 files changed

Lines changed: 119 additions & 20 deletions

File tree

src/document_options_to_musescore.lua

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ local mixin = require("library.mixin")
5858
local enigma_string = require("library.enigma_string")
5959
local utils = require("library.utils")
6060
local client = require("library.client")
61+
local score = require("library.score")
6162

6263
do_folder = do_folder or false
6364

@@ -119,6 +120,7 @@ local mmrest_prefs
119120
local tie_prefs
120121
local tuplet_prefs
121122
local text_exps
123+
local music_font_name
122124

123125
function open_current_prefs()
124126
local font_prefs = finale.FCFontPrefs()
@@ -156,6 +158,25 @@ function open_current_prefs()
156158
tuplet_prefs:Load(1)
157159
text_exps = finale.FCTextExpressionDefs()
158160
text_exps:LoadAll()
161+
music_font_name = default_music_font.Name -- piece of the rock
162+
if default_music_font.IsSMuFLFont then
163+
music_font_name = default_music_font.Name -- duplicate assignment avoids warning
164+
elseif music_font_name == "Broadway Copyist" then
165+
music_font_name = "Finale Broadway"
166+
elseif music_font_name == "Engraver" then
167+
music_font_name = "Finale Engraver"
168+
elseif music_font_name == "Jazz" then
169+
music_font_name = "Finale Jazz"
170+
elseif music_font_name == "Maestro"
171+
or music_font_name == "Pmusic"
172+
or music_font_name == "Sonata" then
173+
music_font_name = "Finale Maestro"
174+
elseif music_font_name == "Petrucci" then
175+
music_font_name = "Finale Legacy"
176+
-- add more elseif blocks if needed
177+
else
178+
music_font_name = nil
179+
end
159180
end
160181

161182
function set_element_text(style_element, name, value)
@@ -282,9 +303,26 @@ function write_page_prefs(style_element)
282303
local page_percent = page_prefs.PageScaling / 100
283304
local staff_percent = (page_prefs.SystemStaffHeight / (EVPU_PER_SPACE * 4 * 16)) * (page_prefs.SystemScaling / 100)
284305
set_element_text(style_element, "spatium", (EVPU_PER_SPACE * staff_percent * page_percent) / EVPU_PER_MM)
285-
if default_music_font.IsSMuFLFont then
286-
set_element_text(style_element, "musicalSymbolFont", default_music_font.Name)
287-
set_element_text(style_element, "musicalTextFont", default_music_font.Name .. " Text")
306+
local first_system = finale.FCStaffSystem()
307+
if first_system:LoadFirst() then
308+
local min_size = 100
309+
if first_system.UseStaffResize then
310+
local system_staves = finale.FCSystemStaves()
311+
system_staves.LoadAllForItem(first_system.ItemNo)
312+
for system_staff in each(system_staves) do
313+
if system_staff.Resize < min_size then
314+
min_size = system_staff.Resize
315+
end
316+
end
317+
end
318+
if min_size < 100 then
319+
set_element_text(style_element, "smallStaffMag", min_size / 100)
320+
set_element_text(style_element, "smallNoteMag", min_size / 100)
321+
end
322+
end
323+
if music_font_name then
324+
set_element_text(style_element, "musicalSymbolFont", music_font_name)
325+
set_element_text(style_element, "musicalTextFont", music_font_name .. " Text")
288326
end
289327
end
290328

@@ -315,7 +353,8 @@ function write_line_measure_prefs(style_element)
315353
set_element_text(style_element, "startBarlineSingle", misc_prefs.LeftBarlineDisplaySingle)
316354
set_element_text(style_element, "startBarlineMultiple", misc_prefs.LeftBarlineDisplayMultiple)
317355
set_element_text(style_element, "bracketWidth", 0.5) -- hard-coded in Finale
318-
set_element_text(style_element, "bracketDistance", -distance_prefs.GroupBracketDefaultDistance / EVPU_PER_SPACE)
356+
-- Finale subtracts half the bracket width on layout for bracket distance (observed).
357+
set_element_text(style_element, "bracketDistance", ((-distance_prefs.GroupBracketDefaultDistance) - 0.25 * EVPU_PER_SPACE) / EVPU_PER_SPACE)
319358
set_element_text(style_element, "akkoladeBarDistance", -distance_prefs.GroupBracketDefaultDistance / EVPU_PER_SPACE)
320359
set_element_text(style_element, "clefLeftMargin", distance_prefs.ClefSpaceBefore / EVPU_PER_SPACE)
321360
set_element_text(style_element, "keysigLeftMargin", distance_prefs.KeySpaceBefore / EVPU_PER_SPACE)
@@ -328,7 +367,7 @@ function write_line_measure_prefs(style_element)
328367
-- differences in how MuseScore and Finale interpret these settings means the following two are better off left alone
329368
-- set_element_text(style_element, "systemHeaderDistance", distance_prefs.KeySpaceAfter / EVPU_PER_SPACE)
330369
-- set_element_text(style_element, "systemHeaderTimeSigDistance", distance_prefs.TimeSigSpaceAfter / EVPU_PER_SPACE)
331-
set_element_text(style_element, "clefBarlineDistance", repeat_prefs.AfterClefSpace / EVPU_PER_SPACE)
370+
set_element_text(style_element, "clefBarlineDistance", distance_prefs.ClefChangeOffset / EVPU_PER_SPACE)
332371
set_element_text(style_element, "timesigBarlineDistance", repeat_prefs.AfterClefSpace / EVPU_PER_SPACE)
333372
set_element_text(style_element, "measureRepeatNumberPos", -(music_character_prefs.VerticalTwoMeasureRepeatOffset + 0.5) / EVPU_PER_SPACE)
334373
set_element_text(style_element, "staffLineWidth", size_prefs.StaffLineThickness / EFIX_PER_SPACE)
@@ -344,7 +383,7 @@ function write_line_measure_prefs(style_element)
344383
set_element_text(style_element, "genCourtesyClef", misc_prefs.CourtesyClefAtSystemEnd)
345384
set_element_text(style_element, "keySigCourtesyBarlineMode", misc_prefs.DoubleBarlineAtKeyChange)
346385
set_element_text(style_element, "timeSigCourtesyBarlineMode", 0)
347-
set_element_text(style_element, "hideEmptyStaves", not current_is_part)
386+
set_element_text(style_element, "hideEmptyStaves", score.calc_has_optimized_systems())
348387
end
349388

350389
function write_stem_prefs(style_element)
@@ -371,10 +410,17 @@ function write_note_related_prefs(style_element)
371410
-- Finale randomly adds twice the stem width to the length of a beam stub. (Observed behavior)
372411
set_element_text(style_element, "beamMinLen", (size_prefs.BrokenBeamLength + (2 * size_prefs.StemLineThickness / EFIX_PER_EVPU)) / EVPU_PER_SPACE)
373412
set_element_text(style_element, "beamNoSlope", misc_prefs.BeamSlopeStyle == finale.BEAMSLOPE_FLATTENALL)
374-
set_element_text(style_element, "dotMag", muse_mag_val(finale.FONTPREF_AUGMENTATIONDOT))
413+
local dot_mag = muse_mag_val(finale.FONTPREF_AUGMENTATIONDOT)
414+
set_element_text(style_element, "dotMag", dot_mag)
375415
set_element_text(style_element, "dotNoteDistance", distance_prefs.AugmentationDotNoteSpace / EVPU_PER_SPACE)
376416
set_element_text(style_element, "dotRestDistance", distance_prefs.AugmentationDotNoteSpace / EVPU_PER_SPACE)
377-
set_element_text(style_element, "dotDotDistance", distance_prefs.AugmentationDotSpace / EVPU_PER_SPACE)
417+
local dot_width = (function()
418+
local metrics = finale.FCTextMetrics()
419+
metrics:LoadSymbol(music_character_prefs.SymbolAugmentationDot, default_music_font, 100)
420+
return metrics:CalcWidthEVPUs()
421+
end)()
422+
-- MuseScore dot-dot width includes the dot whereas Finale's is from right edge of previous to left edge of next
423+
set_element_text(style_element, "dotDotDistance", (distance_prefs.AugmentationDotSpace + dot_mag * dot_width) / EVPU_PER_SPACE)
378424
set_element_text(style_element, "articulationMag", muse_mag_val(finale.FONTPREF_ARTICULATION))
379425
set_element_text(style_element, "graceNoteMag", size_prefs.GraceNoteSize / 100)
380426
set_element_text(style_element, "concertPitch", part_scope_prefs.DisplayInConcertPitch)
@@ -383,7 +429,7 @@ function write_note_related_prefs(style_element)
383429
end
384430

385431
function write_smart_shape_prefs(style_element)
386-
set_element_text(style_element, "hairpinHeight", smart_shape_prefs.HairpinDefaultOpening / EVPU_PER_SPACE)
432+
set_element_text(style_element, "hairpinHeight", smart_shape_prefs.HairpinDefaultShortOpening / EVPU_PER_SPACE)
387433
set_element_text(style_element, "hairpinContHeight", 0.5) -- not configurable in Finale: hard-coded to a half space
388434
write_category_text_font_pref(style_element, "hairpin", finale.DEFAULTCATID_DYNAMICS)
389435
write_line_prefs(style_element, "hairpin", smart_shape_prefs.HairpinLineWidth, smart_shape_prefs.LineDashLength, smart_shape_prefs.LineDashSpace)
@@ -419,7 +465,7 @@ function write_measure_number_prefs(style_element)
419465
return "right,baseline"
420466
end
421467
end
422-
local function horz_alignment(align)
468+
local function horz_alignment(align) -- MuseScore 4.6 changes this to "left", "center", "right"
423469
if align == finale.MNALIGN_LEFT then
424470
return 0
425471
elseif align == finale.MNALIGN_CENTER then
@@ -484,6 +530,10 @@ end
484530

485531
function write_tuplet_prefs(style_element)
486532
set_element_text(style_element, "tupletOutOfStaff", tuplet_prefs.AvoidStaff)
533+
-- tupletNumberRythmicCenter and tupletExtendToEndOfDuration are 4.6 settings, but MuseScore 4.5 should ignore them
534+
-- while MuseScore 4.6 picks them up even out of a 4.5 file.
535+
set_element_text(style_element, "tupletNumberRythmicCenter", tuplet_prefs.CenterUsingDuration); -- 4.6 setting
536+
set_element_text(style_element, "tupletExtendToEndOfDuration", tuplet_prefs.BracketFullDuration); -- 4.6 setting
487537
set_element_text(style_element, "tupletStemLeftDistance", tuplet_prefs.LeftExtension / EVPU_PER_SPACE)
488538
set_element_text(style_element, "tupletStemRightDistance", tuplet_prefs.RightExtension / EVPU_PER_SPACE)
489539
set_element_text(style_element, "tupletNoteLeftDistance", tuplet_prefs.LeftExtension / EVPU_PER_SPACE)

src/font_map_legacy.lua

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ context = {
3535
local function format_mapping(mapping)
3636
local codepoint_desc = "[" .. utils.format_codepoint(mapping.codepoint) .. "]"
3737
if mapping.glyph then
38-
return "'" .. mapping.glyph .. "' " .. codepoint_desc
38+
codepoint_desc = "'" .. mapping.glyph .. "' " .. codepoint_desc
39+
end
40+
if mapping.smuflFontName then
41+
codepoint_desc = codepoint_desc .. "(" .. mapping.smuflFontName ..")"
3942
end
4043
return codepoint_desc
4144
end
@@ -84,11 +87,30 @@ local function set_codepoint(control, codepoint)
8487
control:SetText(fcstr)
8588
end
8689

90+
local function on_smufl_popup(popup)
91+
local dialog = popup:GetParent()
92+
local smufl_box = dialog:GetControl("smufl_box")
93+
local fcstr = finale.FCString()
94+
popup:GetItemText(popup:GetSelectedItem(), fcstr)
95+
smufl_box:SetFont(finale.FCFontInfo(fcstr.LuaString, 24))
96+
end
97+
8798
local function on_popup(popup)
8899
local legacy_codepoint = context.popup_keys[popup:GetSelectedItem() + 1] or 0
89100
local current_mapping = legacy_codepoint > 0 and context.current_mapping[legacy_codepoint]
90101
local smufl_codepoint = current_mapping and current_mapping.codepoint or 0
91102
local dialog = popup:GetParent()
103+
if current_mapping and current_mapping.smuflFontName then
104+
local smufl_list = dialog:GetControl("smufl_list")
105+
for index = 0, smufl_list:GetCount() - 1 do
106+
local str = finale.FCString()
107+
smufl_list:GetItemText(index, str)
108+
if str.LuaString == current_mapping.smuflFontName then
109+
smufl_list:SetSelectedItem(index)
110+
on_smufl_popup(smufl_list)
111+
end
112+
end
113+
end
92114
set_codepoint(dialog:GetControl("legacy_box"), legacy_codepoint)
93115
set_codepoint(dialog:GetControl("smufl_box"), smufl_codepoint)
94116
end
@@ -164,6 +186,7 @@ local function on_select_file(control)
164186
t.glyph = glyph
165187
t.codepoint = utils.parse_codepoint(v.codepoint)
166188
t.nameIsMakeMusic = v.nameIsMakeMusic
189+
t.smuflFontName = v.smuflFontName
167190
if t.codepoint == 0xFFFD then
168191
local smufl_box = dialog:GetControl("smufl_box")
169192
local _, info = smufl_glyphs.get_glyph_info(glyph, smufl_box:CreateFontInfo())
@@ -200,14 +223,6 @@ local function on_symbol_select(box)
200223
enable_disable(dialog)
201224
end
202225

203-
local function on_smufl_popup(popup)
204-
local dialog = popup:GetParent()
205-
local smufl_box = dialog:GetControl("smufl_box")
206-
local fcstr = finale.FCString()
207-
popup:GetItemText(popup:GetSelectedItem(), fcstr)
208-
smufl_box:SetFont(finale.FCFontInfo(fcstr.LuaString, 24))
209-
end
210-
211226
local function on_add_mapping(control)
212227
local dialog = control:GetParent()
213228
local popup = dialog:GetControl("mappings")
@@ -221,13 +236,17 @@ local function on_add_mapping(control)
221236
return
222237
end
223238
end
239+
local font = dialog:GetControl("smufl_box"):CreateFontInfo()
224240
current_mapping = {codepoint = smufl_point}
225-
local glyph, info = smufl_glyphs.get_glyph_info(smufl_point, dialog:GetControl("smufl_box"):CreateFontInfo())
241+
local glyph, info = smufl_glyphs.get_glyph_info(smufl_point, font)
226242
if info then
227243
current_mapping.glyph = glyph
228244
else
229245
current_mapping.glyph = utils.format_codepoint(smufl_point)
230246
end
247+
if font and smufl_point >= 0xF400 and smufl_point <= 0xF8FF then
248+
current_mapping.smuflFontName = font.Name
249+
end
231250
context.current_mapping[legacy_point] = current_mapping
232251
update_popup(popup, legacy_point)
233252
end
@@ -264,6 +283,9 @@ local function emit_json(mapping, reverse_lookup)
264283
else
265284
table.insert(parts, '\t\t"description": ' .. quote(""))
266285
end
286+
if entry.smuflFontName then
287+
table.insert(parts, '\t\t"smuflFontName": ' .. quote(entry.smuflFontName))
288+
end
267289
return "{\n" .. table.concat(parts, ",\n") .. "\n\t}"
268290
end
269291

src/library/score.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,4 +825,31 @@ function score.calc_voice_staff(staff_num)
825825
return is_voice_staff
826826
end
827827

828+
--[[
829+
% calc_has_optimized_systems()
830+
831+
Deterimines if this score contains optimized systems
832+
833+
: (boolean) True if an optimized system is found
834+
]]
835+
function score.calc_has_optimized_systems()
836+
local staff_systems = finale.FCStaffSystems()
837+
staff_systems:LoadAll()
838+
local scroll_view = finale.FCSystemStaves()
839+
scroll_view:LoadScrollView()
840+
for staff_system in each(staff_systems) do
841+
local next_system = finale.FCSystemStaves()
842+
next_system:LoadAllForItem(staff_system.ItemNo)
843+
if next_system.Count ~= scroll_view.Count then
844+
return true
845+
end
846+
for staff_index = 0, next_system.Count - 1 do
847+
if next_system:GetItemAt(staff_index).Staff ~= scroll_view:GetItemAt(staff_index).Staff then
848+
return true
849+
end
850+
end
851+
end
852+
return false
853+
end
854+
828855
return score

0 commit comments

Comments
 (0)