]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Don't crash when no time signature is given
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 14 Sep 2007 23:38:02 +0000 (01:38 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 3 Oct 2007 16:39:20 +0000 (18:39 +0200)
MusicXML allows scores without time signature given. Don't assume that a time
sig will always be present!

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
python/musicxml.py

index 46473bf7469acbdac4fcb80ad8c5e6bdbd0d816c..5b335baafbef1873263d234a3e19d19fa0ddabbb 100644 (file)
@@ -226,11 +226,13 @@ class Attributes (Measure_element):
 
         try:
             mxl = self.get_named_attribute ('time')
-            
-            beats = mxl.get_maybe_exist_named_child ('beats')
-            type = mxl.get_maybe_exist_named_child ('beat-type')
-            return (int (beats.get_text ()),
-                    int (type.get_text ()))
+            if mxl:
+                beats = mxl.get_maybe_exist_named_child ('beats')
+                type = mxl.get_maybe_exist_named_child ('beat-type')
+                return (int (beats.get_text ()),
+                        int (type.get_text ()))
+            else:
+                return (4, 4)
         except KeyError:
             sys.stderr.write ('error: requested time signature, but time sig unknown')
             return (4, 4)
@@ -623,6 +625,8 @@ class Chord (Music_xml_node):
 class Dot (Music_xml_node):
     pass
 
+# 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)