]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Implement support for transposed instruments
authorReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 18 Nov 2008 19:19:21 +0000 (20:19 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 18 Nov 2008 20:51:21 +0000 (21:51 +0100)
We simply need to take the <transpose> attribute and determine
the correct sounding pitch from the chromatic tag (adjust it
enharmonically if an explicit diatonic shift is given)...

input/regression/musicxml/16-TransposingInstruments.itexi [new file with mode: 0644]
input/regression/musicxml/16a-TransposingInstruments.xml [new file with mode: 0644]
input/regression/musicxml/16b-TransposingInstruments-Full.xml [new file with mode: 0644]
python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/16-TransposingInstruments.itexi b/input/regression/musicxml/16-TransposingInstruments.itexi
new file mode 100644 (file)
index 0000000..1bdbb55
--- /dev/null
@@ -0,0 +1,2 @@
+@section Transposing instruments
+
diff --git a/input/regression/musicxml/16a-TransposingInstruments.xml b/input/regression/musicxml/16a-TransposingInstruments.xml
new file mode 100644 (file)
index 0000000..82cb627
--- /dev/null
@@ -0,0 +1,333 @@
+<?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">Transposing instruments: Trumpet \r
+          in Bb, Horn in Eb, Piano; All of them show the C major scale (the \r
+          trumpet with 2 sharp, the horn with 3 sharp).</miscellaneous-field>\r
+    </miscellaneous>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name>Trumpet in Bb</part-name>\r
+      <part-abbreviation>Bb Tpt.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P2">\r
+      <part-name>Horn in Eb</part-name>\r
+      <part-abbreviation>Hn.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P3">\r
+      <part-name>Piano</part-name>\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>2</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
+        <transpose>\r
+          <diatonic>-1</diatonic>\r
+          <chromatic>-2</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>F</step>\r
+          <alter>1</alter>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\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
+      </note>\r
+    </measure>\r
+    <!--=======================================================-->\r
+    <measure number="2">\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
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>B</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>C</step>\r
+          <alter>1</alter>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+  <part id="P2">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>3</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
+        <transpose>\r
+          <diatonic>-5</diatonic>\r
+          <chromatic>-9</chromatic>\r
+        </transpose>\r
+      </attributes>\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
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>B</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>C</step>\r
+          <alter>1</alter>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+    </measure>\r
+    <!--=======================================================-->\r
+    <measure number="2">\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>F</step>\r
+          <alter>1</alter>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>G</step>\r
+          <alter>1</alter>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+  <part id="P3">\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>C</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>F</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\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
+      </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
+      </note>\r
+      <note>\r
+        <pitch>\r
+          <step>B</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\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
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+</score-partwise>\r
diff --git a/input/regression/musicxml/16b-TransposingInstruments-Full.xml b/input/regression/musicxml/16b-TransposingInstruments-Full.xml
new file mode 100644 (file)
index 0000000..84e1e48
--- /dev/null
@@ -0,0 +1,453 @@
+<?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">Various transposition. Each\r
+          part plays a c'', just displayed in different display pitches.\r
+          The second-to-last staff uses a transposition where the displayed c'\r
+          is an actual f''' concert pitch. The final staff is an untransposed\r
+          instrument.</miscellaneous-field>\r
+    </miscellaneous>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name>Clarinet in Eb</part-name>\r
+      <part-abbreviation>Eb Cl.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P2">\r
+      <part-name>Clarinet in Bb</part-name>\r
+      <part-abbreviation>Bb Cl.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P3">\r
+      <part-name>Clarinet in A</part-name>\r
+      <part-abbreviation>A Cl.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P4">\r
+      <part-name>Horn in F</part-name>\r
+      <part-abbreviation>Hn.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P5">\r
+      <part-name>Horn in Eb</part-name>\r
+      <part-abbreviation>Hn.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P6">\r
+      <part-name>Piccolo Trumpet in A</part-name>\r
+      <part-abbreviation>Picc.Tpt.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P7">\r
+      <part-name>Trumpet in Bb</part-name>\r
+      <part-abbreviation>Bb Tpt.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P8">\r
+      <part-name>Trumpet in C</part-name>\r
+      <part-abbreviation>C Tpt.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P9">\r
+      <part-name>Trumpet in D</part-name>\r
+      <part-abbreviation>D Tpt.</part-abbreviation>\r
+    </score-part>\r
+    <score-part id="P10">\r
+      <part-name>displayed c'=fis'''</part-name>\r
+    </score-part>\r
+    <score-part id="P11">\r
+      <part-name print-object="no">MusicXML Part</part-name>\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>4</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
+        <transpose>\r
+          <diatonic>2</diatonic>\r
+          <chromatic>3</chromatic>\r
+        </transpose>\r
+      </attributes>\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
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+  <part id="P2">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>3</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
+        <transpose>\r
+          <diatonic>-1</diatonic>\r
+          <chromatic>-2</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P3">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>-2</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
+        <transpose>\r
+          <diatonic>-2</diatonic>\r
+          <chromatic>-3</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <alter>-1</alter>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P4">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>2</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
+        <transpose>\r
+          <diatonic>-4</diatonic>\r
+          <chromatic>-7</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>G</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P5">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>4</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
+        <transpose>\r
+          <diatonic>-5</diatonic>\r
+          <chromatic>-9</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P6">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>-2</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
+        <transpose>\r
+          <diatonic>5</diatonic>\r
+          <chromatic>9</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>E</step>\r
+          <alter>-1</alter>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P7">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>3</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
+        <transpose>\r
+          <diatonic>-1</diatonic>\r
+          <chromatic>-2</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>D</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P8">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>1</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>C</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P9">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>-1</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
+        <transpose>\r
+          <diatonic>1</diatonic>\r
+          <chromatic>2</chromatic>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>B</step>\r
+          <alter>-1</alter>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P10">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>7</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>F</sign>\r
+          <line>4</line>\r
+          <clef-octave-change>-1</clef-octave-change>\r
+        </clef>\r
+        <transpose>\r
+          <diatonic>3</diatonic>\r
+          <chromatic>6</chromatic>\r
+          <octave-change>3</octave-change>\r
+        </transpose>\r
+      </attributes>\r
+      <note>\r
+        <pitch>\r
+          <step>F</step>\r
+          <alter>1</alter>\r
+          <octave>1</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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
+  <part id="P11">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>1</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>C</step>\r
+          <octave>5</octave>\r
+        </pitch>\r
+        <duration>4</duration>\r
+        <voice>1</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 e0f3f52c979ab50e5a97e85842af2fbe697bc19c..c0b298f36797fd9a775c0afb588c77ea9bff4a37 100644 (file)
@@ -1355,6 +1355,13 @@ class ClefChange (Music):
 """ % (glyph, pos, c0)
         return clefsetting
 
+class Transposition (Music):
+    def __init__ (self):
+        Music.__init__ (self)
+        self.pitch = None
+    def ly_expression (self):
+        self.pitch._force_absolute_pitch = True
+        return '\\transposition %s' % self.pitch.ly_expression ()
 
 class StaffChange (Music):
     def __init__ (self, staff):
index 498661e6211b1a8e1bff7934d38e8d1c585c9627..588a469f970ea537749a3c27bbc4942a9fe65616 100644 (file)
@@ -362,6 +362,11 @@ class Attributes (Measure_element):
 
         fifths = int (key.get_maybe_exist_named_child ('fifths').get_text ())
         return (fifths, mode)
+        
+    def get_transposition (self):
+        return self.get_named_attribute ('transpose')
+        
+
 
 class Barline (Measure_element):
     pass
index a99a5ece808b521f980994517ffe598879edfafa..08f2dc97ba937b33578acd637798dca3059413fa 100644 (file)
@@ -687,13 +687,47 @@ def musicxml_key_to_lily (attributes):
     change.mode = mode
     change.tonic = start_pitch
     return change
+
+def musicxml_transpose_to_lily (attributes):
+    transpose = attributes.get_transposition ()
+    if not transpose:
+        return None
+
+    shift = musicexp.Pitch ()
+    octave_change = transpose.get_maybe_exist_named_child ('octave-change')
+    if octave_change:
+        shift.octave = string.atoi (octave_change.get_text ())
+    chromatic_shift = string.atoi (transpose.get_named_child ('chromatic').get_text ())
+    chromatic_shift_normalized = chromatic_shift % 12;
+    (shift.step, shift.alteration) = [
+        (0,0), (0,1), (1,0), (2,-1), (2,0), 
+        (3,0), (3,1), (4,0), (5,-1), (5,0), 
+        (6,-1), (6,0)][chromatic_shift_normalized];
     
+    shift.octave += (chromatic_shift - chromatic_shift_normalized) / 12
+
+    diatonic = transpose.get_maybe_exist_named_child ('diatonic')
+    if diatonic:
+        diatonic_step = string.atoi (diatonic.get_text ()) % 7
+        if diatonic_step != shift.step:
+            # We got the alter incorrect!
+            old_semitones = shift.semitones ()
+            shift.step = diatonic_step
+            new_semitones = shift.semitones ()
+            shift.alteration += old_semitones - new_semitones
+
+    transposition = musicexp.Transposition ()
+    transposition.pitch = musicexp.Pitch ().transposed (shift)
+    return transposition
+
+
 def musicxml_attributes_to_lily (attrs):
     elts = []
     attr_dispatch =  {
         'clef': musicxml_clef_to_lily,
         'time': musicxml_time_to_lily,
-        'key': musicxml_key_to_lily
+        'key': musicxml_key_to_lily,
+        'transpose': musicxml_transpose_to_lily,
     }
     for (k, func) in attr_dispatch.items ():
         children = attrs.get_named_children (k)