Skip to content

Commit 864201d

Browse files
authored
Merge pull request #26190 from rettinghaus/xml/invisibleStaff
fix #17398: mark hidden staves in MusicXML export
2 parents e3940af + 4d64a97 commit 864201d

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/importexport/musicxml/internal/musicxml/export/exportmusicxml.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ class ExportMusicXml : public muse::Injectable
468468
int m_tenths = 0;
469469
bool m_tboxesAboveWritten = false;
470470
bool m_tboxesBelowWritten = false;
471+
std::vector<size_t> m_hiddenStaves;
471472
TrillHash m_trillStart;
472473
TrillHash m_trillStop;
473474
MusicXmlInstrumentMap m_instrMap;
@@ -7444,13 +7445,19 @@ void ExportMusicXml::print(const Measure* const m, const int partNr, const int f
74447445
if (prevStaffNr == muse::nidx) {
74457446
continue;
74467447
}
7448+
if (!system->staff(staffNr)->show()) {
7449+
m_hiddenStaves.push_back(staffIdx);
7450+
continue;
7451+
}
74477452
const RectF& prevBbox = system->staff(prevStaffNr)->bbox();
74487453
const double staffDist = system->staff(staffNr)->bbox().y() - prevBbox.y() - prevBbox.height();
74497454

74507455
if (staffDist > 0) {
74517456
m_xml.startElement("staff-layout", { { "number", staffIdx + 1 } });
74527457
m_xml.tag("staff-distance", String::number(getTenthsFromDots(staffDist), 2));
74537458
m_xml.endElement();
7459+
} else {
7460+
m_hiddenStaves.push_back(staffIdx);
74547461
}
74557462
}
74567463

@@ -7909,29 +7916,41 @@ static void clampMusicXmlOctave(int& octave)
79097916
Write the staff details for \a part to \a xml.
79107917
*/
79117918

7912-
static void writeStaffDetails(XmlWriter& xml, const Part* part)
7919+
static void writeStaffDetails(XmlWriter& xml, const Part* part, const std::vector<size_t> hiddenStaves)
79137920
{
79147921
const Instrument* instrument = part->instrument();
7915-
size_t staves = part->nstaves();
7922+
const size_t staves = part->nstaves();
79167923

79177924
// staff details
7918-
// TODO: decide how to handle linked regular / TAB staff
7919-
// currently exported as a two staff part ...
79207925
for (size_t i = 0; i < staves; i++) {
79217926
Staff* st = part->staff(i);
79227927
const double mag = st->staffMag(Fraction(0, 1));
7928+
bool hidden = false;
7929+
if (!st->show()) {
7930+
hidden = true;
7931+
} else {
7932+
for (size_t staffIdx : hiddenStaves) {
7933+
if (i == staffIdx) {
7934+
hidden = true;
7935+
}
7936+
}
7937+
}
79237938
const Color lineColor = st->color(Fraction(0, 1));
79247939
const bool invis = st->isLinesInvisible(Fraction(0, 1));
79257940
const bool needsLineDetails = invis || lineColor != engravingConfiguration()->defaultColor();
79267941
if (st->lines(Fraction(0, 1)) != 5 || st->isTabStaff(Fraction(0, 1)) || !muse::RealIsEqual(mag, 1.0)
7927-
|| !st->show() || needsLineDetails) {
7942+
|| hidden || needsLineDetails) {
79287943
XmlWriter::Attributes attributes;
79297944
if (staves > 1) {
7930-
attributes.push_back({ "number", i + 1 });
7945+
attributes.emplace_back(std::make_pair("number", i + 1));
79317946
}
7932-
if (!st->show()) {
7933-
attributes.push_back({ "print-object", "no" });
7947+
if (hidden) {
7948+
attributes.emplace_back(std::make_pair("print-object", "no"));
7949+
if (st->cutaway()) {
7950+
attributes.emplace_back(std::make_pair("print-spacing", "yes"));
7951+
}
79347952
}
7953+
79357954
xml.startElement("staff-details", attributes);
79367955

79377956
if (i > 0 && st->links() && st->links()->contains(part->staff(i - 1))) {
@@ -8494,9 +8513,24 @@ void ExportMusicXml::writeMeasure(const Measure* const m,
84948513

84958514
// output attributes with the first actual measure (pickup or regular) only
84968515
if (isFirstActualMeasure) {
8497-
writeStaffDetails(m_xml, part);
8516+
writeStaffDetails(m_xml, part, m_hiddenStaves);
84988517
writeInstrumentDetails(part->instrument(), m_score->style().styleB(Sid::concertPitch));
8518+
} else {
8519+
for (size_t staffIdx : m_hiddenStaves) {
8520+
m_attr.doAttr(m_xml, true);
8521+
XmlWriter::Attributes attributes;
8522+
if (staves > 1) {
8523+
attributes.emplace_back(std::make_pair("number", staffIdx + 1));
8524+
}
8525+
attributes.emplace_back(std::make_pair("print-object", "no"));
8526+
if (part->staff(staffIdx)->cutaway()) {
8527+
attributes.emplace_back(std::make_pair("print-spacing", "yes"));
8528+
}
8529+
m_xml.tag("staff-details", attributes);
8530+
m_attr.doAttr(m_xml, false);
8531+
}
84998532
}
8533+
m_hiddenStaves.clear();
85008534

85018535
// output attribute at start of measure: measure-style
85028536
measureStyle(m_xml, m_attr, m, partIndex);

0 commit comments

Comments
 (0)