Attached is a git diff to translate articulations from MusicXML to lilypond.
It's basically the patch from yesterday with a few style-fixes as requested
by Han-Wen.
Cheers,
Reinhold
PS: If anyone needs an ubuntu package for guile 1.8.2, I have built one to be
able to build lilypond.
--
--
Reinhold Kainhofer, Vienna University of Technology, Austria
email: [EMAIL PROTECTED], http://reinhold.kainhofer.com/
* Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at/
* K Desktop Environment, http://www.kde.org, KOrganizer maintainer
* Chorvereinigung "Jung-Wien", http://www.jung-wien.at/
From 757c4f75afadfd94e0480435374ed526f9282a91 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <[EMAIL PROTECTED]>
Date: Sat, 18 Aug 2007 12:02:39 +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 | 30 +-
python/musicxml.py | 36 +++
scripts/musicxml2ly.py | 151 +++-
3 files changed, 214 insertions(+), 3 deletions(-)
diff --git a/python/musicexp.py b/python/musicexp.py
index e7b3870..963b311 100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -498,7 +498,35 @@ 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 = ''
+try:
+dirstr += { 1: '^', -1: '_', 0: '-' }[self.force_direction]
+except KeyError:
+pass
+return dirstr
+
+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..77561f3 100644
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -168,6 +168,101 @@ def musicxml_spanner_to_lily_event (mxl_event):
return ev
+def musicxml_direction_to_indicator (direction):
+returnval = None
+try:
+ val = { "above": 1, "upright": 1, "below": -1, "downright": -1 }[direction];
+ returnval = val
+except (KeyError):
+ pass
+return returnval
+
+def musicxml_fermata_to_lily_event (mxl_event):
+ev = musicexp.ArticulationEvent ()
+ev.type = "fermata"
+try:
+ dir = musicxml_direction_to_indicator( mxl_event.type )
+ if dir:
+ev.force_direction = dir
+except (AttributeError, KeyError):
+ pass
+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": "",
+#