diff --git a/libmscore/rest.cpp b/libmscore/rest.cpp index 0ec471d5b2e84..f37f7f5c01843 100644 --- a/libmscore/rest.cpp +++ b/libmscore/rest.cpp @@ -436,7 +436,7 @@ int Rest::computeLineOffset(int lines) } } } -#if 0 + if (offsetVoices && staff()->mergeMatchingRests()) { // automatically merge matching rests in voices 1 & 2 if nothing in any other voice // this is not always the right thing to do do, but is useful in choral music @@ -454,7 +454,7 @@ int Rest::computeLineOffset(int lines) // try to find match in other voice (1 or 2) if (e && e->type() == ElementType::REST) { Rest* r = toRest(e); - if (r->globalDuration() == globalDuration()) { + if (r->globalTicks() == globalTicks()) { matchFound = true; continue; } @@ -473,7 +473,6 @@ int Rest::computeLineOffset(int lines) offsetVoices = false; } } -#endif int lineOffset = 0; int assumedCenter = 4; diff --git a/libmscore/staff.cpp b/libmscore/staff.cpp index 8ab267a2e5e9a..efe6b3b784498 100644 --- a/libmscore/staff.cpp +++ b/libmscore/staff.cpp @@ -698,6 +698,9 @@ void Staff::write(XmlWriter& xml) const if (_hideSystemBarLine) { xml.tag("hideSystemBarLine", _hideSystemBarLine); } + if (_mergeMatchingRests) { + xml.tag("mergeMatchingRests", _mergeMatchingRests); + } for (const BracketItem* i : _brackets) { BracketType a = i->bracketType(); @@ -766,6 +769,8 @@ bool Staff::readProperties(XmlReader& e) setShowIfEmpty(e.readInt()); } else if (tag == "hideSystemBarLine") { _hideSystemBarLine = e.readInt(); + } else if (tag == "mergeMatchingRests") { + _mergeMatchingRests = e.readInt(); } else if (tag == "keylist") { _keys.read(e, score()); } else if (tag == "bracket") { @@ -1169,6 +1174,7 @@ void Staff::init(const Staff* s) _cutaway = s->_cutaway; _showIfEmpty = s->_showIfEmpty; _hideSystemBarLine = s->_hideSystemBarLine; + _mergeMatchingRests = s->_mergeMatchingRests; _color = s->_color; _userDist = s->_userDist; } diff --git a/libmscore/staff.h b/libmscore/staff.h index 4801af23b8f27..b981d1b7bf0dc 100644 --- a/libmscore/staff.h +++ b/libmscore/staff.h @@ -180,6 +180,8 @@ class Staff final : public Element void setHideSystemBarLine(bool val) { _hideSystemBarLine = val; } HideMode hideWhenEmpty() const { return _hideWhenEmpty; } void setHideWhenEmpty(HideMode v) { _hideWhenEmpty = v; } + bool mergeMatchingRests() const { return _mergeMatchingRests; } + void setMergeMatchingRests(bool val) { _mergeMatchingRests = val; } int barLineSpan() const { return _barLineSpan; } int barLineFrom() const { return _barLineFrom; } diff --git a/libmscore/undo.cpp b/libmscore/undo.cpp index 95bbc0b9f13ae..a70ac81061c67 100644 --- a/libmscore/undo.cpp +++ b/libmscore/undo.cpp @@ -1559,7 +1559,8 @@ void SetUserBankController::flip(EditData*) //--------------------------------------------------------- ChangeStaff::ChangeStaff(Staff* _staff, bool _invisible, ClefTypeList _clefType, - qreal _userDist, Staff::HideMode _hideMode, bool _showIfEmpty, bool _cutaway, bool hide) + qreal _userDist, Staff::HideMode _hideMode, bool _showIfEmpty, bool _cutaway, + bool _hideSystemBarLine, bool _mergeMatchingRests) { staff = _staff; invisible = _invisible; @@ -1568,7 +1569,8 @@ ChangeStaff::ChangeStaff(Staff* _staff, bool _invisible, ClefTypeList _clefType hideMode = _hideMode; showIfEmpty = _showIfEmpty; cutaway = _cutaway; - hideSystemBarLine = hide; + hideSystemBarLine = _hideSystemBarLine; + mergeMatchingRests = _mergeMatchingRests; } //--------------------------------------------------------- @@ -1584,7 +1586,8 @@ void ChangeStaff::flip(EditData*) Staff::HideMode oldHideMode = staff->hideWhenEmpty(); bool oldShowIfEmpty = staff->showIfEmpty(); bool oldCutaway = staff->cutaway(); - bool hide = staff->hideSystemBarLine(); + bool oldHideSystemBarLine = staff->hideSystemBarLine(); + bool oldMergeMatchingRests = staff->mergeMatchingRests(); staff->setInvisible(invisible); staff->setDefaultClefType(clefType); @@ -1600,7 +1603,8 @@ void ChangeStaff::flip(EditData*) hideMode = oldHideMode; showIfEmpty = oldShowIfEmpty; cutaway = oldCutaway; - hideSystemBarLine = hide; + hideSystemBarLine = oldHideSystemBarLine; + mergeMatchingRests = oldMergeMatchingRests; Score* score = staff->score(); if (invisibleChanged) { diff --git a/libmscore/undo.h b/libmscore/undo.h index be7153f17c8aa..576d3df05a70e 100644 --- a/libmscore/undo.h +++ b/libmscore/undo.h @@ -657,12 +657,13 @@ class ChangeStaff : public UndoCommand bool showIfEmpty; bool cutaway; bool hideSystemBarLine; + bool mergeMatchingRests; void flip(EditData*) override; public: ChangeStaff(Staff*, bool invisible, ClefTypeList _clefType, qreal userDist, Staff::HideMode _hideMode,bool _showIfEmpty, bool _cutaway, - bool hide); + bool hide, bool mergeRests); UNDO_NAME("ChangeStaff") }; diff --git a/mscore/editstaff.cpp b/mscore/editstaff.cpp index dbb9fbf4342de..5ebc6f68e7a63 100644 --- a/mscore/editstaff.cpp +++ b/mscore/editstaff.cpp @@ -110,6 +110,7 @@ void EditStaff::setStaff(Staff* s, const Fraction& tick) staff->setShowIfEmpty(orgStaff->showIfEmpty()); stt->setUserMag(orgStaff->staffType(Fraction(0,1))->userMag()); staff->setHideSystemBarLine(orgStaff->hideSystemBarLine()); + staff->setMergeMatchingRests(orgStaff->mergeMatchingRests()); // get tick range for instrument auto i = part->instruments()->upper_bound(tick.ticks()); @@ -135,6 +136,7 @@ void EditStaff::setStaff(Staff* s, const Fraction& tick) hideMode->setCurrentIndex(int(staff->hideWhenEmpty())); showIfEmpty->setChecked(staff->showIfEmpty()); hideSystemBarLine->setChecked(staff->hideSystemBarLine()); + mergeMatchingRests->setChecked(staff->mergeMatchingRests()); mag->setValue(stt->userMag() * 100.0); updateStaffType(); updateInstrument(); @@ -364,6 +366,7 @@ void EditStaff::apply() qreal userDist = spinExtraDistance->value(); bool ifEmpty = showIfEmpty->isChecked(); bool hideSystemBL = hideSystemBarLine->isChecked(); + bool mergeRests = mergeMatchingRests->isChecked(); bool cutAway = cutaway->isChecked(); Staff::HideMode hideEmpty = Staff::HideMode(hideMode->currentIndex()); @@ -422,9 +425,10 @@ void EditStaff::apply() || hideEmpty != orgStaff->hideWhenEmpty() || ifEmpty != orgStaff->showIfEmpty() || hideSystemBL != orgStaff->hideSystemBarLine() + || mergeRests != orgStaff->mergeMatchingRests() ) { score->undo(new ChangeStaff(orgStaff, inv, clefType, userDist * score->spatium(), hideEmpty, ifEmpty, cutAway, - hideSystemBL)); + hideSystemBL, mergeRests)); } if (!(*orgStaff->staffType(Fraction(0,1)) == *staff->staffType(Fraction(0,1)))) { diff --git a/mscore/editstaff.ui b/mscore/editstaff.ui index 3951494485998..a120372e5ea65 100644 --- a/mscore/editstaff.ui +++ b/mscore/editstaff.ui @@ -298,6 +298,13 @@ + + + + Merge matching rests + + +