Detecting clef changes

• Dec 12, 2024 - 16:31

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 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 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...

Attachment Size
ClefTest.qml 1.58 KB

In reply to 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.

Do you still have an unanswered question? Please log in first to post your question.