Problems with removing empty trailing bars

• May 15, 2021 - 16:06


here is a German melody with some chords. Its construction is in this link for all people who can speak German.
This very composition ends with an empty bar with chords before it repeats and plays till "Fine". Unfortunately after that empty bar, there are some more empty bars with no chords.
If we go to Tools > Delete empty traling bars, then every empty traling bar will be deleted, even that one with the chords.
I think this bug should be fixed as some songs end with such bars and it is veery tedious to delete bars at the end.


Please report this in the issue tracker
The workaround is easy though, just select those measures and press Ctrl+Del

Here's the code responsible for this:

//   firstTrailingMeasure
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
      else {
            ChordRest* tempCR = *cr;
            while (m && (tempCR = m->first()->nextChordRest(trackZeroVoice((*cr)->track()), false))->isFullMeasureRest()) {
                  *cr = tempCR;
                  firstMeasure = m;
                  m = m->prevMeasure();
      return firstMeasure;

Which reveals that it indeed, starting with the last measure, picks on measures with full measure rests, not checking for chord symbols or anything else that would e.g. prevent a staff from getting hidden.
Seems that using the same algorithm that does hide empty staves should get used here.

Another workaround: in that last measure with 2 chord symbols, use 2 rests, or more exact: not a full measure rest.

In reply to by Jojo-Schmitz


      if (!cr)
            for (; m && m->isFullMeasureRest(); firstMeasure = m, m = m->prevMeasure());


      if (!cr)
            for (; m && m->isEmpty(-1); firstMeasure = m, m = m->prevMeasure());

might work, if also fixing a bug in Measure::isEmpty() that makes it crash on the -1, regardless this being documented to work and to check all staves for being empty.
For the else branch a different approach might be needed though.

Do you still have an unanswered question? Please log in first to post your question.