From: Reinhold Kainhofer Date: Mon, 17 Nov 2008 14:50:56 +0000 (+0100) Subject: MusicXML: For notes/rests w/o type, use to calculate proper length X-Git-Tag: release/2.11.65-1~51^2~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1c81c9b6916279e0ed40871383ed6978dbc1f285;p=lilypond.git MusicXML: For notes/rests w/o type, use to calculate proper length --- diff --git a/input/regression/musicxml/00p-Rest-NoType.xml b/input/regression/musicxml/00p-Rest-NoType.xml new file mode 100644 index 0000000000..700ffadc38 --- /dev/null +++ b/input/regression/musicxml/00p-Rest-NoType.xml @@ -0,0 +1,91 @@ + + + + + + In some cases, a rest might + not have its type attribute set (this happens, for example, with + voices in Finale, where you don't manually insert a + rest). + + + + + MusicXML Part + + + + + + + 1 + + 0 + major + + + 2 + + G + 2 + + + F + 4 + + + + + C + 5 + + 1 + 1 + quarter + 1 + + + 1 + + + + 1 + 2 + 2 + + + + + + + A + 4 + + 4 + 1 + whole + 1 + + + 4 + + + + E + 3 + + 4 + 2 + whole + + + light-heavy + + + + + diff --git a/python/musicxml.py b/python/musicxml.py index e1a9446826..0e1cb4ae6d 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -382,8 +382,7 @@ class Note (Measure_element): # FIXME: is it ok to default to eight note for grace notes? return 3 else: - self.message (_ ("Encountered note at %s with %s duration (no element):") % (self.start, self.duration) ) - return 0 + return None def get_factor (self): return 1 diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 0dcaf10ab3..a99a5ece80 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -447,17 +447,22 @@ def extract_score_structure (part_list, staffinfo): def musicxml_duration_to_lily (mxl_note): d = musicexp.Duration () - # if the note has no Type child, then that method spits out a warning and - # returns 0, i.e. a whole note + # if the note has no Type child, then that method returns None. In that case, + # use the tag instead. If that doesn't exist, either -> Error d.duration_log = mxl_note.get_duration_log () - - d.dots = len (mxl_note.get_typed_children (musicxml.Dot)) - # Grace notes by specification have duration 0, so no time modification - # factor is possible. It even messes up the output with *0/1 - if not mxl_note.get_maybe_exist_typed_child (musicxml.Grace): - d.factor = mxl_note._duration / d.get_length () - - return d + if d.duration_log == None: + if mxl_note._duration > 0: + return rational_to_lily_duration (mxl_note._duration) + else: + mxl_note.message (_ ("Encountered note at %s without type and duration (=%s)") % (mxl_note.start, mxl_note._duration) ) + return None + else: + d.dots = len (mxl_note.get_typed_children (musicxml.Dot)) + # Grace notes by specification have duration 0, so no time modification + # factor is possible. It even messes up the output with *0/1 + if not mxl_note.get_maybe_exist_typed_child (musicxml.Grace): + d.factor = mxl_note._duration / d.get_length () + return d def rational_to_lily_duration (rational_len): d = musicexp.Duration ()