]> git.donarmstrong.com Git - lilypond.git/commitdiff
Convert articulations like fermata, staccato, tenuto, tremolo (only single-note tremo...
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 19 Aug 2007 21:50:29 +0000 (23:50 +0200)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 20 Aug 2007 03:35:14 +0000 (00:35 -0300)
These entries in the xml are inside the <notation>...</notation> tags, listed in the <ornaments>, <technical> and <articulations> tags.

python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

index e7b3870425cabd4344322035742174c9b533c6d5..56252f339e4e4e8e089da084b22ff8fc10893b41 100644 (file)
@@ -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)
index 3466473c4352a879c2d1259e46f4f3b6d90f6f4a..304b2c62d246a8ee993d97c9a21e090e0e46f817 100644 (file)
@@ -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):
index e3582682349ade26bacab3022af1c7c51b534567..3a5f465087310864f7006f0141c3f2a3f1ae19fa 100644 (file)
@@ -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 <notation> 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')