]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXMl: Fix fretboard assignment to voices.
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 26 Oct 2007 15:00:18 +0000 (17:00 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 26 Oct 2007 15:00:18 +0000 (17:00 +0200)
Instead of assigning <harmony> elements to every voice or only the very
first voice (in the frist case, we'll have duplicated frets, in the
second one the fretboards will often be inserted at the completely
wrong position), simply insert the fretboard into the next note that
we encounter in the MusicXML file.

I suppose we could also do something similar for text markup (i.e.
<direction><words>...</word></direction>), but there we need to
distinguish direction elements with words-only subelements and with
dynamics subelements.

python/musicxml.py

index 3c38f30828ea09d669a9241deb81e2971c300782..84ffb75080fe7d7165fb60e72a9eb447d967a8df 100644 (file)
@@ -613,6 +613,7 @@ class Part (Music_xml_node):
 
 
        start_attr = None
+        assign_to_next_note = []
        for n in elements:
            voice_id = n.get_maybe_exist_typed_child (get_class ('voice'))
 
@@ -639,18 +640,21 @@ class Part (Music_xml_node):
                 continue
 
             if isinstance (n, Direction) or isinstance (n, Harmony):
-                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 ())
-                else:
-                    dir_voices = voices.keys ()
-                # assign only to first voice, otherwise we'll have duplicates!
-                if dir_voices:
-                    voices[dir_voices[0]].add_element (n)
-                #for v in dir_voices:
-                    #voices[v].add_element (n)
+                # store the harmony element until we encounter the next note
+                # and assign it only to that one voice.
+                assign_to_next_note.append (n)
+                #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 ())
+                #else:
+                    #dir_voices = voices.keys ()
+                ## assign only to first voice, otherwise we'll have duplicates!
+                #if dir_voices:
+                    #voices[dir_voices[0]].add_element (n)
+                ##for v in dir_voices:
+                    ##voices[v].add_element (n)
                 continue
 
            id = voice_id.get_text ()
@@ -658,6 +662,9 @@ class Part (Music_xml_node):
                 #Skip this note. 
                 pass
             else:
+                for i in assign_to_next_note:
+                    voices[id].add_element (i)
+                assign_to_next_note = []
                 voices[id].add_element (n)
 
        if start_attr: