+
+class Sound(Music_xml_node):
+
+ def get_tempo(self):
+ """
+ Return the tempo attribute(if it exists) of the sound element.
+ This attribute can be used by musicxml2ly for the midi output(see L{musicexp.Score}).
+
+ @rtype: string
+ @return: The value of the tempo attribute
+ """
+ if hasattr(self, 'tempo'):
+ return self.tempo
+ else:
+ return None
+
+
+class Notations(Music_xml_node):
+
+ def get_tie(self):
+ ts = self.get_named_children('tied')
+ starts = [t for t in ts if t.type == 'start']
+ if starts:
+ return starts[0]
+ else:
+ return None
+
+ def get_tuplets(self):
+ return self.get_typed_children(Tuplet)
+
+
+class Time_modification(Music_xml_node):
+
+ def get_fraction(self):
+ b = self.get_maybe_exist_named_child('actual-notes')
+ a = self.get_maybe_exist_named_child('normal-notes')
+ return(int(a.get_text()), int(b.get_text()))
+
+ def get_normal_type(self):
+ tuplet_type = self.get_maybe_exist_named_child('normal-type')
+ if tuplet_type:
+ dots = self.get_named_children('normal-dot')
+ log = utilities.musicxml_duration_to_log(tuplet_type.get_text().strip())
+ return(log , len(dots))
+ else:
+ return None
+
+
+class Accidental(Music_xml_node):
+
+ def __init__(self):
+ Music_xml_node.__init__(self)
+ self.editorial = False
+ self.cautionary = False
+
+
+class Tuplet(Music_xml_spanner):
+
+ def duration_info_from_tuplet_note(self, tuplet_note):
+ tuplet_type = tuplet_note.get_maybe_exist_named_child('tuplet-type')
+ if tuplet_type:
+ dots = tuplet_note.get_named_children('tuplet-dot')
+ log = utilities.musicxml_duration_to_log(tuplet_type.get_text().strip())
+ return(log, len(dots))
+ else:
+ return None
+
+ # Return tuplet note type as(log, dots)
+ def get_normal_type(self):
+ tuplet = self.get_maybe_exist_named_child('tuplet-normal')
+ if tuplet:
+ return self.duration_info_from_tuplet_note(tuplet)
+ else:
+ return None
+
+ def get_actual_type(self):
+ tuplet = self.get_maybe_exist_named_child('tuplet-actual')
+ if tuplet:
+ return self.duration_info_from_tuplet_note(tuplet)
+ else:
+ return None
+
+ def get_tuplet_note_count(self, tuplet_note):
+ if tuplet_note:
+ tuplet_nr = tuplet_note.get_maybe_exist_named_child('tuplet-number')
+ if tuplet_nr:
+ return int(tuplet_nr.get_text())
+ return None
+
+ def get_normal_nr(self):
+ return self.get_tuplet_note_count(self.get_maybe_exist_named_child('tuplet-normal'))
+
+ def get_actual_nr(self):
+ return self.get_tuplet_note_count(self.get_maybe_exist_named_child('tuplet-actual'))
+
+
+class Slur(Music_xml_spanner):
+
+ def get_type(self):
+ return self.type
+
+
+class Tied(Music_xml_spanner):
+
+ def get_type(self):
+ return self.type
+
+
+class Beam(Music_xml_spanner):
+ def get_type(self):
+ return self.get_text()
+ def is_primary(self):
+ if hasattr(self, 'number'):
+ return self.number == "1"
+ else:
+ return True
+
+class Octave_shift(Music_xml_spanner):
+ # default is 8 for the octave-shift!
+ def get_size(self):
+ if hasattr(self, 'size'):
+ return int(self.size)
+ else:
+ return 8
+
+
+# Rests in MusicXML are <note> blocks with a <rest> inside. This class is only
+# for the inner <rest> element, not the whole rest block.
+class Rest(Music_xml_node):
+
+ def __init__(self):
+ Music_xml_node.__init__(self)
+ self._is_whole_measure = False
+
+ def is_whole_measure(self):
+ return self._is_whole_measure
+
+ def get_step(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'display-step'))
+ if ch:
+ return ch.get_text().strip()
+ else:
+ return None
+
+ def get_octave(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'display-octave'))
+ if ch:
+ oct = ch.get_text().strip()
+ return int(oct)
+ else:
+ return None
+
+ def to_lily_object(self):
+ p = None
+ step = self.get_step()
+ if step:
+ p = musicexp.Pitch()
+ p.step = musicxml2ly_conversion.musicxml_step_to_lily(step)
+ octave = self.get_octave()
+ if octave and p:
+ p.octave = octave - 4
+ return p
+
+
+class Bend(Music_xml_node):
+
+ def bend_alter(self):
+ alter = self.get_maybe_exist_named_child('bend-alter')
+ return utilities.interpret_alter_element(alter)
+
+
+class ChordPitch(Music_xml_node):
+
+ def step_class_name(self):
+ return u'root-step'
+
+ def alter_class_name(self):
+ return u'root-alter'
+
+ def get_step(self):
+ ch = self.get_unique_typed_child(get_class(self.step_class_name()))
+ return ch.get_text().strip()
+
+ def get_alteration(self):
+ ch = self.get_maybe_exist_typed_child(get_class(self.alter_class_name()))
+ return utilities.interpret_alter_element(ch)
+
+
+class Bass(ChordPitch):
+
+ def step_class_name(self):
+ return u'bass-step'
+
+ def alter_class_name(self):
+ return u'bass-alter'
+
+
+class ChordModification(Music_xml_node):
+
+ def get_type(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'degree-type'))
+ return {'add': 1, 'alter': 1, 'subtract':-1}.get(ch.get_text().strip(), 0)
+
+ def get_value(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'degree-value'))
+ value = 0
+ if ch:
+ value = int(ch.get_text().strip())
+ return value
+
+ def get_alter(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'degree-alter'))
+ return utilities.interpret_alter_element(ch)
+
+
+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 ''
+
+