]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Improvements / Fixes for articulations
authorReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 31 Oct 2007 15:56:30 +0000 (16:56 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 31 Oct 2007 15:56:30 +0000 (16:56 +0100)
Implement some more conversions for articulations, make \context Staff
actually use the type attribute instead of hard-coded "Staff", fix crashes
due to empty type attributes in articulations.

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

index d4f90827e2dd8b05fb05de4c29b1f502fdee02eb..edae323f7945a2e95b630acd206437c875a99848 100644 (file)
@@ -685,9 +685,13 @@ class GlissandoEvent (SpanEvent):
             1:''}.get (self.span_direction, '')
 
 class ArpeggioEvent(Event):
+    def __init__ (self):
+        Event.__init__ (self)
+        self.direction = 0
     def wait_for_note (self):
         return True;
     def ly_expression (self):
+        # TODO: Use self.direction for up/down arpeggios
         return ('\\arpeggio')
 
 
@@ -776,11 +780,17 @@ class ShortArticulationEvent (ArticulationEvent):
         # default is -
         return { 1: '^', -1: '_', 0: '-' }.get (self.force_direction, '-')
     def ly_expression (self):
-        return '%s%s' % (self.direction_mod (), self.type)
+        if self.type:
+            return '%s%s' % (self.direction_mod (), self.type)
+        else:
+            return ''
 
 class NoDirectionArticulationEvent (ArticulationEvent):
     def ly_expression (self):
-        return '\\%s' % self.type
+        if self.type:
+            return '\\%s' % self.type
+        else:
+            return ''
 
 class MarkupEvent (ShortArticulationEvent):
     def __init__ (self):
@@ -1115,9 +1125,9 @@ class Staff (StaffGroup):
 
         for [staff_id, voices] in self.part_information:
             if staff_id:
-                printer ('\\context Staff = "%s" << ' % staff_id)
+                printer ('\\context %s = "%s" << ' % (self.stafftype, staff_id))
             else:
-                printer ('\\context Staff << ')
+                printer ('\\context %s << ' % self.stafftype)
             printer.newline ()
             n = 0
             nr_voices = len (voices)
index cd260a404be76dbe1c863d74288f887f639d2b4f..cb8e1957cb2f500ff7b5219529e4295d189d6e4c 100644 (file)
@@ -439,11 +439,11 @@ class Musicxml_voice:
             return self._lyrics
 
 
-
 class Part (Music_xml_node):
     def __init__ (self):
         Music_xml_node.__init__ (self)
        self._voices = []
+        self._staff_attributes_dict = {}
 
     def get_part_list (self):
         n = self
@@ -679,6 +679,7 @@ class Part (Music_xml_node):
             for (s, vids) in staff_to_voice_dict.items ():
                 staff_attributes = part.extract_attributes_for_staff (start_attr, s)
                 staff_attributes.read_self ()
+                part._staff_attributes_dict[s] = staff_attributes
                 for v in vids:
                     voices[v].insert (0, staff_attributes)
                     voices[v]._elements[0].read_self()
index be4cc8343a47edbdef8cf82887301c8eb8a5ad7c..9b99d3abd0897182f3a608ba6261fe8e10041465 100644 (file)
@@ -568,6 +568,13 @@ def musicxml_fermata_to_lily_event (mxl_event):
         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 ()
@@ -618,13 +625,13 @@ def musicxml_accidental_mark (mxl_event):
 #   -) (class, name)  (like string, only that a different class than ArticulationEvent is used)
 # TODO: Some translations are missing!
 articulations_dict = {
-    "accent": (musicexp.ShortArticulationEvent, ">"),
+    "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": "",
+    "detached-legato": (musicexp.ShortArticulationEvent, "_"), # or "portato"
     #"doit": "",
     #"double-tongue": "",
     "down-bow": "downbow",
@@ -638,24 +645,23 @@ articulations_dict = {
     "inverted-mordent": "prall",
     "inverted-turn": "reverseturn",
     "mordent": "mordent",
-    #"open-string": "",
+    "open-string": "open",
     #"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, "+"),
+    "staccatissimo": (musicexp.ShortArticulationEvent, "|"), # or "staccatissimo"
+    "staccato": (musicexp.ShortArticulationEvent, "."), # or "staccato"
+    "stopped": (musicexp.ShortArticulationEvent, "+"), # or "stopped"
     #"stress": "",
     "string": musicxml_string_event,
-    "strong-accent": (musicexp.ShortArticulationEvent, "^"),
+    "strong-accent": (musicexp.ShortArticulationEvent, "^"), # or "marcato"
     #"tap": "",
-    "tenuto": (musicexp.ShortArticulationEvent, "-"),
+    "tenuto": (musicexp.ShortArticulationEvent, "-"), # or "tenuto"
     #"thumb-position": "",
     #"toe": "",
     "turn": "turn",
@@ -1211,7 +1217,9 @@ def musicxml_voice_to_lily_voice (voice):
 
             arpeggiate = notations.get_named_children ('arpeggiate')
             for a in arpeggiate:
-                ev_chord.append (musicexp.ArpeggioEvent ())
+                ev = musicxml_arpeggiate_to_lily_event (a)
+                if ev:
+                    ev_chord.append (ev)
 
             glissandos = notations.get_named_children ('glissando')
             for a in glissandos:
@@ -1492,7 +1500,6 @@ def update_score_setup (score_structure, part_list, voices):
             staves = uniq_list (staves)
             staves.sort ()
             for s in staves:
-                #((music, lyrics), mxlvoice))
                 thisstaff_raw_voices = [(voice_name, voice.lyrics_order) 
                     for (voice_name, voice) in nv_dict.items ()
                     if voice.voicedata._start_staff == s]