Skip to content

Commit

Permalink
ported #6746, #6749, #6757 : rest improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Feb 15, 2021
1 parent aa05efa commit beb4106
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/libmscore/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,39 +443,44 @@ int Rest::computeLineOffset(int lines)
}
}

if (offsetVoices) {
// if the staff contains slash notation then don't offset voices
int baseTrack = staffIdx() * VOICES;
for (int v = 0; v < VOICES; ++v) {
Element* e = s->element(baseTrack + v);
if (e && e->isChord() && toChord(e)->slash()) {
offsetVoices = false;
break;
}
}
}

if (offsetVoices && staff()->mergeMatchingRests()) {
// automatically merge matching rests in voices 1 & 2 if nothing in any other voice
// automatically merge matching rests if nothing in any other voice
// this is not always the right thing to do do, but is useful in choral music
// and perhaps could be made enabled via a staff property
// so choral staves can be treated differently than others
// and can be enabled via a staff property
bool matchFound = false;
bool nothingElse = true;
int baseTrack = staffIdx() * VOICES;
for (int v = 0; v < VOICES; ++v) {
if (v == voice()) {
continue;
}
Element* e = s->element(baseTrack + v);
if (v <= 1) {
// try to find match in other voice (1 or 2)
if (e && e->type() == ElementType::REST) {
// try to find match in any other voice
if (e) {
if (e->type() == ElementType::REST) {
Rest* r = toRest(e);
if (r->globalTicks() == globalTicks()) {
matchFound = true;
continue;
}
}
// no match found; no sense looking for anything else
matchFound = false;
break;
} else {
// if anything in another voice, do not merge
if (e) {
nothingElse = false;
break;
}
}
}
if (matchFound && nothingElse) {
if (matchFound) {
offsetVoices = false;
}
}
Expand All @@ -494,8 +499,9 @@ int Rest::computeLineOffset(int lines)
// Ignore stems and articulations, because which multi-voice they are at the opposite end.
int upOffset = up ? 1 : 0;
int line = up ? 10 : -10;

// For compatibility reasons apply automatic collision avoidance only if y-offset is unchanged
if (qFuzzyIsNull(offset().y())) {
if (qFuzzyIsNull(offset().y()) && autoplace()) {
int firstTrack = staffIdx() * 4;
int extraOffsetForFewLines = lines < 5 ? 2 : 0;
bool isMeasureRest = durationType().type() == TDuration::DurationType::V_MEASURE;
Expand Down

0 comments on commit beb4106

Please sign in to comment.