Skip to content

Commit ee20fdc

Browse files
authored
Merge pull request #25960 from rettinghaus/xml/staffDist
Fix #22098: staff distance with hidden staves
2 parents 02a0a52 + 7e67995 commit ee20fdc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class ExportMusicXml : public muse::Injectable
424424
void keysigTimesig(const Measure* m, const Part* p);
425425
void chordAttributes(Chord* chord, Notations& notations, Technical& technical, TrillHash& trillStart, TrillHash& trillStop);
426426
void wavyLineStartStop(const ChordRest* cr, Notations& notations, Ornaments& ornaments, TrillHash& trillStart, TrillHash& trillStop);
427-
void print(const Measure* const m, const int partNr, const int firstStaffOfPart, const int nrStavesInPart,
427+
void print(const Measure* const m, const int partNr, const int firstStaffOfPart, const size_t nrStavesInPart,
428428
const MeasurePrintContext& mpc);
429429
void measureLayout(const double distance);
430430
void findAndExportClef(const Measure* const m, const int staves, const track_idx_t strack, const track_idx_t etrack);
@@ -7250,7 +7250,7 @@ static bool hasPageBreak(const System* const system)
72507250
*/
72517251

72527252
void ExportMusicXml::print(const Measure* const m, const int partNr, const int firstStaffOfPart,
7253-
const int nrStavesInPart, const MeasurePrintContext& mpc)
7253+
const size_t nrStavesInPart, const MeasurePrintContext& mpc)
72547254
{
72557255
const MeasureBase* const prevSysMB = lastMeasureBase(mpc.prevSystem);
72567256

@@ -7332,15 +7332,21 @@ void ExportMusicXml::print(const Measure* const m, const int partNr, const int f
73327332
}
73337333

73347334
// Staff layout elements.
7335-
for (int staffIdx = (firstStaffOfPart == 0) ? 1 : 0; staffIdx < nrStavesInPart; staffIdx++) {
7335+
for (staff_idx_t staffIdx = (firstStaffOfPart == 0) ? 1 : 0; staffIdx < nrStavesInPart; staffIdx++) {
73367336
// calculate distance between this and previous staff using the bounding boxes
7337-
const int staffNr = firstStaffOfPart + staffIdx;
7338-
const RectF& prevBbox = system->staff(staffNr - 1)->bbox();
7337+
const staff_idx_t staffNr = firstStaffOfPart + staffIdx;
7338+
const staff_idx_t prevStaffNr = system->prevVisibleStaff(staffNr);
7339+
if (prevStaffNr == muse::nidx) {
7340+
continue;
7341+
}
7342+
const RectF& prevBbox = system->staff(prevStaffNr)->bbox();
73397343
const double staffDist = system->staff(staffNr)->bbox().y() - prevBbox.y() - prevBbox.height();
73407344

7341-
m_xml.startElement("staff-layout", { { "number", staffIdx + 1 } });
7342-
m_xml.tag("staff-distance", String::number(getTenthsFromDots(staffDist), 2));
7343-
m_xml.endElement();
7345+
if (staffDist > 0) {
7346+
m_xml.startElement("staff-layout", { { "number", staffIdx + 1 } });
7347+
m_xml.tag("staff-distance", String::number(getTenthsFromDots(staffDist), 2));
7348+
m_xml.endElement();
7349+
}
73447350
}
73457351

73467352
// Measure layout elements.
@@ -8321,7 +8327,7 @@ void ExportMusicXml::writeMeasure(const Measure* const m,
83218327

83228328
m_xml.startElementRaw(measureTag);
83238329

8324-
print(m, partIndex, staffCount, static_cast<int>(staves), mpc);
8330+
print(m, partIndex, staffCount, staves, mpc);
83258331

83268332
m_attr.start();
83278333

0 commit comments

Comments
 (0)