Plugin works in Musescore GUI, but not on command line
Can anyone explain what I'm doing wrong here ? The plugin shown below works fine when I run it in Plugin Creator, but when run on the command line I get a pop-up: "Invalid Command, Command select-all not valid in current state", then ""Invalid Command, Command transpose-down not valid in current state". It returns a pdf of the input file unmodified. I am using v3.6.2 on Windows 10.
"C:\Program Files\MuseScore 3\bin\MuseScore3.exe" R27_TEST.mscx -p transpose_test.qml -o R27_TEST_DOWN.pdf
transpose_test.qml
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
onRun:{
cmd("select-all");
cmd("transpose-down");
Qt.quit();
} }
I also tried v4.0.2; it first popped up the error "MuseScore4: Unknown option 'p'".
--plugin transpose_test.qml avoided the error messages, also returned the pdf unmodified. Many thanks for any assistance !
Comments
That plugin won't work in Mu4 anyway, due to the Qt.quit() it'd crash Mu4.
Andother issue with Mu4 is that the command line interface is pretty broken (it is in the works for 4.1)
Try
"C:\Program Files\MuseScore 3\bin\MuseScore3.exe" -p transpose_test.qml -o R27_TEST_DOWN.pdf R27_TEST.mscx
i.e. putting the source file last
In reply to That plugin won't work in… by Jojo-Schmitz
Thanks, but behaves exactly the same.
In reply to Thanks, but behaves exactly… by BanjoJake
Does
"C:\Program Files\MuseScore 3\bin\MuseScore3.exe" -p transpose_test.qml R27_TEST.mscx
do something? Like opening and transposing that score?
In reply to Does "C:\Program Files… by Jojo-Schmitz
No. no error pop-ups, no change to R27_TEST.mscx, no new files appear in the folder.
EDIT: see also https://musescore.org/en/node/334669, i.e. sandwich cmd("select-all") between start & endCmd
Look at colornotes3.qml attached. For some reason you need this construction
if (fullScore) {
cmd("select-all")
curScore.startCmd()
}
[do something]
if (fullScore) {
curScore.endCmd()
cmd("escape")
}
In reply to Look at colornotes3.qml… by elsewhere
Thanks, but as a quick first test, I just tried invoking colornotes:
"C:\Program Files\MuseScore 3\bin\MuseScore3.exe" -p colornotes3_0.qml -o R27_TEST_DOWN.pdf R27_TEST.mscx
no error pop-ups, but PDF file is unchanged (all notes black).
It worked fine invoking it in the GUI, BTW
In reply to Look at colornotes3.qml… by elsewhere
that startCmd/endCmd is mandatory in Mu4, not in Mu3 though (but still good to have)
In reply to that startCmd/endCmd is… by Jojo-Schmitz
?? In “Plugin can set selection but does not see what’s in it” (https://musescore.org/en/node/334669)
Jeetee claimed the opposite: “You forgot to persist your score-changing action (the selection) by wrapping it between startCmd and endCmd.”
And that solved my problem…
In reply to ?? In “Plugin can set… by elsewhere
It doesn't harm for sure for Mu3 plugins, but as far as I'm aware it is mandatory only for Mu4, without those Mu4 plugins don't modify the score at all.
In reply to ?? In “Plugin can set… by elsewhere
Thanks, but I'm still stuck. So you've successfully run a plugin from the command line and saved the modified output ? Your own plugin or colornotes ? I would really appreciate any details you would care to provide. Thanks again !
In reply to Thanks, but I'm still stuck… by BanjoJake
No success. I tried a few things and always get: select-all and/or escape not valid in this state...
EDIT: but you could imitate a batch procedure using
curScore.startCmd();
cmd("next-score")
curScore.endCmd();
(at least in MU3.6). I have loaded 35 files and ran a plugin with next-score on them without problems. The only fun fact to know is: next-score goes back to the first score after processing the last. So you need some "dummy" first file to stop the iteration
EDIT2: Also have a look at https://musescore.org/en/node/336449
In reply to Thanks, but I'm still stuck… by BanjoJake
Try my https://musescore.org/en/project/batch-transpose
Brand new. May still be buggy
In reply to Try my https://musescore.org… by elsewhere
Works, except for key signature (as discussed off-line). Thanks again !
In reply to Works, thanks !! by BanjoJake
int keySignature is read only (Search keySignature at
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…), so I doubt it can be changed from within a plugin.
Simpler might be to change the key signature manually before you run the transpose plugin or have a test3.mscz output and change it afterwards. If you need a pdf output you would need an additional step (export as pdf)
In reply to int keySignature is read… by elsewhere
>> ... change the key signature manually ...
Thanks, but too many files to do. Trying to loop within MS for now ... musescore.org/en/node/336449 ...