Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #331007: [MusicXML import] support tie element #11485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ static std::shared_ptr<mu::iex::musicxml::IMusicXmlConfiguration> configuration(

//#define DEBUG_VOICE_MAPPER true

//---------------------------------------------------------
// function declarations
//---------------------------------------------------------

static void addTie(const Notation& notation, Score* score, Note* note, const int track, Tie*& tie, MxmlLogger* logger,
const QXmlStreamReader* const xmlreader);

//---------------------------------------------------------
// support enums / structs / classes
//---------------------------------------------------------
Expand Down Expand Up @@ -4443,6 +4450,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
bool printObject = _e.attributes().value("print-object") != "no";
BeamMode bm = BeamMode::AUTO;
QString instrumentId;
QString tieType;
MusicXMLParserLyric lyric { _pass1.getMusicXmlPart(partId).lyricNumberHandler(), _e, _score, _logger };
MusicXMLParserNotations notations { _e, _score, _logger };

Expand Down Expand Up @@ -4498,6 +4506,9 @@ Note* MusicXMLParserPass2::note(const QString& partId,
}
} else if (_e.name() == "stem") {
stem(stemDir, noStem);
} else if (_e.name() == "tie") {
tieType = _e.attributes().value("type").toString();
_e.skipCurrentElement();
} else if (_e.name() == "type") {
isSmall = _e.attributes().value("size") == "cue";
type = _e.readElementText();
Expand Down Expand Up @@ -4723,6 +4734,14 @@ Note* MusicXMLParserPass2::note(const QString& partId,
// handle notations
if (cr) {
notations.addToScore(cr, note, noteStartTime.ticks(), _slurs, _glissandi, _spanners, _trills, _tie);

// if no tie added yet, convert the "tie" into "tied" and add it.
if (note && !note->tieFor() && !tieType.isEmpty()) {
Notation notation { "tied" };
const QString type { "type" };
notation.addAttribute(&type, &tieType);
addTie(notation, _score, note, cr->track(), _tie, _logger, &_e);
}
}

// handle grace after state: remember current grace list size
Expand Down
160 changes: 160 additions & 0 deletions src/importexport/musicxml/tests/data/testTieTied.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Tie and ties</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>
<miscellaneous>
<miscellaneous-field name="description">
Test interaction of tie and tied elements. MuseScore does not
distinguish between sound and notation.

Either tie or tied will create a tie on import, on export
both will be present.
</miscellaneous-field>
</miscellaneous>
</identification>
<part-list>
<score-part id="P1">
<part-name></part-name>
<score-instrument id="P1-I1">
<instrument-name></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>74</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>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<words>tie only</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="start"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="stop"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
</note>
</measure>
<measure number="2">
<direction placement="above">
<direction-type>
<words>tied only</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="stop"/>
</notations>
</note>
</measure>
<measure number="3">
<direction placement="above">
<direction-type>
<words>both tie and tied</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="start"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="stop"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="stop"/>
</notations>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
159 changes: 159 additions & 0 deletions src/importexport/musicxml/tests/data/testTieTied_ref.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Tie and ties</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></part-name>
<score-instrument id="P1-I1">
<instrument-name></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>74</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>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<words>tie only</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="start"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="stop"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="stop"/>
</notations>
</note>
</measure>
<measure number="2">
<direction placement="above">
<direction-type>
<words>tied only</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="start"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="stop"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="stop"/>
</notations>
</note>
</measure>
<measure number="3">
<direction placement="above">
<direction-type>
<words>both tie and tied</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="start"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="start"/>
</notations>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<tie type="stop"/>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
<notations>
<tied type="stop"/>
</notations>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
1 change: 1 addition & 0 deletions src/importexport/musicxml/tests/tst_mxml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private slots:
// void tempoOverlap() { mxmlIoTestRef("testTempoOverlap"); } fails
void tempoPrecision() { mxmlMscxExportTestRef("testTempoPrecision"); }
//void textLines() { mxmlMscxExportTestRef("testTextLines"); } FIXME
void tieTied() { mxmlIoTestRef("testTieTied"); }
void timesig1() { mxmlIoTest("testTimesig1"); }
void timesig3() { mxmlIoTest("testTimesig3"); }
void trackHandling() { mxmlIoTest("testTrackHandling"); }
Expand Down