--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"
+ "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise>
+ <movement-title>Articulations Test</movement-title>
+ <identification>
+ <creator type="composer">Reinhold Kainhofer</creator>
+ <rights>Public Domain</rights>
+ <encoding>
+ <software>Kate</software>
+ </encoding>
+ </identification>
+ <part-list>
+ <score-part id="P1">
+ <part-name>Test part</part-name>
+ </score-part>
+ </part-list>
+ <!--=========================================================-->
+ <part id="P1">
+ <measure number="1">
+ <attributes>
+ <divisions>1</divisions>
+ <key>
+ <fifths>0</fifths>
+ <mode>major</mode>
+ </key>
+ <time symbol="common">
+ <beats>12</beats>
+ <beat-type>4</beat-type>
+ </time>
+ <clef>
+ <sign>G</sign>
+ <line>2</line>
+ </clef>
+ </attributes>
+ <sound tempo="120"/>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <accent/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <turn/>
+ <accidental-mark>sharp</accidental-mark>
+ <accidental-mark>three-quarters-flat</accidental-mark>
+ <accidental-mark>natural</accidental-mark>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <bend><bend-alter>4</bend-alter></bend>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <breath-mark/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <caesura/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <delayed-turn/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <detached-legato/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <doit/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <double-tongue/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <down-bow/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <falloff/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <fingering/>
+ </technical>
+ </notations>
+ </note>
+ </measure>
+ <!--=======================================================-->
+ <measure number="2">
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <fingernails/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <fret/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <hammer-on type="start"/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <hammer-on type="stop"/>
+ <harmonic/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <heel/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <inverted-mordent/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <!--inverted-turn/-->
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <mordent/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <open-string/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <plop/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <pluck/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <!--portato/-->
+ </technical>
+ </notations>
+ </note>
+ </measure>
+ <!--=======================================================-->
+ <measure number="3">
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <pull-off type="start"/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <pull-off type="stop"/>
+ </technical>
+ <ornaments>
+ <schleifer/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <scoop/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <shake/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <snap-pizzicato/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <spiccato/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <staccatissimo/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <staccato/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <stopped/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <!--stress/-->
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <string/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <strong-accent/>
+ </articulations>
+ </notations>
+ </note>
+ </measure>
+ <!--=======================================================-->
+ <measure number="4">
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <tap/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <articulations>
+ <tenuto/>
+ </articulations>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <thumb-position/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <toe/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <turn/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <tremolo>3</tremolo>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <ornaments>
+ <trill-mark/>
+ </ornaments>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <triple-tongue/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <!--unstress/-->
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <pitch>
+ <step>C</step>
+ <octave>4</octave>
+ </pitch>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ <notations>
+ <technical>
+ <up-bow/>
+ </technical>
+ </notations>
+ </note>
+ <note>
+ <rest/>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ </note>
+ <note>
+ <rest/>
+ <duration>1</duration>
+ <voice>1</voice>
+ <type>quarter</type>
+ <stem>up</stem>
+ </note>
+ </measure>
+ <!--=======================================================-->
+ </part>
+ <!--=========================================================-->
+</score-partwise>
return ev
def musicxml_tremolo_to_lily_event (mxl_event):
- if mxl_event.get_name () != "tremolo":
- return
ev = musicexp.TremoloEvent ()
ev.bars = mxl_event.get_text ()
return ev
def musicxml_bend_to_lily_event (mxl_event):
- if mxl_event.get_name () != "bend":
- return
ev = musicexp.BendEvent ()
ev.alter = mxl_event.bend_alter ()
return ev
-short_articulations_dict = {
- "staccato": ".",
- "tenuto": "-",
- "stopped": "+",
- "staccatissimo": "|",
- "accent": ">",
- "strong-accent": "^",
- #"portato": "_", # does not exist in MusicXML
- #"fingering": "", # fingering is special cased, as get_text() will be the event's name
-}
+def musicxml_fingering_event (mxl_event):
+ ev = musicexp.ShortArticulationEvent ()
+ 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 = {
- ##### ORNAMENTS
- "trill-mark": "trill",
- "turn": "turn",
- #"delayed-turn": "?",
- "inverted-turn": "reverseturn",
- #"shake": "?",
- #"wavy-line": "?",
- "mordent": "mordent",
- "inverted-mordent": "prall",
- #"schleifer": "?"
- ##### TECHNICALS
- "up-bow": "upbow",
- "down-bow": "downbow",
- "harmonic": "flageolet",
- #"open-string": "",
- #"thumb-position": "",
- #"pluck": "",
- #"double-tongue": "",
- #"triple-tongue": "",
- #"snap-pizzicato": "",
- #"fret": "",
- #"string": "",
- #"hammer-on": "",
- #"pull-off": "",
- #"bend": "bendAfter #%s", # bend is special-cased, as we need to process the bend-alter subelement!
- #"tap": "",
- #"heel": "",
- #"toe": "",
- #"fingernails": ""
- ##### ARTICULATIONS
- #"detached-legato": "",
- #"spiccato": "",
- #"scoop": "",
- #"plop": "",
- #"doit": "",
+articulations_dict = {
+ "accent": (musicexp.ShortArticulationEvent, ">"),
+ "accidental-mark": musicxml_accidental_mark,
+ "bend": musicxml_bend_to_lily_event,
+ "breath-mark": (musicexp.NoDirectionArticulationEvent, "breathe"),
+ #"caesura": "caesura",
+ #"delayed-turn": "?",
+ #"detached-legato": "",
+ #"doit": "",
+ #"double-tongue": "",
+ "down-bow": "downbow",
#"falloff": "",
- "breath-mark": "breathe",
- #"caesura": "caesura",
- #"stress": "",
+ "fingering": musicxml_fingering_event,
+ #"fingernails": "",
+ #"fret": "",
+ #"hammer-on": "",
+ "harmonic": "flageolet",
+ #"heel": "",
+ "inverted-mordent": "prall",
+ "inverted-turn": "reverseturn",
+ "mordent": "mordent",
+ #"open-string": "",
+ #"plop": "",
+ #"pluck": "",
+ #"portato": (musicexp.ShortArticulationEvent, "_"), # does not exist in MusicXML
+ #"pull-off": "",
+ #"schleifer": "?",
+ #"scoop": "",
+ #"shake": "?",
+ #"snap-pizzicato": "",
+ #"spiccato": "",
+ "staccatissimo": (musicexp.ShortArticulationEvent, "|"),
+ "staccato": (musicexp.ShortArticulationEvent, "."),
+ "stopped": (musicexp.ShortArticulationEvent, "+"),
+ #"stress": "",
+ #"string": "",
+ "strong-accent": (musicexp.ShortArticulationEvent, "^"),
+ #"tap": "",
+ "tenuto": (musicexp.ShortArticulationEvent, "-"),
+ #"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" ]
if mxl_event.get_name () in articulation_spanners:
return musicxml_spanner_to_lily_event (mxl_event)
- # special case, because of the bend-alter subelement
- if mxl_event.get_name() == "bend":
- return musicxml_bend_to_lily_event (mxl_event)
-
- # If we can write a shorthand, use them!
- if mxl_event.get_name() == "fingering":
- ev = musicexp.ShortArticulationEvent ()
- tp = mxl_event.get_text()
- # In all other cases, use the dicts to translate the xml tag name to a proper lilypond command
- elif short_articulations_dict.get (mxl_event.get_name ()):
- ev = musicexp.ShortArticulationEvent ()
- tp = short_articulations_dict.get (mxl_event.get_name ())
- else:
- ev = musicexp.ArticulationEvent ()
- tp = articulations_dict.get (mxl_event.get_name ())
-
- if not tp:
+ tmp_tp = articulations_dict.get (mxl_event.get_name ())
+ if not tmp_tp:
return
-
- ev.type = tp
+
+ 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
dir = musicxml_direction_to_indicator (mxl_event.type)
if hasattr (mxl_event, 'placement'):
dir = musicxml_direction_to_indicator (mxl_event.placement)
- # \breathe cannot have any direction modifier (^, _, -)!
- if dir and tp != "breathe":
- ev.force_direction = dir
return ev