Skip to content

Commit

Permalink
ENG-65: Volta print-object not respected
Browse files Browse the repository at this point in the history
Dolet tends to export voltas on every part, then hide all but one.
Previously, these would all be imported and not hidden. This commit
hides voltas when print-object="no".

Additionally, it adds handling for only exporting voltas in the staff
they are in, as previously one volta was exported for each part, despite
the volta only existing on one part.

Duplicate of musescore#8622, part 1
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Aug 13, 2021
1 parent 14f1a7f commit 6a6be18
Show file tree
Hide file tree
Showing 8 changed files with 6,888 additions and 19 deletions.
17 changes: 10 additions & 7 deletions importexport/musicxml/exportxml.cpp
Expand Up @@ -342,7 +342,7 @@ class ExportMusicXml {
void clef(int staff, const ClefType ct, const QString& extraAttributes = "");
void timesig(TimeSig* tsig);
void keysig(const KeySig* ks, ClefType ct, int staff = 0, bool visible = true);
void barlineLeft(const Measure* const m);
void barlineLeft(const Measure* const m, const int track);
void barlineMiddle(const BarLine* bl);
void barlineRight(const Measure* const m, const int strack, const int etrack);
void lyrics(const std::vector<Lyrics*>* ll, const int trk);
Expand Down Expand Up @@ -1546,14 +1546,15 @@ static QString tick2xml(const Fraction& ticks, int* dots)
// findVolta -- find volta starting in measure m
//---------------------------------------------------------

static Volta* findVolta(const Measure* const m, bool left)
static Volta* findVolta(const Measure* const m, bool left, const int track)
{
Fraction stick = m->tick();
Fraction etick = m->tick() + m->ticks();
auto spanners = m->score()->spannerMap().findOverlapping(stick.ticks(), etick.ticks());
for (auto i : spanners) {
Spanner* el = i.value;
if (el->type() != ElementType::VOLTA)
if (el->type() != ElementType::VOLTA
|| track2staff(el->track()) != track2staff(track))
continue;
if (left && el->tick() == stick)
return (Volta*) el;
Expand Down Expand Up @@ -1595,17 +1596,19 @@ static void ending(XmlWriter& xml, Volta* v, bool left)
}
QString voltaXml = QString("ending number=\"%1\" type=\"%2\"").arg(number, type);
voltaXml += positioningAttributes(v, left);
if (!v->visible())
voltaXml += " print-object=\"no\"";
xml.tagE(voltaXml);
}

//---------------------------------------------------------
// barlineLeft -- search for and handle barline left
//---------------------------------------------------------

void ExportMusicXml::barlineLeft(const Measure* const m)
void ExportMusicXml::barlineLeft(const Measure* const m, const int track)
{
bool rs = m->repeatStart();
Volta* volta = findVolta(m, true);
Volta* volta = findVolta(m, true, track);
if (!rs && !volta) return;
_attr.doAttr(_xml, false);
_xml.stag(QString("barline location=\"left\""));
Expand Down Expand Up @@ -1800,7 +1803,7 @@ void ExportMusicXml::barlineRight(const Measure* const m, const int strack, cons
bool visible = m->endBarLineVisible();

bool needBarStyle = (bst != BarLineType::NORMAL && bst != BarLineType::START_REPEAT) || !visible;
Volta* volta = findVolta(m, false);
Volta* volta = findVolta(m, false, strack);
// detect short and tick barlines
QString special = "";
if (bst == BarLineType::NORMAL) {
Expand Down Expand Up @@ -6587,7 +6590,7 @@ void ExportMusicXml::writeMeasure(const Measure* const m,
findTrills(m, strack, etrack, _trillStart, _trillStop);

// barline left must be the first element in a measure
barlineLeft(m);
barlineLeft(m, strack);

// output attributes with the first actual measure (pickup or regular)
if (isFirstActualMeasure) {
Expand Down
11 changes: 8 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -3851,13 +3851,15 @@ void MusicXMLParserPass2::barline(const QString& partId, Measure* measure, const
QString endingText;
QString repeat;
QString count;
bool printEnding = true;

while (_e.readNextStartElement()) {
if (_e.name() == "bar-style")
barStyle = _e.readElementText();
else if (_e.name() == "ending") {
endingNumber = _e.attributes().value("number").toString();
endingType = _e.attributes().value("type").toString();
printEnding = _e.attributes().value("print-object").toString() != "no";
endingText = _e.readElementText();
}
else if (_e.name() == "repeat") {
Expand Down Expand Up @@ -3909,15 +3911,15 @@ void MusicXMLParserPass2::barline(const QString& partId, Measure* measure, const
}
}

doEnding(partId, measure, endingNumber, endingType, endingText);
doEnding(partId, measure, endingNumber, endingType, endingText, printEnding);
}

//---------------------------------------------------------
// doEnding
//---------------------------------------------------------

void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure,
const QString& number, const QString& type, const QString& text)
void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, const QString& number,
const QString& type, const QString& text, const bool print)
{
if (!(number.isEmpty() && type.isEmpty())) {
if (number.isEmpty())
Expand Down Expand Up @@ -3950,11 +3952,13 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure,
volta->setTick(measure->tick());
_score->addElement(volta);
_lastVolta = volta;
volta->setVisible(print);
}
else if (type == "stop") {
if (_lastVolta) {
_lastVolta->setVoltaType(Volta::Type::CLOSED);
_lastVolta->setTick2(measure->tick() + measure->ticks());
// Assume print-object was handled at the start
_lastVolta = 0;
}
else
Expand All @@ -3964,6 +3968,7 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure,
if (_lastVolta) {
_lastVolta->setVoltaType(Volta::Type::OPEN);
_lastVolta->setTick2(measure->tick() + measure->ticks());
// Assume print-object was handled at the start
_lastVolta = 0;
}
else
Expand Down
2 changes: 1 addition & 1 deletion importexport/musicxml/importmxmlpass2.h
Expand Up @@ -294,7 +294,7 @@ class MusicXMLParserPass2 {
void backup(Fraction& dura);
void timeModification(Fraction& timeMod, TDuration& normalType);
void stem(Direction& sd, bool& nost);
void doEnding(const QString& partId, Measure* measure, const QString& number, const QString& type, const QString& text);
void doEnding(const QString& partId, Measure* measure, const QString& number, const QString& type, const QString& text, const bool print);
void staffDetails(const QString& partId);
void staffTuning(StringData* t);
void skipLogCurrElem();
Expand Down
8 changes: 0 additions & 8 deletions mtest/musicxml/io/testTextLines_ref.xml
Expand Up @@ -315,9 +315,6 @@
</note>
</measure>
<measure number="7">
<barline location="left">
<ending number="1" type="start"/>
</barline>
<note>
<pitch>
<step>F</step>
Expand All @@ -330,14 +327,10 @@
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
<ending number="1" type="stop"/>
<repeat direction="backward"/>
</barline>
</measure>
<measure number="8">
<barline location="left">
<ending number="2" type="start"/>
</barline>
<note>
<pitch>
<step>G</step>
Expand All @@ -349,7 +342,6 @@
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
<ending number="2" type="discontinue"/>
</barline>
</measure>
</part>
Expand Down

0 comments on commit 6a6be18

Please sign in to comment.