]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: For notes/rests w/o type, use <duration> to calculate proper length
authorReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 17 Nov 2008 14:50:56 +0000 (15:50 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 17 Nov 2008 14:50:56 +0000 (15:50 +0100)
input/regression/musicxml/00p-Rest-NoType.xml [new file with mode: 0644]
python/musicxml.py
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/00p-Rest-NoType.xml b/input/regression/musicxml/00p-Rest-NoType.xml
new file mode 100644 (file)
index 0000000..700ffad
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.1 Partwise//EN"\r
+                                "http://www.musicxml.org/dtds/partwise.dtd">\r
+<score-partwise version="1.1">\r
+  <identification>\r
+    <miscellaneous>\r
+      <miscellaneous-field name="description">In some cases, a rest might \r
+          not have its type attribute set (this happens, for example, with\r
+          voices in Finale, where you don't manually insert a \r
+          rest).</miscellaneous-field>\r
+    </miscellaneous>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name>MusicXML Part</part-name>\r
+    </score-part>\r
+  </part-list>\r
+  <!--=========================================================-->\r
+  <part id="P1">\r
+    <measure implicit="yes" number="0">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>0</fifths>\r
+          <mode>major</mode>\r
+        </key>\r
+        <time symbol="common">\r
+          <beats>4</beats>\r
+          <beat-type>4</beat-type>\r
+        </time>\r
+        <staves>2</staves>\r
+        <clef number="1">\r
+          <sign>G</sign>\r
+          <line>2</line>\r
+        </clef>\r
+        <clef number="2">\r
+          <sign>F</sign>\r
+          <line>4</line>\r
+        </clef>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>C</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <staff>1</staff>\r
+      </note>\r
+      <backup>\r
+        <duration>1</duration>\r
+      </backup>\r
+      <note>\r
+        <rest/>\r
+        <duration>1</duration>\r
+        <voice>2</voice>\r
+        <staff>2</staff>\r
+      </note>\r
+    </measure>\r
+    <!--=======================================================-->\r
+    <measure number="1">\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</voice>\r
+        <type>whole</type>\r
+        <staff>1</staff>\r
+      </note>\r
+      <backup>\r
+        <duration>4</duration>\r
+      </backup>\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <octave>3</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>2</voice>\r
+        <type>whole</type>\r
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+</score-partwise>\r
index e1a9446826bc18d7311110e992712bda8b62f0e9..0e1cb4ae6d087da34db85133daa7d453af274044 100644 (file)
@@ -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 <type> element):") % (self.start, self.duration) )
-            return 0
+            return None
 
     def get_factor (self):
         return 1
index 0dcaf10ab3fc2239e5f1ffefac65b5c945afc9db..a99a5ece808b521f980994517ffe598879edfafa 100644 (file)
@@ -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 <duration> 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 ()