cursor.goToSelectionEnd() and cursor.goToSelectionStart() seem to behave differently to the documentation
I am using Windows 7, MuseScore 1.2, Revision 5470.
When trying to write a plugin, I found that cursor.goToSelectionEnd() and cursor.goToSelectionStart() seem to behave differently to the documentation.
The cursor documentation, here:
http://musescore.org/en/plugin-development/cursor-object
states the following about goToSelectionEnd() (I have bolded the parts to notice particularly):
"Positions the cursor immediately after the last chord or rest at the end of selection, voice will be 0. The staff property has to be previously set. If no selection exists in that staff, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true.
Note: a single 'blue' note or rest is not considered a selection; only extended selections ('blue rectangles') are taken into account."
However, in actual practice, it seems that it doesn't mater what you set the staff to before you call goToSelectionEnd. cursor.staff will always be set to the staff after the last staff in the selection, which may not even exist. E.g. if you have staves 0 & 1 selected, then cursor.staff will be 2 after cursor.goToSelectionEnd(), even if there is no staff number 2 in your score.
Similarly, the documentation for goToSelectionStart() says:
"Positions the cursor at the chord or rest at the beginning of the selection, voice will be 0. The staff property has to be previously set. If no selection exists in that staff, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true.
Note: a single 'blue' note or rest is not considered a selection; only extended selections ('blue rectangles') are taken into account."
In reality, calling cursor.goToSelectionStart() seems to ignore whatever you set cursor.staff to be, and simply goes to the first staff in the selection. You have to set the staff after you have called cursor.goToSelectionStart() to access a different staff in the seleciton.
I suggest the documentation needs changing to match what actually happens - i.e. cursor.staff does not need to be set before calling goToSelectionStart() and goToSelectionEnd(). Also, after cursor.goToSelectionStart(), cursor.staff will be the first staff in the selection. After cursor.goToSelectionEnd(), cursor.staff will be one greater than the last staff in the selection, which may not even exist.
See also the example code here, which relies on the actual behaviour of .goToSelectionStart/End, not their documented behaviour.
http://musescore.org/en/plugin-development/how-plugin-development and the code in the section "Applying a Function to Each Note of a Selection."
Comments
I've modified http://musescore.org/en/plugin-development/cursor-object, please check.
Thanks, Jojo-Schmitz. However, there is still one sentence in each description that needs some fixing, as follows:
I did some testing of the behavour of these methods. I made a selection in Staff 1 only (i.e. the 2nd staff in the score; the first staff is staff 0), and ran the following code:
cursor.staff = 0;
print(" cursor.staff has been set to " + cursor.staff + "\n");
cursor.goToSelectionStart();
print(" after cursor.goToSelectionStart, cursor.staff = " + cursor.staff + "\n");
Which gives the following output:
cursor.staff has been set to 0
after cursor.goToSelectionStart, cursor.staff = 1
..... so the sentence, "If no selection exists in that staff, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true." in the documentation is false. It should probably be chaned to say "If no selection exists in that SCORE, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true."
Similarly, for goToSelectionEnd, the documentation says "If no selection exists in that staff, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true." ... but running the following code:
cursor.staff = 0;
print(" cursor.staff has been set to " + cursor.staff + "\n");
cursor.goToSelectionEnd();
print(" after cursor.goToSelectionEnd, cursor.staff = " + cursor.staff + "\n");
print(" cursor.eos = " + cursor.eos());
... when only staff 1 is selected results in:
cursor.staff has been set to 0
after cursor.goToSelectionEnd, cursor.staff = 2
cursor.eos = false
This score had only two staves (0 & 1), so just like the case for goToSelectionEnd, the documentation should be changed to read, "If no selection exists in that SCORE, the cursor will be positioned at the end of score, i.e. cursor.eos() would return true."
done. does it look OK now?
Looks good now. Thanks for fixing it.
Automatically closed -- issue fixed for 2 weeks with no activity.