From ad228b1e645d8f8e0bf0116d784a76f73dbc0a67 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer
Date: Sun, 19 Aug 2007 23:50:29 +0200
Subject: [PATCH] Convert articulations like fermata, staccato, tenuto, tremolo (only single-note tremolo), accents, etc.
These entries in the xml are inside the ... tags, listed in the , and tags.
---
python/musicexp.py | 29 ++++++++++-
python/musicxml.py | 36 +++++++++++++
scripts/musicxml2ly.py | 136 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 200 insertions(+), 1 deletions(-)
diff --git a/python/musicexp.py b/python/musicexp.py
index e7b3870..56252f3 100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -498,7 +498,34 @@ class TieEvent(Event):
def ly_expression (self):
return '~'
-
+
+class ArticulationEvent (Event):
+ def __init__ (self):
+ self.type = None
+ self.force_direction = None
+
+ def direction_mod (self):
+ dirstr = { 1: '^', -1: '_', 0: '-' }.get (self.force_direction)
+ if dirstr:
+ return dirstr
+ else:
+ return ''
+
+ def ly_expression (self):
+ return '%s\\%s' % (self.direction_mod (), self.type)
+
+
+class TremoloEvent (Event):
+ def __init__ (self):
+ self.bars = 0;
+
+ def ly_expression (self):
+ str=''
+ if self.bars > 0:
+ str += ':%s' % (2 ** (2 + string.atoi (self.bars)))
+ return str
+
+
class RhythmicEvent(Event):
def __init__ (self):
Event.__init__ (self)
diff --git a/python/musicxml.py b/python/musicxml.py
index 3466473..304b2c6 100644
--- a/python/musicxml.py
+++ b/python/musicxml.py
@@ -450,6 +450,32 @@ class Staff (Music_xml_node):
class Instrument (Music_xml_node):
pass
+class Fermata (Music_xml_node):
+ pass
+class Dynamics (Music_xml_node):
+ pass
+class Articulations (Music_xml_node):
+ pass
+class Accent (Music_xml_node):
+ pass
+class Staccato (Music_xml_node):
+ pass
+class Tenuto (Music_xml_node):
+ pass
+class Tremolo (Music_xml_node):
+ pass
+class Technical (Music_xml_node):
+ pass
+class Ornaments (Music_xml_node):
+ pass
+
+
+class Direction (Music_xml_node):
+ pass
+class DirType (Music_xml_node):
+ pass
+
+
## need this, not all classes are instantiated
## for every input file.
class_dict = {
@@ -477,6 +503,16 @@ class_dict = {
'type': Type,
'part-list': Part_list,
'staff': Staff,
+ 'fermata': Fermata,
+ 'articulations': Articulations,
+ 'accent': Accent,
+ 'staccato': Staccato,
+ 'tenuto': Tenuto,
+ 'tremolo': Tremolo,
+ 'technical': Technical,
+ 'ornaments': Ornaments,
+ 'direction': Direction,
+ 'direction-type': DirType
}
def name2class_name (name):
diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py
index e358268..3a5f465 100644
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -168,6 +168,99 @@ def musicxml_spanner_to_lily_event (mxl_event):
return ev
+def musicxml_direction_to_indicator (direction):
+ val = { "above": 1, "upright": 1, "below": -1, "downright": -1 }.get (direction)
+ if val:
+ return val
+ else:
+ return ''
+
+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_tremolo_to_lily_event(mxl_event):
+ if mxl_event.get_name () != "tremolo":
+ return
+ ev = musicexp.TremoloEvent ()
+ ev.bars = mxl_event.get_text ()
+ return ev
+
+# 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": "?",
+ #"schleifer": "?"
+ ##### TECHNICALS
+ "up-bow": "upbow",
+ "down-bow": "downbow",
+ #"harmonic": "",
+ #"open-string": "",
+ #"thumb-position": "",
+ #"fingering": "",
+ #"pluck": "",
+ #"double-tongue": "",
+ #"triple-tongue": "",
+ #"stopped": "",
+ #"snap-pizzicato": "",
+ #"fret": "",
+ #"string": "",
+ #"hammer-on": "",
+ #"pull-off": "",
+ #"bend": "",
+ #"tap": "",
+ #"heel": "",
+ #"toe": "",
+ #"fingernails": ""
+ ##### ARTICULATIONS
+ "accent": "accent",
+ "strong-accent": "marcato",
+ "staccato": "staccato",
+ "tenuto": "tenuto",
+ #"detached-legato": "",
+ "staccatissimo": "staccatissimo",
+ #"spiccato": "",
+ #"scoop": "",
+ #"plop": "",
+ #"doit": "",
+ #"falloff": "",
+ "breath-mark": "breathe",
+ #"caesura": "caesura",
+ #"stress": "",
+ #"unstress": ""
+}
+
+def musicxml_articulation_to_lily_event(mxl_event):
+ ev = musicexp.ArticulationEvent ()
+ tp = articulations_dict.get (mxl_event.get_name ())
+ if not tp:
+ return
+
+ ev.type = tp
+
+ # 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)
+ if dir:
+ ev.force_direction = dir
+ return ev
+
+
instrument_drumtype_dict = {
'Acoustic Snare Drum': 'acousticsnare',
'Side Stick': 'sidestick',
@@ -353,6 +446,12 @@ def musicxml_voice_to_lily_voice (voice):
notations = n.get_maybe_exist_typed_child (musicxml.Notations)
tuplet_event = None
span_events = []
+
+ # The element can have the following children (+ means implemented, ~ partially, - not):
+ # +tied | +slur | +tuplet | glissando | slide |
+ # ornaments | technical | articulations | dynamics |
+ # +fermata | arpeggiate | non-arpeggiate |
+ # accidental-mark | other-notation
if notations:
if notations.get_tuplet():
tuplet_event = notations.get_tuplet()
@@ -375,6 +474,43 @@ def musicxml_voice_to_lily_voice (voice):
mxl_tie = notations.get_tie ()
if mxl_tie and mxl_tie.type == 'start':
ev_chord.append (musicexp.TieEvent ())
+
+ fermatas = notations.get_named_children ('fermata')
+ for a in fermatas:
+ ev = musicxml_fermata_to_lily_event (a);
+ if ev:
+ ev_chord.append (ev)
+
+ # Articulations can contain the following child elements:
+ # accent | strong-accent | staccato | tenuto |
+ # detached-legato | staccatissimo | spiccato |
+ # scoop | plop | doit | falloff | breath-mark |
+ # caesura | stress | unstress
+ # Technical can contain the following child elements:
+ # up-bow | down-bow | harmonic | open-string |
+ # thumb-position | fingering | pluck | double-tongue |
+ # triple-tongue | stopped | snap-pizzicato | fret |
+ # string | hammer-on | pull-off | bend | tap | heel |
+ # toe | fingernails | other-technical
+ # Ornaments can contain the following child elements:
+ # trill-mark | turn | delayed-turn | inverted-turn |
+ # shake | wavy-line | mordent | inverted-mordent |
+ # schleifer | tremolo | other-ornament, accidental-mark
+ ornaments = notations.get_named_children ('ornaments')
+ for a in ornaments:
+ for ch in a.get_named_children ('tremolo'):
+ ev = musicxml_tremolo_to_lily_event (ch)
+ if ev:
+ ev_chord.append (ev)
+
+ ornaments += notations.get_named_children ('articulations')
+ ornaments += notations.get_named_children ('technical')
+
+ for a in ornaments:
+ for ch in a.get_all_children ():
+ ev = musicxml_articulation_to_lily_event (ch)
+ if ev:
+ ev_chord.append (ev)
mxl_beams = [b for b in n.get_named_children ('beam')
if (b.get_type () in ('begin', 'end')
--
1.5.2.3