Skip to content

Commit

Permalink
Manually merged #5896 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-os committed Aug 20, 2020
1 parent f30bec6 commit 13551ef
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
5 changes: 2 additions & 3 deletions libmscore/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -473,7 +473,6 @@ int Rest::computeLineOffset(int lines)
offsetVoices = false;
}
}
#endif

int lineOffset = 0;
int assumedCenter = 4;
Expand Down
6 changes: 6 additions & 0 deletions libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions libmscore/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 8 additions & 4 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1568,7 +1569,8 @@ ChangeStaff::ChangeStaff(Staff* _staff, bool _invisible, ClefTypeList _clefType
hideMode = _hideMode;
showIfEmpty = _showIfEmpty;
cutaway = _cutaway;
hideSystemBarLine = hide;
hideSystemBarLine = _hideSystemBarLine;
mergeMatchingRests = _mergeMatchingRests;
}

//---------------------------------------------------------
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion libmscore/undo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};

Expand Down
6 changes: 5 additions & 1 deletion mscore/editstaff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)))) {
Expand Down
7 changes: 7 additions & 0 deletions mscore/editstaff.ui
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@
</item>
</layout>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="mergeMatchingRests">
<property name="text">
<string>Merge matching rests</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 13551ef

Please sign in to comment.