return cn[0]
+ def get_named_child_value_number (self, name, default):
+ n = self.get_maybe_exist_named_child (name)
+ if n:
+ return string.atoi (n.get_text())
+ else:
+ return default
+
+
class Music_xml_node (Xml_node):
def __init__ (self):
Xml_node.__init__ (self)
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 not (voice_id or isinstance (n, Attributes) or
isinstance (n, Direction) or isinstance (n, Partial) or
- isinstance (n, Barline) ):
+ isinstance (n, Barline) or isinstance (n, Harmony) ):
continue
if isinstance (n, Attributes) and not start_attr:
voices[v].add_element (n)
continue
+ if isinstance (n, Harmony):
+ # store the harmony element until we encounter the next note
+ # and assign it only to that one voice.
+ assign_to_next_note.append (n)
+ continue
+
id = voice_id.get_text ()
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)
class Words (Music_xml_node):
pass
+class Harmony (Music_xml_node):
+ pass
+
+class Frame (Music_xml_node):
+ def get_frets (self):
+ return self.get_named_child_value_number ('frame-frets', 4)
+ def get_strings (self):
+ return self.get_named_child_value_number ('frame-strings', 6)
+ def get_first_fret (self):
+ return self.get_named_child_value_number ('first-fret', 1)
+class Frame_Note (Music_xml_node):
+ def get_string (self):
+ return self.get_named_child_value_number ('string', 1)
+ def get_fret (self):
+ return self.get_named_child_value_number ('fret', 0)
+ def get_fingering (self):
+ return self.get_named_child_value_number ('fingering', -1)
+ def get_barre (self):
+ n = self.get_maybe_exist_named_child ('barre')
+ if n:
+ return getattr (n, 'type', '')
+ else:
+ return ''
+
## need this, not all classes are instantiated
## for every input file. Only add those classes, that are either directly
'direction': Direction,
'direction-type': DirType,
'duration': Duration,
+ 'frame': Frame,
+ 'frame-note': Frame_Note,
'glissando': Glissando,
'grace': Grace,
+ 'harmony': Harmony,
'identification': Identification,
'lyric': Lyric,
'measure': Measure,