Measure::cloneMeasure() appends too many staves to cloned measure

• Mar 1, 2016 - 05:24
Type
Functional
Severity
S4 - Minor
Status
active
Project

In beginning of cloneMeasure(), after creating a new Measure. The measure constructor already appends a number of staves based on the number of staves in the score passed to cloneMeasure():

int n = _score->nstaves();

But then right after that, cloneMeasure() unecessarily addes extra staves to the measure based on the number of staves in the measure that is being cloned

      foreach(MStaff* ms, staves)
            m->staves.append(new MStaff(*ms));

But these extra staves are unecessary and a source of bugs.

Note that later when copying data for each tracks, it is only concerned with the number of staves in the dest score (not in the source measure).


Comments

For instance, if destination score to clone into has 2 staves, and input measure being cloned has 1 stave, then this code as is will erroneously produce 3 staves (2 staves by the measure constructor, then the additional stave), when resultant measure should only have 2 staves.

I'm going to replace

      foreach(MStaff* ms, staves)
            m->staves.append(new MStaff(*ms));

with a

      Q_ASSERT(sc->staves().size() >= staves.size()); // destination score must we're cloning into have at least as many staves as measure being cloned