Plugin is not changing the score if Dialog is used
I have made a plugin that creates notes from Harmony texts (based on the plugin chordsToNotes). It's working good if I don't use a Dialog, it creates all notes (changing the score).
But when I use a (starting) Dialog it run through the code without problem, but nothing happens with the score. I have very detailed logging and all looks fine, it logs exactly the same as if the Dialog isn't used, the code for creating/adding notes are done, but nothing happens with the score.
It's strange, I also tried to do the main logic in onRun
after dialog.open()
, then it works (but no settings from the Dialog since the code in onRun
doesn't wait for the Dialog to close). It's exactly the same main logic that are called from onClicked
for a Button in the Dialog, but as I wrote, when called from there it runs through the code but nothing is really changed in the score.
Any suggestions?
Comments
What plugin, what version of MuseScore which OS?
In reply to What plugin, what version of… by Jojo-Schmitz
It's a new plugin I'm working on. MS 2, Windows 7.
But the answer from @PaulSC solved it!
You could try surrounding the call to score-processing with these commands:
(Although I think of these as making your changes undo-able, and I don't know why you'd need them to apply changes.) If this wild guess doesn't help, it might be useful to post a sketch of your code.
In reply to You could try surrounding… by PaulSC
Thanks a lot, you are my hero!
It also solved another problem I had.
I have tried with
curScore.endCmd();
before, but then I didn't usecurScore.startCmd();
at the start of the plugin. Thought that it wasn't necessary, I saw a warning in the log thatstartCmd()
wasn't used but because there were no errors, only a warning, I thought that it was automatically done.Tanks again!
Now my plugin is working good.
In reply to You could try surrounding… by PaulSC
and I don't know why you'd need them to apply changes
See them more as a start defining my action here up until endCmd completes the definition of it, allowing it to be executed and undone.
In reply to You could try surrounding… by PaulSC
FWIW, endCmd() is typically where the layout happens after executing the code associated with a command. Without it, you won't see any visible effect of the change. That's not just for plugins but for the source to MsueScore itself as well.
In reply to FWIW, endCmd() is typically… by Marc Sabatella
Ok, good to know.
The plugin works good now. But there is one issue, I think it's a bug (minor). When I use the above
startCmd...endCmd
the changes are shown ok when the plugin finish. But the state of the score isn't good. If I save and open it again it's no problem, but if I keep doing things MuseScore can crash.I'm adding notes in my plugin and as I wrote they are now shown ok. But if I delete all the added notes (in the UI) they are not replaced by rests, as when the score is healthy. Even if I don't remove them the state is not good. I'm just notifying, it's not an issue for me, but perhaps interesting to know.
In reply to You could try surrounding… by PaulSC
You are a genius!
I was struggling for one hour with this same problem.
Annotations where not refreshed when button onClicked: changeScore() , whereas they did refresh if the same changeScore() is called from "onRun:".
Your suggestion fixed it !
P.S.: I found your answer when searching for "musescore onClicked", which was only after 100 other search attempts... Sometimes hunting for an answer needs perseverance!