Using note.add(text) doesn't seem to work.

• Jun 13, 2023 - 22:05

I have a note object variable called note, (which I have checked is actually a note object by viewing its element type and its play events), and I want to add a text element to this note.

I have made a new text object variable by using newElement(Element.STAFF_TEXT) and have set various properties of this text object. However, when I use note.add(text) nothing happens. I was expecting this to add the text element to the note in the score.

What am I doing wrong?


Comments

note.add really only works for super small, note-related elements (like accidentals, bends, maybe some others) but it doesnt work for anything larger (text, dynamics, even most articulations)

In reply to by XiaoMigros

In the UI, texts are added to the score by first selecting a note. My (incorrect) reasoning was that the equivalent in a plugin would therefore be to use note.add() with a text element. Wrong! Your comment confirms that I had taken the wrong route. I'm not sure whether this issue is because texts are not actually note properties or that the plugin API just hasn't implemented this capability.

The plugin documentation is helpful but a bit thin on the ground when it comes to explanations and examples but I'm getting there with some trial & error and forum support.

In reply to by yonah_ag

staff text is parented to a segment, not a note or chord, which is why if you delete the notes in a chord the text remains. the opposite is true for note.add elements: they will definitely be deleted if you delete the note (not necessarily chord) they were added to.

In reply to by XiaoMigros

That makes sense.
I've just run the TAB Walk plugin and can clearly see the separate routes:

Segment > ChordRest > Annotation > StaffText vs

Segment > ChordRest > Chord > Notes

Hopefully, next time I have a similar issue, I will remember to use TAB Walk first and save myself some head scratching!

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