Get cursor to score from parts
I'm trying to write a plugin that will set the accidentalBracket
of an accidental in the score to the existing value in the part (e.g. # is bracketed in the part only, so plugin would then bracket it in the score). I haven't worked with the cursor object much and need some help.
I can get the tick of the accidental (well, the segment) and rewind the cursor to that point, but:
1. How do I create a cursor object in the full score when curScore is a part?
2. How do I get the cursor to point to the same note in the correct staff? I don't have any chords in the project I'm working on, but I could imagine the need for multiple notes in a segment.
Here's my test code so far:
var element = curScore.selection.elements[0]; //var bracketSetting = element.accidentalBracket; var bracketSetting = 1; //for testing since the cursor is in the same score right now while(element.type != Element.SEGMENT) { element = element.parent; } var tick = element.tick; var cursor = curScore.newCursor(); cursor.rewindToTick(tick); cursor.element.notes[0].accidental.accidentalBracket = bracketSetting;
Thanks for the help!
Comments
First, before moving the cursor, you have to specify its track:
In reply to First, before moving the… by parkingb
Thanks! So I should maybe take this further by saving the pitch of the note at the beginning and only operating on a matching note in the for loop at the end.
So, how do I modify
var cursor = curScore.newCursor();
to direct the cursor to the score when selecting an accidental in the part? Or is there another way to refer to the same element in the score? That's the reason for the plugin.In reply to Thanks! So I should maybe… by jonarnold
I'm not sure to understand what you are trying to achieve.
What's your starting point ? A selected element ? A selected accidental ? Something else ?
And from that starting point, what do you want to do ?
In reply to I'm not sure to understand… by parkingb
Sorry my first post wasn't clear. I want to select an accidental in the linked part and have the properties (at least the bracket style) copied to the corresponding accidental in the score.
I'm entering music in the parts so that I can mirror the original partbooks with the line breaks and having notes display across measure boundaries. If I make an accidental bracketed there, I want to be able to transfer that easily without having to find it.
In reply to Sorry my first post wasn't… by jonarnold
I got your point, and well this puzzled me a lot.
There is a big WORDING issue in MS:
What is called "Part" in the User Interface is actually called "Excerpt" in the API,
While what is called "Part" in the API is actually a class on-top of the "Staff".
What adds to the confusion every excerpt behaves like a separated score which be obtained by the ...
partScore
property.So for your plugin forget about the Parts, look for the Excerpts.
Here is a sketch:
REMARK: this isn't a finished code. Up-to-you to finalize it.
In this code I deduce the "track" from the selected element.
But the "track" you'll get there is based on current excerpt, not on an overall position.
Look at the attached example:
The Eb for the Trumpet is on track 0 on the main score (curScore) and on track 0 on the trumpet's excerpt.
The code will work fine.
The Ab for the Saxophone is on track 4 on the main score (curScore) but on track 0 on the saxophone's excerpt (because that excerpt contains only one staff).
The code will not work correctly in that case.
Up to you to try to identify the right track. Maybe parse all the tracks and select the ones with the same instrument. But I hope that sketch will help you moving on.
In reply to I got your point, and well… by parkingb
Part is rather Instrument, may contain more than one staff (like for Piano)
Excerpt may contain more than one Part AKA Instrument. Or even less, just a some Staves or some of the 4 Voices of an Instrument
In reply to Part is rather Instrument,… by Jojo-Schmitz
Is there an easy way to identify a same track in different excerpts ? The track number doesn't work as it dependent of its position on the score/excerpt.
Is there some kind of unique ID that is exposed by the API ?
I was thinking to use the Instrument+voice as a kind of a pseudo-unique ID, but the instrument is not unique, thus this approach won't be really error-proof.
In reply to I got your point, and well… by parkingb
Thanks so much for working on this. It is very helpful for learning, and it's the next piece of what I want to be able to do with the plugin.
However, my first goal is to work in the opposite direction. I want to be able access the "full" score when
curScore
is an excerpt. The logical equivalent ofvar cursor = curScore.parent.newCursor()
, or in other words, going the opposite direction ascurScore.excerpts[i].partScore
.In reply to Thanks so much for working… by jonarnold
Actually "curScore" Is always the full score.
In reply to Actually "curScore" Is… by parkingb
That's not the way it functions for me. If I use the code in my first post on an accidental in the part/excerpt, it will affect the selection in that same part, not the score.
In reply to That's not the way it… by jonarnold
You are right. My mistake. I can't help you here. I looked in the datamodel, explored all the curScore properties, explored the various "cmd-xxx" commands. Nothing seems to allow you to retrieve the full score from one of the excerpt score.
In reply to You are right. My mistake. I… by parkingb
For the challenge it was, I manage to have a plugin working. Both ways, for all directions (from the full score to the excerpts and vice versa). I can share it with you.
In reply to For the challenge it was, I… by parkingb
Yes, that would be great! If you don't want to post it here, you can reach me on my contact page: http://jonarnoldmusic.com/contact/
In reply to Yes, that would be great! My… by jonarnold
Here it is:
https://gist.github.com/lgvr123/8a58229bd8a3d96144e3b4c60afcb30e
In reply to Here it is: https://gist… by parkingb
Thanks! I will look over this and try to figure it out.
I haven't followed this completely as I'm not that up on the plugin API, but just a general comment: normally, this isn't how you'd go about it it at all. Within MuseScore itself, the code almost never tries to find parts assdcociated with a score then hunt through the parts looking for the equivalent of a given element. Instead, each element contains links to the corresponding elements in parts directly - no hunting required. So, if that property - the list of linked elements for a given element - isn't exposed already, that's what should be, as that's what you should be looking at in trying to make an update to score & parts simultaneously.
In reply to I haven't followed this… by Marc Sabatella
This isn't exposed in the API. This should be helpful. Does it exist of every element ? E.g. From a saxophone part on an excerpt, it provides a direct link to this part on all the other excerpts ?
In reply to This isn't exposed in the… by parkingb
The link I am talking about is at the element level itself, not the part level. So, for a note in the score, it contains a list to the linked note in the corresponding part - or if there are multiple parts containing that instrument, the linked note each of the relevant parts. It works the same for linked standard+tab staves - the list of linked elements in cludes both the tab note and the corresponding note(s) in any parts. And the list is equally available whether starting from a note in the score or starting from a note in the part. And again, it's part of the element class (or perhaps scoreelement), so it applies to accidentals, text, articulations, etc - anything that inherits from element.
In reply to I haven't followed this… by Marc Sabatella
Yes, that would be great to be able to use. I see that there's an elements property that comes up as
< [object Object] >
for notes. Is that an array? I triedcurScore.selection.elements[0].elements[0].visible = false;
and got aTypeError
EDIT: It looks like the elements list property is for articulations attached to the note according to the API: https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
I don't see anything in the API for Elements that would help. So should I make a feature request to expose this?
In reply to Yes, that would be great to… by jonarnold
Makes sense to me.
In reply to Makes sense to me. by Marc Sabatella
Done: https://musescore.org/en/node/331694
In reply to Done: https://musescore.org… by jonarnold
Better: #331694: Expose element links (score<->parts) to plugin API