]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Don't crash when a part is missing the id attribute
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 5 Apr 2009 21:42:38 +0000 (23:42 +0200)
committerNeil Puttock <n.puttock@gmail.com>
Sun, 19 Jul 2009 23:39:46 +0000 (00:39 +0100)
Still missing: If there is only one part (which has the id missing),
we could automatically assign the id...
(cherry picked from commit e3ee8d211f06835f76fe9d5cd4fba50a1be47cc1)

input/regression/musicxml/41g-PartNoId.xml [new file with mode: 0644]
input/regression/musicxml/41h-TooManyParts.xml [new file with mode: 0644]
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/41g-PartNoId.xml b/input/regression/musicxml/41g-PartNoId.xml
new file mode 100644 (file)
index 0000000..337b851
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="2.0">
+  <identification>
+    <miscellaneous>
+      <miscellaneous-field name="description">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.</miscellaneous-field>
+    </miscellaneous>
+  </identification>
+  <part-list>
+    <score-part id="P1">
+      <part-name print-object="no">MusicXML Part</part-name>
+    </score-part>
+  </part-list>
+  <part>
+    <measure number="1">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+</score-partwise>
diff --git a/input/regression/musicxml/41h-TooManyParts.xml b/input/regression/musicxml/41h-TooManyParts.xml
new file mode 100644 (file)
index 0000000..64b7dc9
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="2.0">
+  <identification>
+    <miscellaneous>
+      <miscellaneous-field name="description">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.</miscellaneous-field>
+    </miscellaneous>
+  </identification>
+  <part-list>
+    <score-part id="P1">
+      <part-name print-object="no">MusicXML Part</part-name>
+    </score-part>
+  </part-list>
+  <part id="P1">
+    <measure number="1">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+  <part id="P3">
+    <measure number="1">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+  <part id="P4">
+    <measure number="1">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+</score-partwise>
index 8abf58a3f66f0b84aeff1100fc03a4b54f5d7cf9..b0f8091582220b01b1cb1ed6a6b541eef70338b4 100644 (file)
@@ -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):