+# 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:
+ # By default, use one dot (when no or invalid content is given). The
+ # MusicXML spec is quiet about this case...
+ 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
+ # Define the newly built command \accReg[H][MMM][L]
+ additional_definitions[commandname] = "%s = %s" % (commandname, command)
+ 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 ()
+ if not text:
+ return
+ # default is boxed rehearsal marks!
+ encl = "box"
+ if hasattr (mxl_event, 'enclosure'):
+ encl = {"none": None, "square": "box", "circle": "circle" }.get (mxl_event.enclosure, None)
+ if encl:
+ text = "\\%s { %s }" % (encl, text)
+ 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,
+ 'coda' : (musicexp.MusicGlyphMarkEvent, "coda"),
+# 'damp' : ???
+# 'damp-all' : ???
+# 'eyeglasses': ??????
+# 'harp-pedals' :
+# 'image' :
+# 'metronome' :
+ 'rehearsal' : musicxml_rehearsal_to_ly_mark,
+# 'scordatura' :
+ 'segno' : (musicexp.MusicGlyphMarkEvent, "segno"),
+ 'words' : musicxml_words_to_lily_event,
+}
+directions_spanners = [ 'octave-shift', 'pedal', 'wedge', 'dashes', 'bracket' ]