Skip to content

Commit

Permalink
Add import/export of invisible clefs to MusicXML
Browse files Browse the repository at this point in the history
Backport of musescore#19605
  • Loading branch information
rettinghaus authored and Jojo-Schmitz committed Nov 14, 2023
1 parent 37a778a commit 3e27fde
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6209,7 +6209,10 @@ void ExportMusicXml::findAndExportClef(const Measure* const m, const int staves,
// exception: at tick=0, export clef anyway
if ((tick.isZero() || !cle->generated()) && ((seg->measure() != m) || ((seg->segmentType() == SegmentType::HeaderClef) && !cle->otherClef()))) {
clefDebug("exportxml: clef exported");
clef(sstaff, cle->clefType(), color2xml(cle));
QString clefAttr = color2xml(cle);
if (!cle->visible())
clefAttr += " print-object=\"no\"";
clef(sstaff, cle->clefType(), clefAttr);
}
else {
clefDebug("exportxml: clef not exported");
Expand Down Expand Up @@ -6433,14 +6436,15 @@ void ExportMusicXml::writeElement(Element* el, const Measure* m, int sstaff, boo
// these will be output at the start of the next measure
const auto cle = toClef(el);
const auto ti = cle->segment()->tick();
const QString visible = (!cle->visible()) ? " print-object=\"no\"" : "";
clefDebug("exportxml: clef in measure ti=%d ct=%d gen=%d", ti, int(cle->clefType()), el->generated());
if (el->generated()) {
clefDebug("exportxml: generated clef not exported");
}
else if (!el->generated() && tickIsInMiddleOfMeasure(ti, m))
clef(sstaff, cle->clefType(), color2xml(cle));
clef(sstaff, cle->clefType(), color2xml(cle) + visible);
else if (!el->generated() && (ti == m->tick()) && (cle->segment()->segmentType() != SegmentType::HeaderClef))
clef(sstaff, cle->clefType(), color2xml(cle) + QString(" after-barline=\"yes\""));
clef(sstaff, cle->clefType(), color2xml(cle) + visible + QString(" after-barline=\"yes\""));
else
clefDebug("exportxml: clef not exported");
}
Expand Down
6 changes: 4 additions & 2 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4826,8 +4826,9 @@ void MusicXMLParserPass2::clef(const QString& partId, Measure* measure, const Fr
int i = 0;
int line = -1;

QString strClefno = _e.attributes().value("number").toString();
const QString strClefno = _e.attributes().value("number").toString();
const bool afterBarline = _e.attributes().value("after-barline") == "yes";
const bool printObject = _e.attributes().value("print-object") != "no";

while (_e.readNextStartElement()) {
if (_e.name() == "sign")
Expand Down Expand Up @@ -4904,7 +4905,7 @@ void MusicXMLParserPass2::clef(const QString& partId, Measure* measure, const Fr
}
else if (c == "TAB") {
clef = ClefType::TAB;
st= StaffTypes::TAB_DEFAULT;
st = StaffTypes::TAB_DEFAULT;
}
else
qDebug("clef: unknown clef <sign=%s line=%d oct ch=%d>", qPrintable(c), line, i); // TODO
Expand Down Expand Up @@ -4932,6 +4933,7 @@ void MusicXMLParserPass2::clef(const QString& partId, Measure* measure, const Fr

Clef* clefs = new Clef(_score);
clefs->setClefType(clef);
clefs->setVisible(printObject);
int track = _pass1.trackForPart(partId) + clefno * VOICES;
clefs->setTrack(track);
Segment* s;
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testInvisibleElements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<clef print-object="no">
<sign>G</sign>
<line>2</line>
</clef>
Expand Down

0 comments on commit 3e27fde

Please sign in to comment.