From: Reinhold Kainhofer Date: Sun, 5 Apr 2009 21:42:38 +0000 (+0200) Subject: MusicXML: Don't crash when a part is missing the id attribute X-Git-Tag: release/2.12.3-1~40 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=6e040a3aa057586b059d1552d0afdd48d9d20944;p=lilypond.git MusicXML: Don't crash when a part is missing the id attribute Still missing: If there is only one part (which has the id missing), we could automatically assign the id... (cherry picked from commit e3ee8d211f06835f76fe9d5cd4fba50a1be47cc1) --- diff --git a/input/regression/musicxml/41g-PartNoId.xml b/input/regression/musicxml/41g-PartNoId.xml new file mode 100644 index 0000000000..337b851607 --- /dev/null +++ b/input/regression/musicxml/41g-PartNoId.xml @@ -0,0 +1,26 @@ + + + + + + A part with no id attribute. + Since this piece has only one part, it is clear which part + is described by the one part element. + + + + + MusicXML Part + + + + + + + 4 + 1 + whole + + + + diff --git a/input/regression/musicxml/41h-TooManyParts.xml b/input/regression/musicxml/41h-TooManyParts.xml new file mode 100644 index 0000000000..64b7dc90ba --- /dev/null +++ b/input/regression/musicxml/41h-TooManyParts.xml @@ -0,0 +1,47 @@ + + + + + + This piece has more part elements + than the part-list section gives. One can either convert all + the parts present, but not listed in the part-list, or simply + not import / ignore them. + + + + + MusicXML Part + + + + + + + 4 + 1 + whole + + + + + + + + 4 + 1 + whole + + + + + + + + 4 + 1 + whole + + + + diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 8abf58a3f6..b0f8091582 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -2547,7 +2547,17 @@ def voices_in_part (part): def voices_in_part_in_parts (parts): """return a Part -> Name -> Voice dictionary""" - return dict([(p.id, voices_in_part (p)) for p in parts]) + # don't crash if p doesn't have an id (that's invalid MusicXML, + # but such files are out in the wild! + dictionary = {} + for p in parts: + voices = voices_in_part (p) + if (hasattr (p, "id")): + dictionary[p.id] = voices + else: + # TODO: extract correct part id from other sources + dictionary[None] = voices + return dictionary; def get_all_voices (parts):