Skip to content

Commit

Permalink
Fix #321227: Problems with removing empty trailing measures
Browse files Browse the repository at this point in the history
Duplicate of musescore#8111 resp. backport of musescore#8112
  • Loading branch information
Jojo-Schmitz committed Sep 1, 2021
1 parent 5d252b2 commit f7de618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,6 @@ bool Measure::isEmpty(int staffIdx) const
{
int strack;
int etrack;
bool hasStaves = score()->staff(staffIdx)->part()->staves()->size() > 1;
if (staffIdx < 0) {
strack = 0;
etrack = score()->nstaves() * VOICES;
Expand All @@ -2865,6 +2864,7 @@ bool Measure::isEmpty(int staffIdx) const
if (e && !e->isRest())
return false;
// Check for cross-staff chords
bool hasStaves = score()->staff(track / VOICES)->part()->staves()->size() > 1;
if (hasStaves) {
if (strack >= VOICES) {
e = s->element(track - VOICES);
Expand All @@ -2879,6 +2879,8 @@ bool Measure::isEmpty(int staffIdx) const
}
}
for (Element* a : s->annotations()) {
if (a && staffIdx < 0)
return false;
if (!a || a->systemFlag() || !a->visible() || a->isFermata())
continue;
int atrack = a->track();
Expand Down
12 changes: 8 additions & 4 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4280,11 +4280,15 @@ Measure* Score::firstTrailingMeasure(ChordRest** cr)
Measure* firstMeasure = nullptr;
auto m = lastMeasure();

// No active selection: prepare first empty trailing measure of entire score
if (!cr)
for (; m && m->isFullMeasureRest(); firstMeasure = m, m = m->prevMeasure());
// Active selection: select full measure rest of active staff's empty trailing measure
if (!cr) {
// No active selection: prepare first empty trailing measure of entire score
while (m && m->isEmpty(-1)) {
firstMeasure = m;
m = m->prevMeasure();
}
}
else {
// Active selection: select full measure rest of active staff's empty trailing measure
ChordRest* tempCR = *cr;
while (m && (tempCR = m->first()->nextChordRest(trackZeroVoice((*cr)->track()), false))->isFullMeasureRest()) {
*cr = tempCR;
Expand Down

0 comments on commit f7de618

Please sign in to comment.