Is there a way for a plugin to know which staff(s) is/are selected?
In a plugin a selection is usually detected by:
cursor.rewind(1); // go to the beginning of the selection
cursor.rewind(2); // go to the end of the selection
But if I only select one staff in a piano score my plugin will affect notes in both staffs.
Is there a way for the plugin to know which staff(s) is/are selected?
Comments
Check colornotes.qml, lines 49-65 for a better detection of a selection
In reply to Check https://github.com… by Jojo-Schmitz
That works! Many thanks!!
In reply to That works! Many thanks!! by elsewhere
IIRC it needs a later 3.x (not sure which though) and didn't work in 3.0.
Ah:
selection.elements
needs MuseScore 3.3 or later, quite a few further methods need 3.5 or laterIn reply to IIRC it needs a later 3.x … by Jojo-Schmitz
Another way, found in existing plugin code is:
EDIT: It's code from the notenames plugin
After cursor.rewind(1) (start of selection) startStaff = cursor.staffIdx
After cursor.rewind(2) (end of selection) endStaff = cursor.staffIdx
With the proviso:
if (cursor.tick === 0) {
// this happens when the selection includes
// the last measure of the score.
// rewind(2) goes behind the last segment (where
// there's none) and sets tick=0
endTick = curScore.lastSegment.tick + 1;
endStaff = curScore.nstaves - 1; // and end with last
else {
endTick = cursor.tick;
endStaff = cursor.staffIdx;
}