selections and cursor.rewind
I want to select some notes, and then examine the segments in the measures these notes belong to in a plugin. (ultimite goal is to delete some rests generated by changing the voice of a note).
But trying to do this raises a lot of questions.
Can this be done by iterating through segments, without using a cursor? (both objects have prev and next functions or properties) ?
If you select some notes randomly (by clicking on the noteheads), are the elements in curScore.selection.elements ordered in some way? f.i. in order of their selection, or sorted by their position?
If I have an element (from the curScore.selection.elements list), How can I get to the segment this element belongs to? Or to obtain the tick of the element?
The documentation at https://musescore.org/en/developers-handbook/references/musescore-inter… says: A segment contains a list of elements that occur at that time position across all staves.
The segment object has an annotations list, but not an element list. It does have an elementAt() function.
So is it correct to conclude that 'A segment contains a list of elements' means that it can 'contain' one element for each track?
cursor.rewind(1) rewinds the cursor to the beginning of a selection, so is it correct that after rewind(1), cursor.segment contains the segment the first selected element belongs to?
Does cursor.rewind(1) is supposed to work only for range selections?
var start_seg = cursor.segment;
console.log('cursor', cursor, 'segment', start_seg, 'tick', cursor.tick);
When I select a range with one note (i.e. a blue rectangle around a single note), I get:
Debug: cursor Ms::PluginAPI::Cursor(0x1c819b60) segment Ms::PluginAPI::Segment(0x1c7b3eb0) tick 960
But when I select only the note (i.e. I select the note and the notehead is blue), I get:
Debug: cursor Ms::PluginAPI::Cursor(0x1c6c3ea0) segment null tick 0
Perhaps this is related to question 2.
Thanks for your help,