+ # make sure we know all voices already so that dynamics, clefs, etc.
+ # can be assigned to the correct voices
+ voice_to_staff_dict = {}
+ for n in elements:
+ voice_id = n.get_maybe_exist_named_child (u'voice')
+ vid = None
+ if voice_id:
+ vid = voice_id.get_text ()
+
+ staff_id = n.get_maybe_exist_named_child (u'staff')
+ sid = None
+ if staff_id:
+ sid = staff_id.get_text ()
+ else:
+ sid = "None"
+ if vid and not voices.has_key (vid):
+ voices[vid] = Musicxml_voice()
+ if vid and sid and not n.get_maybe_exist_typed_child (Grace):
+ if not voice_to_staff_dict.has_key (vid):
+ voice_to_staff_dict[vid] = sid
+ # invert the voice_to_staff_dict into a staff_to_voice_dict (since we
+ # need to assign staff-assigned objects like clefs, times, etc. to
+ # all the correct voices. This will never work entirely correct due
+ # to staff-switches, but that's the best we can do!
+ staff_to_voice_dict = {}
+ for (v,s) in voice_to_staff_dict.items ():
+ if not staff_to_voice_dict.has_key (s):
+ staff_to_voice_dict[s] = [v]
+ else:
+ staff_to_voice_dict[s].append (v)
+