Plugin is not changing the score if Dialog is used

• Jan 2, 2019 - 21:11

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

You could try surrounding the call to score-processing with these commands:

curScore.startCmd();
// processScore();
curScore.endCmd();

(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 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 use curScore.startCmd(); at the start of the plugin. Thought that it wasn't necessary, I saw a warning in the log that startCmd() 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 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 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!

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