Adding a tempo marking ‘hangs’ a plugin that iterates over annotations.

• Feb 23, 2022 - 15:18

Run tempotest2.qml on notempotest.mscz : output is fine;
Run tempotest2.qml on tempotest.mscz (same file with tempo marking added): plugin & Musescore 3.6.2 ‘hang’
Workaround: delete the tempo marking by selecting the tempo marking, right clicking & choosing del from the menu. Simply deleting the tempo marking text is no good: the plugin still hangs & the default tempo (F11) is still the tempo of the tempo marking.

Attachment Size
Tempotest.mscz 6.02 KB
NoTempotest.mscz 5.85 KB
Tempotest2.qml 712 bytes

Comments

Because you create an infinite loop in your plugin.

You only go to the next annotation if the annotation you encounter is a Harmony element. Which means that on encountering any other annotation (such as a Tempo Marking for example) you will end up in an infinite loop.

Also note that your loop condition is testing for a falsy value and hopes that an out of bounds annotation will be as such. There is no guarantee on that at all.
So better change your loop into one that doesn't go out of bounds on the annotations array to start with:

// Option 1
for (var annIdx in segment.annotations) {
    var annotation = segment.annotations[annIdx];
    // Process the annotation
}
 
// Option 2 - including sanity check on the property
if (segment.annotations && segment.annotations.length) {
    for (var annIdx = 0; annIdx < segment.annotations.length; ++annIdx) {
        var annotation = segment.annotations[annIdx];
        // Process the annotation
    }
}

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