]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/musicxml.py
lilypond-manuals.css: edit color scheme and some spacing
[lilypond.git] / python / musicxml.py
index c4635c6aca29705a7fe7ab9b1178621f6aa99738..ae5ca80a59647dca423d6b374bf6b595b53ee315 100644 (file)
@@ -124,6 +124,7 @@ class Music_xml_node(Xml_node):
         self.duration = Rational(0)
         self.start = Rational(0)
         self.converted = False
+        self.voice_id = None;
 
 
 class Music_xml_spanner(Music_xml_node):
@@ -144,11 +145,11 @@ class Music_xml_spanner(Music_xml_node):
 class Measure_element(Music_xml_node):
 
     def get_voice_id(self):
-        voice_id = self.get_maybe_exist_named_child('voice')
-        if voice_id:
-            return voice_id.get_text()
+        voice = self.get_maybe_exist_named_child('voice')
+        if voice:
+            return voice.get_text()
         else:
-            return None
+            return self.voice_id
 
     def is_first(self):
         # Look at all measure elements(previously we had self.__class__, which
@@ -440,6 +441,15 @@ class Unpitched(Music_xml_node):
         return p
 
 
+class Measure_element (Music_xml_node):
+    def get_voice_id (self):
+        voice = self.get_maybe_exist_named_child ('voice')
+        if voice:
+            return voice.get_text ()
+        else:
+            return self.voice_id;
+
+
 class Attributes(Measure_element):
 
     def __init__(self):
@@ -949,7 +959,7 @@ class Syllabic(Music_xml_node):
 
 class Lyric(Music_xml_node):
 
-    def get_number(self):
+    def number(self):
         """
         Return the number attribute(if it exists) of the lyric element.
 
@@ -1231,7 +1241,7 @@ class Musicxml_voice:
           self.has_lyrics = len(lyrics) > 0
 
         for l in lyrics:
-            nr = l.get_number()
+            nr = l.number
             if(nr > 0) and not(nr in self._lyrics):
                 self._lyrics.append(nr)
 
@@ -1310,7 +1320,25 @@ class Part(Music_xml_node):
                 measure_start_moment = now
                 measure_position = Rational(0)
 
-            for n in m.get_all_children():
+            voice_id = None;
+            assign_to_next_voice = []
+            for n in m.get_all_children ():
+                # assign a voice to all measure elements
+                if (n.get_name() == 'backup'):
+                    voice_id = None;
+
+                if isinstance(n, Measure_element):
+                    if n.get_voice_id ():
+                        voice_id = n.get_voice_id ()
+                        for i in assign_to_next_voice:
+                            i.voice_id = voice_id
+                        assign_to_next_voice = []
+                    else:
+                        if voice_id:
+                            n.voice_id = voice_id
+                        else:
+                            assign_to_next_voice.append (n)
+
                 # figured bass has a duration, but applies to the next note
                 # and should not change the current measure position!
                 if isinstance(n, FiguredBass):
@@ -1530,15 +1558,10 @@ class Part(Music_xml_node):
                 continue
 
             if isinstance(n, Direction):
-                staff_id = n.get_maybe_exist_named_child(u'staff')
-                if staff_id:
-                    staff_id = staff_id.get_text()
-                if staff_id:
-                    dir_voices = staff_to_voice_dict.get(staff_id, voices.keys())
+                if (n.voice_id):
+                    voices[n.voice_id].add_element (n)
                 else:
-                    dir_voices = voices.keys()
-                for v in dir_voices:
-                    voices[v].add_element(n)
+                    assign_to_next_note.append (n)
                 continue
 
             if isinstance(n, Harmony) or isinstance(n, FiguredBass):
@@ -1607,7 +1630,7 @@ class Dashes(Music_xml_spanner):
 class DirType(Music_xml_node):
     pass
 
-class Direction(Music_xml_node):
+class Direction(Measure_element):
     pass
 
 class Dot(Music_xml_node):
@@ -1637,6 +1660,9 @@ class Hash_comment(Music_xml_node):
 class KeyAlter(Music_xml_node):
     pass
 
+class Direction (Measure_element):
+    pass
+
 class KeyOctave(Music_xml_node):
     pass