Note’s Elements structure

• Jan 6, 2021 - 03:16

I am trying to read if a note has had articulations or tremolos add to it but cannot find it in the note object. I am guessing it is kept in the elements sub object, but I cannot figure out its structured to be able to read anything from it. Any help would be appreciated.


Comments

It should be a list/array of Elements, so I'd expect something like this to work out:

for (var el in theNote.elements) {
    console.log(el.type + ' ' + el.name);
}

Articulations and tremolos are not attached to Notes but to Chords.

To learn more about the structure of the elements as exposed by the plugin framework, sometimes the best way to learn is to examine the actual structure within the MuseScore source code. See libmscore/chord.h, also libmscore/chordrest.h (parent class of chord & rest) and libmscore/note.h for the definitions of these classes.

In reply to by parkingb

In libmscore/chord.h the tremolo is defined in the same way as the stem, stem slash,etc.
You do not get to these items from the elements but by directly pulling them from the chord
chord.stem or chord.stemslash
This is because they have been define in the chord wrapper in the plugin api.
Tremolo and Articulations are not defined in the API so they are not searchable.
If I am wrong let me know, or else how can I put in a call for these to be added to the chord wrapper.
Pictures are a segment of libmscore/chord.h and plugin/api/elements.h

In reply to by dalekdarbuka

I don't find them neither.
I just dumped all the properties and elements of a note and its parents, and a tremolo and its parents. The parent of the tremolo is indeed the chord, but I don't find to any reference to it in the chord itself. The same applies for articulations.

Could another approach be working on the user's selection ? Or even selecting everything from the code (don't know if it is possible).
Because you can find the tremolo in the selection.


var selection = curScore.selection;
var el = selection.elements;
if (el.length==0) {
invalidSelectionDialog.open();
return;
}

// the tremolos are now among the el array.

Attachment Size
tremolo_dump.txt 11.83 KB

In reply to by parkingb

That is where I was going. Basically finding the tremolos and articulations in the score and checking them to the chords to see which is the parent. The problem I am having is that I can only find it in the selection and as it is what I am doing does not use selections. I cannot even find an object of all elements in a score. I’ll keep looking and if anything will have to switch over to a selection style.

In reply to by dalekdarbuka

Some basic code of mine:

var cursor = curScore.newCursor();
curScore.selection.selectRange(0,curScore.lastSegment.tick + 1,0,curScore.nstaves - 1);
var el = curScore.selection.elements;
var tremolos = [];
for (var i = 0; i < el.length; i++) {
var element = el[i];
console.log("* "+i+") "+element.type + " -- "+element.name);
if (element.type == Element.TREMOLO) {
tremolos.push(element);
}
}
}

In reply to by dalekdarbuka

So since tremolo and articulations are not actually in the plugin api (you cannot tell what type of tremolo or articulation it is), and it would make more sense to be able to read them from their actual parent. I am putting what I am doing on hold and see if I can contribute to flushing out the api more.

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