Center horizontally on notehead

• Jan 30, 2022 - 19:48

I'm working on a very basic musica ficta plugin. I'm still learning the API, but my efforts so far are attached. It does not parse more than one accidental yet and does not have any error detection.

I need help figuring out how to get a precise Xoffset to center the accidental horizontally every time. I posted on the support forum (https://musescore.org/en/node/328913) looking for a way to center an accidental, but I think it's more appropriate here. What's the best way to calculate the width of a notehead and then convert that to staff spaces? I also need to account for the original spacing between the notehead and the accidental. Would I use the horizontal dimensions of the bbox?

Thanks for any help!

Attachment Size
musicaFicta.qml 764 bytes

Comments

This gets pretty close, but not quite exact in all cases (see the sharp over the C in the screenshot). It doesn't look good on whole notes though.

var accidentalWidth = ficta.bbox.width;
var noteWidth = ficta.parent.bbox.width;
targetOffsetX = (noteWidth/2)+(accidentalWidth);

Attachment Size
xOffsetTest.png 12.36 KB

In reply to by jonarnold

I think I figured it out after I found the posX property:
var positionX = ficta.posX;
var noteWidth = ficta.parent.bbox.width;
var accidentalWidth = ficta.bbox.width;
ficta.offsetX = (noteWidth-accidentalWidth)/2-positionX;

This works great except that when I make the accidental small, all of these numbers are no longer accurate. Can I retrieve the small note percentage from the style properties, or is it possible to calculate the widths and positions after the small property change has been set?

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