return self._children
def get_maybe_exist_named_child (self, name):
- return self.get_maybe_exist_typed_child (class_dict[name])
+ return self.get_maybe_exist_typed_child (class_dict.get (name))
def get_maybe_exist_typed_child (self, klass):
cn = self.get_typed_children (klass)
class Pitch (Music_xml_node):
def get_step (self):
- ch = self.get_unique_typed_child (class_dict[u'step'])
+ ch = self.get_unique_typed_child (class_dict.get (u'step'))
step = ch.get_text ().strip ()
return step
def get_octave (self):
- ch = self.get_unique_typed_child (class_dict[u'octave'])
+ ch = self.get_unique_typed_child (class_dict.get (u'octave'))
step = ch.get_text ().strip ()
return int (step)
def get_alteration (self):
- ch = self.get_maybe_exist_typed_child (class_dict[u'alter'])
+ ch = self.get_maybe_exist_typed_child (class_dict.get (u'alter'))
alter = 0
if ch:
alter = int (ch.get_text ().strip ())
self._dict[c.get_name()] = c
def get_named_attribute (self, name):
- return self._dict[name]
+ return self._dict.get (name)
def get_measure_length (self):
(n,d) = self.get_time_signature ()
self.instrument_name = ''
def get_duration_log (self):
- ch = self.get_maybe_exist_typed_child (class_dict[u'type'])
+ ch = self.get_maybe_exist_typed_child (class_dict.get (u'type'))
if ch:
log = ch.get_text ().strip()
'32nd': 5,
'breve': -1,
'long': -2,
- 'whole': 0} [log]
+ 'whole': 0}.get (log)
else:
return 0
return 1
def get_pitches (self):
- return self.get_typed_children (class_dict[u'pitch'])
+ return self.get_typed_children (class_dict.get (u'pitch'))
class Part_list (Music_xml_node):
def __init__ (self):
if not self._id_instrument_name_dict:
self.generate_id_instrument_dict()
- try:
- return self._id_instrument_name_dict[id]
- except KeyError:
+ instrument_name = self._id_instrument_name_dict.get (id)
+ if instrument_name:
+ return instrument_name
+ else:
print "Opps, couldn't find instrument for ID=", id
return "Grand Piano"
class Measure(Music_xml_node):
def get_notes (self):
- return self.get_typed_children (class_dict[u'note'])
+ return self.get_typed_children (class_dict.get (u'note'))
class Musicxml_voice:
attributes_object = n
factor = Rational (1,
- int (attributes_dict['divisions'].get_text ()))
+ int (attributes_dict.get ('divisions').get_text ()))
if (n.get_maybe_exist_typed_child (Duration)):
start_attr = None
for n in elements:
- voice_id = n.get_maybe_exist_typed_child (class_dict['voice'])
+ voice_id = n.get_maybe_exist_typed_child (class_dict.get ('voice'))
# TODO: If the first element of a voice is a dynamics entry,
# then voice_id is not yet set! Thus it will currently be ignored
class Time_modification(Music_xml_node):
def get_fraction (self):
- b = self.get_maybe_exist_typed_child (class_dict['actual-notes'])
- a = self.get_maybe_exist_typed_child (class_dict['normal-notes'])
+ b = self.get_maybe_exist_typed_child (class_dict.get ('actual-notes'))
+ a = self.get_maybe_exist_typed_child (class_dict.get ('normal-notes'))
return (int(a.get_text ()), int (b.get_text ()))
class Accidental (Music_xml_node):
return str (name)
def get_class (name):
- try:
- return class_dict[name]
- except KeyError:
+ classname = class_dict.get (name)
+ if classname:
+ return classname
+ else:
class_name = name2class_name (name)
klass = new.classobj (class_name, (Music_xml_node,) , {})
class_dict[name] = klass