Add missing elements to incomplete tuplets when reading from a file

• Mar 20, 2018 - 11:03
Reported version
S5 - Suggestion

With commit f8ff847, MuseScore no longer allows the deletion of rests within tuplets. MuseScore should now check for incomplete tuplets when loading a score from a file, and add any missing elements to the tuplets as invisible rests.


The tricky part is figuring out whether to insert a hidden rest into the tuplet before the first known element, and if so, what the duration of that rest should be. This is only tricky because the size of the gaps to either side of the known elements of the tuplet may be larger than what is required for the missing elements. Filling in gaps in the middle of the tuplet is not a problem. Care should be taken to ensure that the tuplet starts on a sensible tick, and that the elements of the tuplet are of a sensible duration. Once we know where the tuplet really starts, the rest (no pun intended) is easy.

I believe a reasonable guess for the start of the tuplet is something like:

expectedTick = elements().front()->tick() - elements().front()->tick() % duration().ticks();

Then, if expectedTick == elements().front()->tick(), we should probably not insert an element before elements().front(), and no more guessing is required. If they are not equal, we need to take into account the first available tick and the number of ticks required (inside the tuplet) for the duration of the missing elements. This is easily done. If we can still use expectedTick for the start of the tuplet, we do so.

Of course, a tuplet can be created that starts on a tick that is not divisible by the duration of the tuplet. If such a tuplet is encountered that needs correction, this may figure an earlier start tick for the tuplet, giving the first and last elements a weird duration. But how often is that going to happen?