Skip to content

Commit

Permalink
ENG-65: Remove hidden redundant voltas
Browse files Browse the repository at this point in the history
Since Dolet exports unnecessary hidden voltas, we can discard these
rather than import them as hidden elements (that is, as long as they
are both hidden AND redundant).

Duplicate of musescore#8622, part 2
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Aug 19, 2021
1 parent 0cb8694 commit b334bf6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 70 deletions.
32 changes: 29 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -3914,6 +3914,21 @@ void MusicXMLParserPass2::barline(const QString& partId, Measure* measure, const
doEnding(partId, measure, endingNumber, endingType, endingText, printEnding);
}

//---------------------------------------------------------
// findRedundantVolta
//---------------------------------------------------------

static Volta* findRedundantVolta(const int track, const Measure* measure)
{
auto spanners = measure->score()->spannerMap().findOverlapping(measure->tick().ticks(), measure->endTick().ticks());
for (auto spanner : spanners) {
if (spanner.value->isVolta()
&& track2staff(spanner.value->track()) != track2staff(track))
return toVolta(spanner.value);
}
return 0;
}

//---------------------------------------------------------
// doEnding
//---------------------------------------------------------
Expand Down Expand Up @@ -3942,7 +3957,11 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, cons
if (unsupported)
_logger->logError(QString("unsupported ending number '%1'").arg(number), &_e);
else {
if (type == "start") {
// Ignore if it is hidden and redundant
Volta* redundantVolta = findRedundantVolta(_pass1.trackForPart(partId), measure);
if (!print && redundantVolta)
_logger->logDebugInfo("Ignoring redundant hidden Volta", &_e);
else if (type == "start") {
Volta* volta = new Volta(_score);
volta->setTrack(_pass1.trackForPart(partId));
volta->setText(text.isEmpty() ? number : text);
Expand All @@ -3961,7 +3980,7 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, cons
// Assume print-object was handled at the start
_lastVolta = 0;
}
else
else if (!redundantVolta)
_logger->logError("ending stop without start", &_e);
}
else if (type == "discontinue") {
Expand All @@ -3971,11 +3990,18 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, cons
// Assume print-object was handled at the start
_lastVolta = 0;
}
else
else if (!redundantVolta)
_logger->logError("ending discontinue without start", &_e);
}
else
_logger->logError(QString("unsupported ending type '%1'").arg(type), &_e);

// Delete any hidden redundant voltas before
while (redundantVolta && !redundantVolta->visible()) {
_score->removeElement(redundantVolta);
delete redundantVolta;
redundantVolta = findRedundantVolta(_pass1.trackForPart(partId), measure);
}
}
}
}
Expand Down
57 changes: 0 additions & 57 deletions mtest/musicxml/io/testVoltaHiding_ref.mscx
Expand Up @@ -1015,31 +1015,6 @@
</Measure>
<Measure>
<voice>
<Spanner type="Volta">
<Volta>
<endHookType>1</endHookType>
<beginText>1</beginText>
<visible>0</visible>
<Segment>
<subtype>1</subtype>
<offset x="0" y="-3"/>
<off2 x="0" y="0"/>
<visible>0</visible>
</Segment>
<Segment>
<subtype>3</subtype>
<offset x="0" y="-3"/>
<off2 x="0" y="0"/>
<visible>0</visible>
</Segment>
<endings>1</endings>
</Volta>
<next>
<location>
<measures>7</measures>
</location>
</next>
</Spanner>
<Chord>
<durationType>quarter</durationType>
<StemDirection>down</StemDirection>
Expand Down Expand Up @@ -1139,31 +1114,6 @@
</Measure>
<Measure>
<voice>
<Spanner type="Volta">
<prev>
<location>
<measures>-7</measures>
</location>
</prev>
</Spanner>
<Spanner type="Volta">
<Volta>
<beginText>2</beginText>
<visible>0</visible>
<Segment>
<subtype>0</subtype>
<offset x="0" y="-3"/>
<off2 x="0" y="0"/>
<visible>0</visible>
</Segment>
<endings>2</endings>
</Volta>
<next>
<location>
<measures>1</measures>
</location>
</next>
</Spanner>
<Chord>
<durationType>quarter</durationType>
<StemDirection>down</StemDirection>
Expand Down Expand Up @@ -1195,13 +1145,6 @@
</Measure>
<Measure>
<voice>
<Spanner type="Volta">
<prev>
<location>
<measures>-1</measures>
</location>
</prev>
</Spanner>
<Rest>
<durationType>measure</durationType>
<duration>1/1</duration>
Expand Down
10 changes: 0 additions & 10 deletions mtest/musicxml/io/testVoltaHiding_ref.xml
Expand Up @@ -1578,9 +1578,6 @@
</note>
</measure>
<measure number="14">
<barline location="left">
<ending number="1" type="start" print-object="no"/>
</barline>
<note>
<pitch>
<step>C</step>
Expand Down Expand Up @@ -1862,14 +1859,10 @@
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
<ending number="1" type="stop" print-object="no"/>
<repeat direction="backward"/>
</barline>
</measure>
<measure number="21">
<barline location="left">
<ending number="2" type="start" print-object="no"/>
</barline>
<note>
<pitch>
<step>B</step>
Expand Down Expand Up @@ -1957,9 +1950,6 @@
<stem>down</stem>
<staff>2</staff>
</note>
<barline location="right">
<ending number="2" type="discontinue" print-object="no"/>
</barline>
</measure>
<measure number="22">
<note>
Expand Down

0 comments on commit b334bf6

Please sign in to comment.