Center horizontally on notehead
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);
In reply to This gets pretty close, but… 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 I think I figured it out… by jonarnold
I found curScore.style.value("smallNoteMag")! Sorry for thinking out loud on this thread. I've attached an updated plugin. Please let me know if you have any feedback!
Future improvements: check for selection of an accidental, account for prior alteration of that accidental, multiple selections
In reply to I found curScore.style.value… by jonarnold
Updated version accounts for notes that are above the staff and would have created a collision.
In reply to Updated version accounts for… by jonarnold
Here's an updated version that allows for a range selection and accounts for prior offset of an accidental. Uploading for feedback before I submit it to the plugin repo. Would love to get any suggestions for improvement!
In reply to Here's an updated version… by jonarnold
Hi. I've downloaded your ficta plugin, into MuseScore 4 and it crashes the program unfortunately. Is there a version compatible with MS4?
In reply to Hi. I've downloaded your… by nedkershaw
Try this
In reply to Try this by Jojo-Schmitz
Thanks for doing this quick update! I've needed to upload a new one, so I'll do that now.
In reply to Thanks for doing this quick… by jonarnold
Hmm your plugin isn't quite working for me, and I'm having trouble getting the Component.onCompleted section to work. I'll need to do more work on this.
In reply to Hmm your plugin isn't quite… by jonarnold
The onCompletion stuff is neded for Mu4 to show the name of the plugin
Edit: Oh, I see, I missed a closing brace
In reply to The onCompletion stuff is… by Jojo-Schmitz
Mine oddly works without that block but not with it. I opened another thread: https://musescore.org/en/node/350585
In reply to Mine oddly works without… by jonarnold
I've also forgotten an import...
Try this. Should finally really work for Mu4 and Mu4
In reply to I've also forgotten an… by Jojo-Schmitz
That one does load on v4, but it doesn't seem to function correctly, at least not immediately. I don't get any helpful error messages, but I did switch away from the program and found that it had worked. Very odd.
In reply to That one does load, but it… by jonarnold
OK, I see why...
Mine is lacking the
startCmd()/endCmd()
, those are needed in Mu4 and good in Mu3, for the undo stackIn reply to That one does load, but it… by jonarnold
Try this please
In reply to Try this please by Jojo-Schmitz
Thanks, that works! So the semicolons in the Component block were not correct? That code came from https://musescore.org/en/node/337468 so maybe that page should be edited.
Can you explain why I needed QtQuick?
I'm also adding
menuPath: "Plugins.MusicaFicta"
to make it appear in MuseScore 3.In reply to Thanks, that works! So the… by jonarnold
QtQuick is needed for that onCompletion stuff
The semicolons are optional AFAIK
In reply to Hi. I've downloaded your… by nedkershaw
Thanks for using the plugin. If the one posted below doesn't work, try this one.
In reply to Thanks for using the plugin… 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
In reply to Many thanks to all. This… by nedkershaw
When you enable the plugin from the plugin manager, you can select the shortcut there.
In reply to When you enable the plugin… by Marc Sabatella
Thanks Marc. Done.