Detecting clef changes
Is it possible to detect clef changes with a plugin?
I tried to loop on the element of a score and check if their type is equal to Element.CLEF
(like in the attached example), but even if I have some clef changes in the score, the element type is never equal to Element.CLEF
.
Note that the attached example is for Musescore3.
Attachment | Size |
---|---|
ClefTest.qml | 1.43 KB |
Comments
I think the only way is to select all clefs with "Select -> All Similar Elements" and access them with "curScore.selection.elements". What can be done with it, apart from detecting the tick position, I really can't say...
In reply to I think the only way is to… by ILPEPITO
That would require the user to select the clefs before running the plugin though, which isn't ideal.
In reply to That would require the user… by looptailG
I partially correct what I said before: clef changes are included in the 'blue rectangle' type selection, unlike the clefs at the beginning of each staff. To access them it is always more convenient to use the method I indicated earlier (without the need to select the clefs individually). However... No property seems to indicate the difference between one clef and another...
In reply to I partially correct what I… by ILPEPITO
I'm afraid you're right, by looping over the element using
segment.next
I managed to get the key signature changes, but none of the properties seems to indicate which of the key it is.In reply to I'm afraid you're right, by… by looptailG
Key signatures are something else... you can get them with cursor.keySignature to cursor.tick position... If I remember correctly 0 = no accidentals, positive numbers for sharps, negative numbers for flats.
In reply to Key signatures are something… by ILPEPITO
Sorry, I meant to write clef, not key signature
In reply to Sorry, I meant to write clef… by looptailG
I send you your modified code, in this way you can see all the clefs (or rather the clef changes) that would be selected with the 'Blue rectangle' (the others in any case are not detected, both with the selection and without). It's not the way I would use but it doesn't matter. It remains to be seen what you can do with it...
In reply to I send you your modified… by ILPEPITO
For anyone interested, here (perhaps) is a way to identify clef changes...
In reply to For anyone interested, here … by ILPEPITO
Last information, then I'll close. By setting the cursor.filter to 'HeaderClef' you can also access the clefs located at the beginning of each staff...
In reply to For anyone interested, here … by ILPEPITO
With this it should be possible to detect clef changes. I checked and G, C and F clefs have different bounding boxes, which remains consistent regardless of the staff line the clef is on.
By checking those value, and the y position to find the staff line, it should be possible to get the clef.