Programming question: Hammer-on and Pull-off text

• Apr 22, 2021 - 11:47

I am currently working on adding hammer-on and pull-off support to Musescore. I have created a new slur object that is very similar to a tie (i.e. it connects 2 notes, not 2 chords). I have a question about how to add the text (i.e. the little "H" or "P".) The text can be placed in one of 4 locations: above, below, onslur and onstem.

The question is: Should I "draw" the text myself or should I add a Text (or SystemText) object. The second approach seems simpler because text objects already are hooked into the auto layout engine however the text will be independent from the slur which may be a problem. For example, if you delete the slur the text will remain. So you need some way to link a text object to my new slur object so the slur is aware of changes to the text.

The "draw the text like a glissando" approach is better but how do you make sure the text is included in the auto layout/stacking logic above/below the staff.

Any help here would be greatly appreciated.


Comments

Good question! My gut feel is that if you plan to make the text editable (and perhaps you should - in other languages H or P might not make sense) a text object contained within the main object could make sense. Then it will automatically have all the properties that go with text and you could conceivably hook them up to the Inspector. But, I would also say, it gets complicated all this no matter how you slice, and we've fought bugs over the years involving the text within a tuplet, or within lines, or chord symbols attached to fret diagrams, etc. Tuplets in particular I remember fixing a bug regarding this just a few months ago, look for recent commits by me in tuplet.cpp. I forget what the problem was exactly, but it related to how we propagate font settings between the tuplet object and the text within in.

Very possibly someone should rethink how all of these "composite" objects work, as right now it's pretty inconsistent.

In reply to by Marc Sabatella

Thanks Marc.
I was thinking of not allowing editing -- let that be a config thing -- set it up once and never touch it again. Bury it in some properties/style screen somewhere. Maybe provide an override in the inspector when you click on the slur.

This morning I discovered the SkyLine. I will see if that solves my collision problems? I will take a look at tuplet.cpp and maybe copy that approach.

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