start_attr = None
+ assign_to_next_note = []
for n in elements:
voice_id = n.get_maybe_exist_typed_child (get_class ('voice'))
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 ()
#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: