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?

In reply to by jonarnold

Many thanks to all. This works very nicely!
I'm guessing there's a way of creating shortcut to use it - at the moment I'm going Plugins-Composing/Arranging tools - MusicFicta each time I make a change. Can I add it to a palette or right-click?

My method on editorial accidentals, for what it's worth, is:
(#) = it's obviously a sharp, but wasn't in the manuscript for clear reason (implied by lack of barline in original etc). Performer: trust me
[#] = my opinion is that it should be a sharp, as it's a sharp in another part, or intuitively needs to be a sharp to make musical sense of the phrase/harmony, or it's a typo/error in the part. Performer: trust me, but I may be wrong, and I'm signalling I've made a choice here
ficta # = an editorial decision based on the somewhat conflicting rules of ficta. Performer: take it or leave it, according to your own interpretation of ficta!

Enjoying using MS4 enormously, after many years of Sibelius.
Ned

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