+ ev.set_span_type (type)
+ ev.line_type = getattr (mxl_event, 'line-type', 'solid')
+
+ # assign the size, which is used for octave-shift, etc.
+ ev.size = mxl_event.get_size ()
+
+ return ev
+
+def musicxml_direction_to_indicator (direction):
+ return { "above": 1, "upright": 1, "below": -1, "downright": -1 }.get (direction, '')
+
+def musicxml_fermata_to_lily_event (mxl_event):
+ ev = musicexp.ArticulationEvent ()
+ ev.type = "fermata"
+ if hasattr (mxl_event, 'type'):
+ dir = musicxml_direction_to_indicator (mxl_event.type)
+ if dir:
+ ev.force_direction = dir
+ return ev
+
+
+def musicxml_arpeggiate_to_lily_event (mxl_event):
+ ev = musicexp.ArpeggioEvent ()
+ ev.direction = {"up": 1, "down": -1}.get (getattr (mxl_event, 'direction', None), 0)
+ return ev
+
+
+def musicxml_tremolo_to_lily_event (mxl_event):
+ ev = musicexp.TremoloEvent ()
+ ev.bars = mxl_event.get_text ()
+ return ev
+
+def musicxml_bend_to_lily_event (mxl_event):
+ ev = musicexp.BendEvent ()
+ ev.alter = mxl_event.bend_alter ()
+ return ev
+
+
+def musicxml_fingering_event (mxl_event):
+ ev = musicexp.ShortArticulationEvent ()
+ ev.type = mxl_event.get_text ()
+ return ev
+
+def musicxml_string_event (mxl_event):
+ ev = musicexp.NoDirectionArticulationEvent ()
+ ev.type = mxl_event.get_text ()
+ return ev
+
+def musicxml_accidental_mark (mxl_event):
+ ev = musicexp.MarkupEvent ()
+ contents = { "sharp": "\\sharp",
+ "natural": "\\natural",
+ "flat": "\\flat",
+ "double-sharp": "\\doublesharp",
+ "sharp-sharp": "\\sharp\\sharp",
+ "flat-flat": "\\flat\\flat",
+ "flat-flat": "\\doubleflat",
+ "natural-sharp": "\\natural\\sharp",
+ "natural-flat": "\\natural\\flat",
+ "quarter-flat": "\\semiflat",
+ "quarter-sharp": "\\semisharp",
+ "three-quarters-flat": "\\sesquiflat",
+ "three-quarters-sharp": "\\sesquisharp",
+ }.get (mxl_event.get_text ())
+ if contents:
+ ev.contents = contents
+ return ev
+ else:
+ return None
+
+# translate articulations, ornaments and other notations into ArticulationEvents
+# possible values:
+# -) string (ArticulationEvent with that name)
+# -) function (function(mxl_event) needs to return a full ArticulationEvent-derived object
+# -) (class, name) (like string, only that a different class than ArticulationEvent is used)
+# TODO: Some translations are missing!
+articulations_dict = {
+ "accent": (musicexp.ShortArticulationEvent, ">"), # or "accent"
+ "accidental-mark": musicxml_accidental_mark,
+ "bend": musicxml_bend_to_lily_event,
+ "breath-mark": (musicexp.NoDirectionArticulationEvent, "breathe"),
+ #"caesura": "caesura",
+ #"delayed-turn": "?",
+ "detached-legato": (musicexp.ShortArticulationEvent, "_"), # or "portato"
+ #"doit": "",
+ #"double-tongue": "",
+ "down-bow": "downbow",
+ #"falloff": "",
+ "fingering": musicxml_fingering_event,
+ #"fingernails": "",
+ #"fret": "",
+ #"hammer-on": "",
+ "harmonic": "flageolet",
+ #"heel": "",
+ "inverted-mordent": "prall",
+ "inverted-turn": "reverseturn",
+ "mordent": "mordent",
+ "open-string": "open",
+ #"plop": "",
+ #"pluck": "",
+ #"pull-off": "",
+ #"schleifer": "?",
+ #"scoop": "",
+ #"shake": "?",
+ #"snap-pizzicato": "",
+ #"spiccato": "",
+ "staccatissimo": (musicexp.ShortArticulationEvent, "|"), # or "staccatissimo"
+ "staccato": (musicexp.ShortArticulationEvent, "."), # or "staccato"
+ "stopped": (musicexp.ShortArticulationEvent, "+"), # or "stopped"
+ #"stress": "",
+ "string": musicxml_string_event,
+ "strong-accent": (musicexp.ShortArticulationEvent, "^"), # or "marcato"
+ #"tap": "",
+ "tenuto": (musicexp.ShortArticulationEvent, "-"), # or "tenuto"
+ #"thumb-position": "",
+ #"toe": "",
+ "turn": "turn",
+ "tremolo": musicxml_tremolo_to_lily_event,
+ "trill-mark": "trill",
+ #"triple-tongue": "",
+ #"unstress": ""
+ "up-bow": "upbow",
+ #"wavy-line": "?",
+}
+articulation_spanners = [ "wavy-line" ]
+
+def musicxml_articulation_to_lily_event (mxl_event):
+ # wavy-line elements are treated as trill spanners, not as articulation ornaments
+ if mxl_event.get_name () in articulation_spanners:
+ return musicxml_spanner_to_lily_event (mxl_event)
+
+ tmp_tp = articulations_dict.get (mxl_event.get_name ())
+ if not tmp_tp:
+ return
+
+ if isinstance (tmp_tp, str):
+ ev = musicexp.ArticulationEvent ()
+ ev.type = tmp_tp
+ elif isinstance (tmp_tp, tuple):
+ ev = tmp_tp[0] ()
+ ev.type = tmp_tp[1]
+ else:
+ ev = tmp_tp (mxl_event)
+
+ # Some articulations use the type attribute, other the placement...
+ dir = None
+ if hasattr (mxl_event, 'type'):
+ dir = musicxml_direction_to_indicator (mxl_event.type)
+ if hasattr (mxl_event, 'placement'):
+ dir = musicxml_direction_to_indicator (mxl_event.placement)
+ return ev
+
+
+def musicxml_dynamics_to_lily_event (dynentry):
+ dynamics_available = ( "p", "pp", "ppp", "pppp", "ppppp", "pppppp",
+ "f", "ff", "fff", "ffff", "fffff", "ffffff",
+ "mp", "mf", "sf", "sfp", "sfpp", "fp",
+ "rf", "rfz", "sfz", "sffz", "fz" )
+ if not dynentry.get_name() in dynamics_available:
+ return
+ event = musicexp.DynamicsEvent ()
+ event.type = dynentry.get_name ()
+ return event
+
+# Convert single-color two-byte strings to numbers 0.0 - 1.0
+def hexcolorval_to_nr (hex_val):