From: Reinhold Kainhofer Date: Fri, 8 Feb 2008 20:28:25 +0000 (+0100) Subject: MusicXML: Convert accordion registrations X-Git-Tag: release/2.11.40-1~3^2~20^2~7^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4b37aefb683034c7895d245de54c254fd266e4d3;p=lilypond.git MusicXML: Convert accordion registrations They are converted as \mark\markup{...}, where I need to generate the markup manually (following the LSR snipplet http://lsr.dsi.unimi.it/LSR/Item?id=194 ) --- diff --git a/input/regression/musicxml/03b-AccordionRegistrations-MusicXML.xml b/input/regression/musicxml/03b-AccordionRegistrations-MusicXML.xml new file mode 100644 index 0000000000..ad6fa3c739 --- /dev/null +++ b/input/regression/musicxml/03b-AccordionRegistrations-MusicXML.xml @@ -0,0 +1,356 @@ + + + + Accordion registrations + + + + + + + + + + + + + + 1 + + 0 + major + + + + G + 2 + + + + + + + + + + + C4 + 1 + 1 + quarter + 0/0/1 + + + + + 1 + + + + + C4 + 1 + 1 + quarter + 0/1/0 + + + + + 1 + + + + + + C4 + 1 + 1 + quarter + 0/1/1 + + + + + 2 + + + + + C4 + 1 + 1 + quarter + 0/2/0 + + + + + + + 2 + + + + + + C4 + 1 + 1 + quarter + 0/2/1 + + + + + 3 + + + + + C4 + 1 + 1 + quarter + 0/3/0 + + + + + 3 + + + + + + C4 + 1 + 1 + quarter + 0/3/1 + + + + + + + + + + + C4 + 1 + 1 + quarter + 1/0/1 + + + + + + + + + + + + C4 + 1 + 1 + quarter + 1/0/0 + + + + + + 1 + + + + + C4 + 1 + 1 + quarter + 1/1/0 + + + + + + 1 + + + + + + C4 + 1 + 1 + quarter + 1/1/1 + + + + + + 2 + + + + + C4 + 1 + 1 + quarter + 1/2/0 + + + + + + + + 2 + + + + + + C4 + 1 + 1 + quarter + 1/2/1 + + + + + + 3 + + + + + C4 + 1 + 1 + quarter + 1/3/0 + + + + + + 3 + + + + + + C4 + 1 + 1 + quarter + 1/3/1 + + + + + + + + + + C4 + 1 + 1 + quarter + empty + + + + + + + + + + + + + + C4 + 1 + 1 + quarter + empty M + + + + + + test + + + + + + C4 + 1 + 1 + quarter + inval.M + + + + + + 0 + + + + + + C4 + 1 + 1 + quarter + M=0 + + + + + + 5 + + + + + + C4 + 1 + 1 + quarter + M=5 + + + + light-heavy + + + + + + diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index ebad1a51d5..b7460dced4 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -946,7 +946,7 @@ def musicxml_dynamics_to_lily_event (dynentry): dynamicstext = dynamicsname dynamicsname = string.replace (dynamicsname, "-", "") additional_definitions[dynamicsname] = dynamicsname + \ - "=#(make-dynamic-script \"" + dynamicstext + "\")" + " = #(make-dynamic-script \"" + dynamicstext + "\")" needed_additional_definitions.append (dynamicsname) event = musicexp.DynamicsEvent () event.type = dynamicsname @@ -1026,6 +1026,69 @@ def musicxml_words_to_lily_event (words): return event +# convert accordion-registration to lilypond. +# Since lilypond does not have any built-in commands, we need to create +# the markup commands manually and define our own variables. +# Idea was taken from: http://lsr.dsi.unimi.it/LSR/Item?id=194 +def musicxml_accordion_to_markup (mxl_event): + commandname = "accReg" + command = "" + + high = mxl_event.get_maybe_exist_named_child ('accordion-high') + if high: + commandname += "H" + command += """\\combine + \\raise #2.5 \\musicglyph #\"accordion.accDot\" + """ + middle = mxl_event.get_maybe_exist_named_child ('accordion-middle') + if middle: + txt = 1 + try: + txt = string.atoi (middle.get_text ()) + except ValueError: + pass + if txt == 3: + commandname += "MMM" + command += """\\combine + \\raise #1.5 \\musicglyph #\"accordion.accDot\" + \\combine + \\raise #1.5 \\translate #(cons 1 0) \\musicglyph #\"accordion.accDot\" + \\combine + \\raise #1.5 \\translate #(cons -1 0) \\musicglyph #\"accordion.accDot\" + """ + elif txt == 2: + commandname += "MM" + command += """\\combine + \\raise #1.5 \\translate #(cons 0.5 0) \\musicglyph #\"accordion.accDot\" + \\combine + \\raise #1.5 \\translate #(cons -0.5 0) \\musicglyph #\"accordion.accDot\" + """ + elif not txt <= 0: + commandname += "M" + command += """\\combine + \\raise #1.5 \\musicglyph #\"accordion.accDot\" + """ + low = mxl_event.get_maybe_exist_named_child ('accordion-low') + if low: + commandname += "L" + command += """\\combine + \\raise #0.5 \musicglyph #\"accordion.accDot\" + """ + + command += "\musicglyph #\"accordion.accDiscant\"" + command = "\\markup { \\normalsize %s }" % command + additional_definitions[commandname] = "%s = %s" % (commandname, command) + print additional_definitions + needed_additional_definitions.append (commandname) + return "\\%s" % commandname + +def musicxml_accordion_to_ly (mxl_event): + txt = musicxml_accordion_to_markup (mxl_event) + if txt: + ev = musicexp.MarkEvent (txt) + return ev + return + def musicxml_rehearsal_to_ly_mark (mxl_event): text = mxl_event.get_text () @@ -1040,13 +1103,12 @@ def musicxml_rehearsal_to_ly_mark (mxl_event): ev = musicexp.MarkEvent ("\\markup { %s }" % text) return ev - # translate directions into Events, possible values: # -) string (MarkEvent with that command) # -) function (function(mxl_event) needs to return a full Event-derived object # -) (class, name) (like string, only that a different class than MarkEvent is used) directions_dict = { -# 'accordion-registration' : musicxml_accordion_to_ly, + 'accordion-registration' : musicxml_accordion_to_ly, 'coda' : (musicexp.MusicGlyphMarkEvent, "coda"), # 'damp' : ??? # 'damp-all' : ???