From da90ac3105f2e5b7326929a30a0ecae827814f2e Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Sat, 15 Sep 2007 01:38:02 +0200 Subject: [PATCH] MusicXML: Don't crash when no time signature is given MusicXML allows scores without time signature given. Don't assume that a time sig will always be present! Signed-off-by: Reinhold Kainhofer --- python/musicxml.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/musicxml.py b/python/musicxml.py index 46473bf746..5b335baafb 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -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 blocks with a inside. This class is only +# for the inner element, not the whole rest block. class Rest (Music_xml_node): def __init__ (self): Music_xml_node.__init__ (self) -- 2.39.5