Skip to content

Commit

Permalink
Fix #329470: Wrong/missing transpositioning on MusicXML import
Browse files Browse the repository at this point in the history
If the optional element "diatonic" is missing, calculate it from "chromatic".

Backport of musescore#10586
  • Loading branch information
Jojo-Schmitz committed Feb 24, 2022
1 parent 0e2b7e3 commit 7bcfd92
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 1 deletion.
6 changes: 5 additions & 1 deletion importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "libmscore/style.h"
#include "libmscore/spanner.h"
#include "libmscore/bracketItem.h"
#include "libmscore/utils.h"

#include "importmxmllogger.h"
#include "importmxmlnoteduration.h"
Expand Down Expand Up @@ -2671,8 +2672,11 @@ void MusicXMLParserPass1::transpose(const QString& partId, const Fraction& tick)
skipLogCurrElem();
}

if (_parts[partId]._intervals.count(tick) == 0)
if (_parts[partId]._intervals.count(tick) == 0) {
if (!interval.diatonic)
interval.diatonic = chromatic2diatonic(interval.chromatic);
_parts[partId]._intervals[tick] = interval;
}
else
qDebug("duplicate transpose at tick %s", qPrintable(tick.print()));
}
Expand Down
128 changes: 128 additions & 0 deletions mtest/musicxml/io/testChangeTranspose-no-diatonic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Change transpose (no diatonic)</work-title>
</work>
<identification>
<creator type="composer">Leon Vinken</creator>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name>A Clarinet</part-name>
<part-abbreviation>A Cl.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>A Clarinet</instrument-name>
</score-instrument>
<score-instrument id="P1-I2">
<instrument-name>B♭ Clarinet</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>72</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
<midi-device id="P1-I2" port="1"></midi-device>
<midi-instrument id="P1-I2">
<midi-channel>2</midi-channel>
<midi-program>72</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>-3</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<instruments>2</instruments>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
<transpose>
<chromatic>-3</chromatic>
</transpose>
</attributes>
<attributes>
<measure-style>
<multiple-rest>2</multiple-rest>
</measure-style>
</attributes>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="2">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="3">
<note>
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<instrument id="P1-I1"/>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="4">
<attributes>
<key>
<fifths>2</fifths>
</key>
</attributes>
<attributes>
<transpose>
<chromatic>-2</chromatic>
</transpose>
</attributes>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">To B♭ Clarinet</words>
</direction-type>
</direction>
<note>
<pitch>
<step>C</step>
<alter>1</alter>
<octave>5</octave>
</pitch>
<duration>4</duration>
<instrument id="P1-I2"/>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
130 changes: 130 additions & 0 deletions mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Change transpose (no diatonic)</work-title>
</work>
<identification>
<creator type="composer">Leon Vinken</creator>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name>A Clarinet</part-name>
<part-abbreviation>A Cl.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>A Clarinet</instrument-name>
</score-instrument>
<score-instrument id="P1-I2">
<instrument-name>B♭ Clarinet</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>72</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
<midi-device id="P1-I2" port="1"></midi-device>
<midi-instrument id="P1-I2">
<midi-channel>2</midi-channel>
<midi-program>72</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>-3</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<instruments>2</instruments>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
<transpose>
<diatonic>-2</diatonic>
<chromatic>-3</chromatic>
</transpose>
</attributes>
<attributes>
<measure-style>
<multiple-rest>2</multiple-rest>
</measure-style>
</attributes>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="2">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="3">
<note>
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<instrument id="P1-I1"/>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="4">
<attributes>
<key>
<fifths>2</fifths>
</key>
</attributes>
<attributes>
<transpose>
<diatonic>-1</diatonic>
<chromatic>-2</chromatic>
</transpose>
</attributes>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">To B♭ Clarinet</words>
</direction-type>
</direction>
<note>
<pitch>
<step>C</step>
<alter>1</alter>
<octave>5</octave>
</pitch>
<duration>4</duration>
<instrument id="P1-I2"/>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
1 change: 1 addition & 0 deletions mtest/musicxml/io/tst_mxml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private slots:
void breaksPage() { mxmlMscxExportTestRefBreaks("testBreaksPage"); }
void breaksSystem() { mxmlMscxExportTestRefBreaks("testBreaksSystem"); }
void changeTranspose() { mxmlIoTest("testChangeTranspose"); }
void changeTransposeNoDiatonic() { mxmlIoTestRef("testChangeTranspose-no-diatonic"); }
void chordDiagrams1() { mxmlIoTest("testChordDiagrams1"); }
void chordNoVoice() { mxmlIoTestRef("testChordNoVoice"); }
void clefs1() { mxmlIoTest("testClefs1"); }
Expand Down

0 comments on commit 7bcfd92

Please sign in to comment.