Skip to content

Commit 5b110f4

Browse files
committed
<print-object> tags indicate hide empty staves
1 parent f3f509f commit 5b110f4

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ void MusicXMLParserPass2::attributes(const QString& partId, Measure* measure, co
23682368
} else if (_e.name() == "measure-style") {
23692369
measureStyle(measure);
23702370
} else if (_e.name() == "staff-details") {
2371-
staffDetails(partId);
2371+
staffDetails(partId, measure);
23722372
} else if (_e.name() == "time") {
23732373
time(partId, measure, tick);
23742374
} else if (_e.name() == "transpose") {
@@ -2401,7 +2401,7 @@ static void setStaffLines(Score* score, staff_idx_t staffIdx, int stafflines)
24012401
Parse the /score-partwise/part/measure/attributes/staff-details node.
24022402
*/
24032403

2404-
void MusicXMLParserPass2::staffDetails(const QString& partId)
2404+
void MusicXMLParserPass2::staffDetails(const QString& partId, Measure* measure)
24052405
{
24062406
//logDebugTrace("MusicXMLParserPass2::staffDetails");
24072407

@@ -2426,8 +2426,23 @@ void MusicXMLParserPass2::staffDetails(const QString& partId)
24262426

24272427
StringData* t = new StringData;
24282428
QString visible = _e.attributes().value("print-object").toString();
2429+
QString spacing = _e.attributes().value("print-spacing").toString();
24292430
if (visible == "no") {
2430-
_score->staff(staffIdx)->setVisible(false);
2431+
// EITHER:
2432+
// 1) this indicates an empty staff that is hidden
2433+
// 2) this indicates a cutaway measure. if it is a cutaway measure then print-spacing will be yes
2434+
if (spacing == "yes") {
2435+
measure->setStaffVisible(staffIdx, false);
2436+
} else if (measure && !measure->hasVoices(staffIdx) && measure->isOnlyRests(staffIdx * VOICES)) {
2437+
// measures with print-object="no" are generally exported by exporters such as dolet when empty staves are hidden.
2438+
// for this reason, if we see an empty measure with print-object="no", we can assume that this indicates we should set
2439+
// the hide empty staves style.
2440+
_score->setStyleValue(Sid::hideEmptyStaves, true);
2441+
_score->setStyleValue(Sid::dontHideStavesInFirstSystem, false);
2442+
} else {
2443+
// this doesn't apply to a measure, so we'll assume the entire staff has to be hidden.
2444+
_score->staff(staffIdx)->setVisible(false);
2445+
}
24312446
} else if (!visible.isEmpty() && visible != "yes") {
24322447
_logger->logError(QString("print-object should be \"yes\" or \"no\""));
24332448
}

src/importexport/musicxml/internal/musicxml/importmxmlpass2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class MusicXMLParserPass2
305305
void stem(DirectionV& sd, bool& nost);
306306
void doEnding(const QString& partId, Measure* measure, const QString& number, const QString& type, const QString& text,
307307
const bool print);
308-
void staffDetails(const QString& partId);
308+
void staffDetails(const QString& partId, Measure* measure = nullptr);
309309
void staffTuning(StringData* t);
310310
void skipLogCurrElem();
311311

0 commit comments

Comments
 (0)