+ start_attr = None
+ assign_to_next_note = []
+ id = None
+ for n in elements:
+ voice_id = n.get_maybe_exist_typed_child (get_class ('voice'))
+ if voice_id:
+ id = voice_id.get_text ()
+ else:
+ id = "None"
+
+ # We don't need backup/forward any more, since we have already
+ # assigned the correct onset times.
+ # TODO: Let Grouping through. Also: link, print, bokmark sound
+ if not (isinstance (n, Note) or isinstance (n, Attributes) or
+ isinstance (n, Direction) or isinstance (n, Partial) or
+ isinstance (n, Barline) or isinstance (n, Harmony) or
+ isinstance (n, FiguredBass) or isinstance (n, Print)):
+ continue
+
+ if isinstance (n, Attributes) and not start_attr:
+ start_attr = n
+ continue
+
+ if isinstance (n, Attributes):
+ # assign these only to the voices they really belong to!
+ for (s, vids) in staff_to_voice_dict.items ():
+ staff_attributes = part.extract_attributes_for_staff (n, s)
+ if staff_attributes:
+ for v in vids:
+ voices[v].add_element (staff_attributes)
+ continue
+
+ if isinstance (n, Partial) or isinstance (n, Barline) or isinstance (n, Print):
+ for v in voices.keys ():
+ voices[v].add_element (n)
+ 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 ())
+ else:
+ dir_voices = voices.keys ()
+ for v in dir_voices:
+ voices[v].add_element (n)
+ continue
+
+ if isinstance (n, Harmony) or isinstance (n, FiguredBass):
+ # store the harmony or figured bass element until we encounter
+ # the next note and assign it only to that one voice.
+ assign_to_next_note.append (n)
+ continue
+
+ if hasattr (n, 'print-object') and getattr (n, 'print-object') == "no":
+ #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)
+
+ # Assign all remaining elements from assign_to_next_note to the voice
+ # of the previous note:
+ for i in assign_to_next_note:
+ voices[id].add_element (i)
+ assign_to_next_note = []
+
+ if start_attr:
+ 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()
+
+ part._voices = voices