Is there a way for a plugin to know which staff(s) is/are selected?

• Aug 21, 2022 - 12:29

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

In reply to 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;
}

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