Knowing which staff/clef a Note is on ?
I'm iterating over a score and I want to separate the staff/clef (not sure what the nomenclature is for musescore) into different elements that I'm going to be pasting into another program (see my other post for details). I can work with stitching them together, but it would be cleaner if I could separate them.
Is there a way I can tell which staff a Note object is on ?
Likewise, in a similar vein - given a note, is it possible to tell:
1) What the key signature is for the given Note ?
2) What the time signature is for the given Note ?
The last two are just gravy, but would be great.
Comments
How are you iterating over the score?
If you use a Cursor, you start by setting it's track, which is a voice within a certain staff; so everything after that is then pre-filtered for you. You can also set it's filter to include key and time signatures instead of the default ChordRests only.
Or you can access it's
.keySignature
property if you don't keep track of those yourself.Paste the below into a new plugin in onRun and you'll see it logging out what you're looking for:
In reply to How are you iterating over… by jeetee
Thank you! Is it possible to do the same thing with a selection ?
In reply to Is it possible to do the… by mrproxxxy1
So you're not iterating over a score as your post indicated.
Rewind to SELECTION_START instead? (and SELECTION_END as well to know when to stop) at least if it's a range selection.
In reply to Rewind to SELECTION_START… by jeetee
I'm doing both! Depending on whether or not a selection has happened. If I can use the same logic, all the better.
That's a bingo, though - excellent! Now I just need to rewrite my iteration logic. :)
But if you have an Element already, according to the API you can just do
.staff
to get the staff? https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…In reply to But if you have an Element… by jeetee
That's why I clarified "Clef" - it looks like the staff object doesn't contain all of the necessary information to know if, say, you're in the Treble Clef of a piano part. So I wasn't sure if the meaning overlapped or if I was missing something/etc.
In reply to That's why I clarified "Clef… by mrproxxxy1
Since a Clef can change throughout a Staff, the Staff object indeed can't give you a simple answer to that question; it'd need a time reference and then search backward from there to give you that answer.
Something you can do with a Cursor instead (go to selection start, filter for HeaderClefs (? not sure, try All and see how it is identified), test selection start, then move backwards until you find a Clef).
But that'd still won't tell you whether you're on the upper or lower staff of a Grand Staff instrument.
In reply to That's why I clarified "Clef… by mrproxxxy1
I use a workround - create temporary middle c and read its y position
In reply to I use a fix - create… by sammik
This doesn't make sense to me. Isn't posY a position relative to the parent (in this case the chord?) (as per https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…).
This seems like a bad approach to determine a clef; making it likely hard to account for transposing instruments and transposing clefs.
If you want to figure out the clef (again, which has no determinate relation to identifying a staff) then why not navigate backwards until you find an actual Clef element?
But as mentioned before; the clef does not define which staff your on at all.
In reply to This doesn't make sense to… by jeetee
Because in plugin, You can get only info "CLEF", but not which one.
https://musescore.org/en/node/321532
If we didnt miss something.
In reply to Because in plugin, You can… by sammik
So it seems not exposed indeed.
But I thought your actual goal was figuring out whether you're on the top or bottom staff of grand staff, correct? So why not test the staff against the staves in the (API)-Part instead?