How to determine if grace notes comes before or after the associated main note.
Hi,
I'm trying to add tablature fingering images for tin whistle grace notes from within a QML based plugin.
This is a pre-existing plugin that I've forked so I can fix various behaviours that occurred on the MuseEdit 3.0 release. One plugin requirement has been accepted for the 3.2 release. It provides the Part.instrumentId property lost in the 3.0 upgrade. With that change the plugin works well--except for grace notes.
The tab fingering images are characters from a special font having tin whistle fingerings for each note.
To accomplish this I believe I need to walk the grace notes associated with the main note and determine their position before and after the main note.
I can walk the grace notes fine but as far as I can see there is no way to get positioning information from the QML interface. In fact I can't even answer the basic question of if the note is before or after the main note.
I do see such capabilities in the C++ code and they are used extensively in the layout code. I think I need access to something similar to do my layout from the plugin.
I've attached my example score and plugin file that I've been experimenting with.
I've added some code to the plugin to dump various object/interface info but I can't find anything that would assist me.
Am I attacking this from the wrong angle?
Any insights would be greatly appreciated!
Dale
Attachment | Size |
---|---|
Grace_note_tab_test.mscz | 5.58 KB |
tin_whistle_tablature-hack.qml | 10.25 KB |
Comments
As a follow on...
The idea of a trailing grace note seems to be work in MuseScore but not in MusicXML.
If you create a note with leading and trailing grace notes in MusicScore and you save it as musicxml. Reloading that musicxml file into will lose the trailing grace note association. The trailing grace notes are attached to the next regular note in the score.
Dale
In reply to As a follow on... The idea… by DLLarson
My workaround for now is to simply assume the trailing is not supported in the score and assume that all grace notes are of the leading variety. With this approach I can layout the tab images properly.
It still doesn't solve the overall problem though.
Dale
Whilst I can see the NoteType enumeration itself is exposed (https://dmitrio95.github.io/plugins/html/namespace_ms.html) I currently indeed don't find a property using it.
Therefor my conclusion would be that this information is currently unavailable to the plugin framework.
In reply to Whilst I can see the… by jeetee
Yep...
That's the enum I was looking at. It's used internally to layout the grace notes.
If such a property were exposed on what level would it be placed?
In reply to Yep... That's the enum I was… by DLLarson
I would expect it on the Chord element (the graceChord in this case), as the exposure of https://github.com/musescore/MuseScore/blob/fbfd693d79e5b55879f658a2248…
It might be exposed on the graceNote itself as well for convenience, after all, it currently is so on the C++-side as well.
In reply to I would expect it on the… by jeetee
Well it turns out that the NoteType enum was not exposed to QML.
The plugin doxygen docs are missleading. It's just showing all the enums swept up in the source code scan.
In the current code exposed enum types need to be moved to libmscore/types.h to be exported. I have successfully done that and can access the enum in the script. This QML:
console.log("enum value=", NoteType.APPOGGIATURA)
produces this output:
Debug: enum value= 2
I still haven't been able to expose the property itself. In the libmscore note.h/cpp code the noteType delegates to the chord element you found so I know we're on the right path. I'm still missing some secret sauce to get it working. I'm getting close. Stay tuned.
In reply to Well it turns out that the… by DLLarson
I got it working.
The weird thing is that the graceNote list is in reverse order. i.e., from right to left. This score when walked from the start :
Produces this QML result:
Running…
Plugin Details:
Menu Path: Plugins.Tin Whistle.Add tablature
Version: 3.0
Description: This plugin provides fingering diagrams for the tin whistle. Ensure font
TinWhistleTab.ttf
is installedRequires Score
Debug: hello tin whistle tablature
Debug: Full score staves 0 - 0
Debug: Staff 0 whistle type: wind.flutes.whistle.tin.d
Debug: Loop through main note's grace notes.
Debug: note.pitch= 76
Debug: note.noteType= GRACE8_AFTER
Debug: note.pitch= 78
Debug: note.noteType= GRACE8_AFTER
Debug: note.pitch= 79
Debug: note.noteType= GRACE8_AFTER
Debug: note.pitch= 83
Debug: note.noteType= APPOGGIATURA
Debug: note.pitch= 81
Debug: note.noteType= APPOGGIATURA
Debug: Loop through main note's grace notes.
Debug: note.pitch= 83
Debug: note.noteType= GRACE8_AFTER
Debug: Loop through main note's grace notes.
Debug: note.pitch= 76
Debug: note.noteType= APPOGGIATURA
Now it needs to survive a push request to the main code.
-Dale
In reply to I got it working. The weird… by DLLarson
The weird thing is that the graceNote list is in reverse order. i.e., from right to left.
At closer inspection of the pitches I seeded in descending order, it looks like the list provides the trailing grace notes from farthest toward the main note. Then it delivers the grace notes from the again farthest to towards the main note.
Very strange.
-Dale
In reply to The weird thing is that the… by DLLarson
I think I see why the list is ordered is this manner.
If you look at functions graceNotesBefore() and graceNotesAfter() you can see that they scan the main grace note list and save the graceNotes in the order found onto their respective lists:
https://github.com/musescore/MuseScore/blob/master/libmscore/chord.cpp#…
The following code uses the above functions to render the notes and has comments about the ordering of the lists:
https://github.com/musescore/MuseScore/blob/master/libmscore/chord.cpp#…
Mystery solved.
-Dale
In reply to The weird thing is that the… by DLLarson
I don't know that part of the code, but if you add grace notes, the first one is closest to the main note, the next is farther away and so forth. You haven't mentioned grace notes after in your results, but I suspect the first one listed will be the one closes to the main note (left to right) rather than right to left again. This is how they are added to the note.
In reply to I don't know that part of… by mike320
What the code says is that if you scan the graceNote list (internally with C++ or using QML) and you, in order, create two lists--one for the "before" grace notes and one for the "after" grace notes--adding each note to the end of the list based on the noteType being "before" or "after" you will end up with two lists:
-Dale