My Plugins is not working on Musescore4 (especially "cmd()")

• Dec 13, 2024 - 08:00

I modified a plugin that I used without any issues in MuseScore 3 for MuseScore 4, but Cmd("next-measure") does not work.

The plugin appears in the menu of MuseScore 4, and I believe it is recognized as a plugin. Also, as far as I can see, Cmd("Copy"), Cmd("Paste"), Cmd("Transpose-up"), and Cmd("Transpose-down") all worked correctly.

It did not work in both MuseScore 4.4 and 4.3. Does this mean that MuseScore 4 does not support certain commands?

I have been using MuseScore for about 10 years and finally decided to try creating a plugin. I am a programming beginner and have just started learning Javascript, so if my code is incorrect, I would appreciate it if you could point it out! (I use a lot of transposition commands because I want to write the score in Bb) If I cannot resolve this issue, I plan to continue using MuseScore 3 for the time being.

Here is my environment: PC: MacBook Air (M1) OS: macOS 15.1

Attachment Size
test.qml 1.38 KB

Comments

The problem with the 'cmd()' function in Musescore 4 is quite strange, and is probably related to the relationship between the two windows (the plugin one and the software one), that is, who has the 'focus'. Similarly, the same problem exists with keyboard shortcuts that may be included in a plugin. In fact, in a non-visual plugin 'cmd()' placed in onRun:{} works perfectly.

However, there are several ways to make this work in a visual plugin. Let's imagine we have a simple plugin that uses a 'button' to do the following:

onClicked :
{
doThis();
doThat();
.....all the operations to be carried out, even with the 'cmd()' function
}

modified like this it works perfectly:

onClicked :
{
quit();
doThis();
doThat();
.....all the operations to be carried out, even with the 'cmd()' function
}

Closing the plugin window allows the 'cmd()' function to be applied. Of course, this is a workaround, and everyone can decide whether to adopt it or not.
The price to pay is the plugin's closure, which is not always desirable...but it's better than nothing.

Another way is to create a plugin...to launch the actual plugin!
It's a little more complicated, but not that much. It's about making a window appear that has a single button with the task of launching the plugin:

onClicked :
{
myMainWindow.showNormal();
quit();
}

.........below, the entire plugin

The window is now the one created by you and not by the plugin.
Magically, the 'cmd()' function starts working again.

In reply to by ILPEPITO

Last addition: you don't actually even need (unless you want to create a 'launcher' for multiple plugins) to insert a 'button'. Just insert the lines:

myMainWindow.showNormal();
quit();

in onRun:{}.

and delete 'pluginType' from the initial declaration. The plugin will be started directly with your window.

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