]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Fix notes that end a slur and start a slur at the same time
authorReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 11 Nov 2008 20:50:50 +0000 (21:50 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 11 Nov 2008 23:15:45 +0000 (00:15 +0100)
input/regression/musicxml/04f-Slurs.xml [new file with mode: 0644]
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/04f-Slurs.xml b/input/regression/musicxml/04f-Slurs.xml
new file mode 100644 (file)
index 0000000..f500d93
--- /dev/null
@@ -0,0 +1,154 @@
+<?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
+  <movement-title>Slurs</movement-title>\r
+  <identification>\r
+    <creator type="composer">Reinhold Kainhofer</creator>\r
+    <rights>Public Domain</rights>\r
+    <encoding>\r
+      <software>Finale 2008 for Windows</software>\r
+      <software>Dolet Light for Finale 2008</software>\r
+      <encoding-date>2008-11-11</encoding-date>\r
+    </encoding>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name print-object="no">MusicXML Part</part-name>\r
+      <score-instrument id="P1-I1">\r
+        <instrument-name>Grand Piano</instrument-name>\r
+      </score-instrument>\r
+      <midi-instrument id="P1-I1">\r
+        <midi-channel>1</midi-channel>\r
+        <midi-program>1</midi-program>\r
+      </midi-instrument>\r
+    </score-part>\r
+  </part-list>\r
+  <!--=========================================================-->\r
+  <part id="P1">\r
+    <measure number="1">\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
+        <clef>\r
+          <sign>G</sign>\r
+          <line>2</line>\r
+        </clef>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>G</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <notations>\r
+          <slur number="1" placement="above" type="start"/>\r
+        </notations>\r
+      </note>\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
+        <notations>\r
+          <slur number="1" type="stop"/>\r
+          <slur number="1" placement="above" type="start"/>\r
+        </notations>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <notations>\r
+          <slur number="1" type="stop"/>\r
+          <slur number="1" placement="below" type="start"/>\r
+        </notations>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>G</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <notations>\r
+          <slur number="1" type="stop"/>\r
+        </notations>\r
+      </note>\r
+    </measure>\r
+    <!--=======================================================-->\r
+    <measure number="2">\r
+      <note>\r
+        <pitch>\r
+          <step>G</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <notations>\r
+          <slur number="1" placement="above" type="start"/>\r
+        </notations>\r
+      </note>\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
+        <notations>\r
+          <slur number="2" placement="above" type="start"/>\r
+        </notations>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem default-y="10.5">up</stem>\r
+        <notations>\r
+          <slur number="2" type="stop"/>\r
+        </notations>\r
+      </note>\r
+      <note default-x="312">\r
+        <pitch>\r
+          <step>G</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem default-y="5.5">up</stem>\r
+        <notations>\r
+          <slur number="1" type="stop"/>\r
+        </notations>\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 2a48cd12c13f2cc752620ad31da23853e9ca68a9..b01507273224b90ddf039ea235e01b130f6bccab 100644 (file)
@@ -1909,20 +1909,36 @@ def musicxml_voice_to_lily_voice (voice):
                 
                 tuplet_events.append ((ev_chord, tuplet_event, frac))
 
-            slurs = [s for s in notations.get_named_children ('slur')
-                if s.get_type () in ('start','stop')]
-            if slurs:
-                if len (slurs) > 1:
-                    error_message (_ ('cannot have two simultaneous slurs'))
+            # First, close all open slurs, only then start any new slur
+            # TODO: Record the number of the open slur to dtermine the correct
+            #       closing slur!
+            endslurs = [s for s in notations.get_named_children ('slur')
+                if s.get_type () in ('stop')]
+            if endslurs and not inside_slur:
+                endslurs[0].message (_ ('Encountered closing slur, but no slur is open'))
+            elif endslurs:
+                if len (endslurs) > 1:
+                    endslurs[0].message (_ ('Cannot have two simultaneous (closing) slurs'))
                 # record the slur status for the next note in the loop
                 if not grace:
-                    if slurs[0].get_type () == 'start':
-                        inside_slur = True
-                    elif slurs[0].get_type () == 'stop':
-                        inside_slur = False
-                lily_ev = musicxml_spanner_to_lily_event (slurs[0])
+                    inside_slur = False
+                lily_ev = musicxml_spanner_to_lily_event (endslurs[0])
                 ev_chord.append (lily_ev)
 
+            startslurs = [s for s in notations.get_named_children ('slur')
+                if s.get_type () in ('start')]
+            if startslurs and inside_slur:
+                startslurs[0].message (_ ('Cannot have a slur inside another slur'))
+            elif startslurs:
+                if len (startslurs) > 1:
+                    startslurs[0].message (_ ('Cannot have two simultaneous slurs'))
+                # record the slur status for the next note in the loop
+                if not grace:
+                    inside_slur = True
+                lily_ev = musicxml_spanner_to_lily_event (startslurs[0])
+                ev_chord.append (lily_ev)
+
+
             if not grace:
                 mxl_tie = notations.get_tie ()
                 if mxl_tie and mxl_tie.type == 'start':