How to determine if grace notes comes before or after the associated main note.

• Jun 24, 2019 - 16:47

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

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

graceNoteTestScore.png

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 installed
Requires 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 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 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 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 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:

  • The "before" list is in the order as seen visibly in the score.
  • The "after" list is in reverse order from those seen visibly in the score.

-Dale

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