Running plugins in converter mode.
I'm trying to get musescore to batch-transpose some sheet music (my use case is writing lead sheets - I'd like to write them in concert pitch, then transpose for Bb/Eb instruments in a script), but I'm having trouble getting the "transposer_0" script (found here: https://musescore.org/en/project/transposer) to run in converter mode, or at the command line in general.
Specifically, I'm copying the qml file to ~/MuseScore/Plugins
, then running the following command:
mscore3 Concert_Pitch.mscx -p transposer_0.qml -o B_flat.mscx
I am sure the plugin is being run, as various logging output is printed, but the output .mscx file is identical to the input file.
The command line output that I get is as follows:
Jack appears to be installed on this system, so we'll use it.
QApplication: invalid style override passed, ignoring it.
qml: Hello Transposer
qml: Score title: undefined
qml: Original key: undefined
qml: Transposed key: undefined
Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
convert to
For ease of reference, the entire qml script is as follows:
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.Transposer"
description: "Description goes here"
version: "1.0"
onRun: {
console.log("Hello Transposer")
console.log("Score title: " + curScore.title);
if (!curScore)
Qt.quit();
// transpose up a whole step for Bb instrument
// note: to get the key right, go up 3 half-steps and down 1
console.log("Original key: " + curScore.keysig);
for (var i = 3; i-- > 0; ) {
cmd("transpose-up");
}
cmd("transpose-down");
console.log("Transposed key: " + curScore.keysig);
// insert instrument name on first note
var cursor = curScore.newCursor();
cursor.staffIdx = 0;
cursor.voice = 0;
cursor.rewind(Cursor.SCORE_START);
var text = newElement(Element.INSTRUMENT_CHANGE);
text.autoplace = false;
text.placement = Placement.ABOVE;
text.text = "Bb Instrument";
text.fontSize = 18;
text.sizeSpatiumDependent = false;
cursor.add(text);
// offsets must be done AFTER adding
text.offsetX = -8;
text.offsetY = -8;
Qt.quit();
}
}
My assumption is that certain Qt elements are not initialised correctly when running from the command line, but I can't see why that would be a good design decision, so it seems like a bug. If anyone has any insight, or anything I could do that would fix the issue I'd appreciate the help.
Thanks!
Comments
So, on some experimentation, it seems that the error output was only for musescore 3.0.5. With the new beta (3.4.0), I get output that seems more reasonable:
However, on inspection,
Bb.mscx
is no different toConcert.mscx
. By that I mean runningdiff
shows no difference between the two files.EDIT:
Trying other output formats, exporting to PDF doesn't work either - it almost seems like the script is being run at the wrong time in the lifecycle of the command, so that it doesn't end up actually touching the score.
In reply to So, on some experimentation,… by harries.adam
Right! Solved (or at least, I know what's wrong with it, I think).
So: Musescore can run in one of two modes - GUI, or Non-GUI. When run in Non-GUI mode, the following logic is followed (essentially):
The issue with this is that in
plugin
mode, a file is loaded, and then modified. In converter mode, another file is then loaded, converted, and written out. Unfortunately, this means that the file loaded and processed by the plugin is entirely disregarded and another fresh file is loaded and converted.I'm going to try and fix this when I have some time, but that might take a while.
In reply to Right! Solved (or at least,… by harries.adam
Hmm, on closer inspection, when converting, we should also be running a plugin, but don't seem to be...
In reply to Hmm, on closer inspection,… by harries.adam
No, I was incorrect - we do run plugins when converting, but not the one specified at the command line! We run a blank-name plugin (which will obviously do nothing).
More problematically, we also don't properly append the score when converting, so that would seem to be the first port of call for a fix...
In reply to Right! Solved (or at least,… by harries.adam
So I've managed to fix this, and have a successful build of musescore that will correctly run plugins when converting. I'll open a PR when I get some time, but in the meantime if anyone stumbles across this topic and needs a similar fix, then this patch will give you what you need (albeit, in a rather hacky way):
In reply to So I've managed to fix this,… by harries.adam
That patch is certainly not ready for inclusion, but please submit a (clean) PR for this. Do not include revision.h (changes to it should get ignored, there's a hint about how to avoid that in the developers handbook, albeit pretty well hidden, see https://musescore.org/en/handbook/developers-handbook/finding-your-way-…).
I've reconstructed and attached your patch (your's had formatting issues here)...
In reply to That patch is certainly not… by Jojo-Schmitz
I'm not surprised - it was just the result of me hacking on it to try and get something actually working. I've never worked with the musescore source code before, so the patch is just the result of my frustration - not an attempt to creat something beautiful.
Would it be worth me expanding the scope of the PR to tran and encompass some cleanup to command line behaviour in general? It's quite shockingly bad right now, and some cleaner handling of the various options might be good.
In reply to I'm not surprised - it was… by harries.adam
No, different issue (if any at all), I don't see the command line behavior being bad), better create a clean PR for the plugin in converter mode problem and another for any other problem.
In reply to No, different issue (if any… by Jojo-Schmitz
The command-line behaviour is /complicated/, and somewhat confusing. It's not entirely clear which options work together, and which options should work together. For example, the code to run plugins doesn't actually save anything, so if it's run without anything else it does absolutely nothing. Similarly, the converterMode re-loads the input file from scratch, so ignores anything that the plugin mode does beforehand.
I could go on - I think this is either an issue with documentation or with the overall design (or lack thereof) of the command line interface. I'm minded to say it's the latter (and happy to design something new), but I'm not sure where to start discussing this with the community. Is there a good place for formal RFC-like discussions? Or should I open an issue or something?
In reply to The command-line behaviour… by harries.adam
A (new) forum topic would be better than an issue, although one should be made too, eventually.
Discussions can also be done on the developers' Telegram chat
In reply to A (new) forum topic would be… by Jojo-Schmitz
Will do!
OK, thanks for #299539: Plugins are not run correctly when running musescore in converter mode. ;-)
In reply to OK, thanks for #299539:… by Jojo-Schmitz
Cheers - I'll work on the PR a bit this week, and hopefully I can close the issue quickly :)
In reply to Cheers - I'll work on the PR… by harries.adam
PR now open - any feedback would be very welcome: https://github.com/musescore/MuseScore/pull/5609
Hi - So 3 years later, I still can't figure out how to get musescore to batch-transpose - did you ever solve the problem ? Thanks !
In reply to Hi - So 3 years later, I… by BanjoJake
It should have been fixed in 3.5 though
In reply to It should have been fixed in… by Jojo-Schmitz
Evidently not - running the example in his original post still fails. The output score has new text "Bb Instrument" but is otherwise identical to the input; it has not been transposed. Also the transpose commands cause the "not valid in current state" error pop-ups reported in my other post (musescore.org/en/comment/1190347). MS v3.6.2 on Windows 11. Thanks for any suggestions ...