A plugin to transpose a score from the command line
Hello alltogether!
I have searched for a possibility to transpose a score from the command line, but have had no luck.
What I want to do is to maintain jazz lead sheets mainly for C, Bb and Eb automatically with a make file, something like this Makefile snippet:
Bb/%_Bb.mscz: %.mscz
-TAB- mscore -p transpose -2 $<
Eb%_Eb.mscz: %.mscz
-TAB- mscore -p transpose +3 $<
For the curiosity: I play the alto flute myself and therefore also need to transpose to G.
Maybe it would be better to implement this as a regular command line option?? The advantage with a plugin, would be that one could change the title of the score to indicate that it is transposed for e.g. Bb instruments.
Now to the problem: I haven't found a method "transpose" that could be applied to a score. Is this found somewhere else? Also, how do I access cli parameters, as in this case -2 and +3? I do realize that the minus sign might be unsuitable, as it probably will be caught by the mscore program itself and never be passed to the script.
With a little bit of advice on these topics, I would probably be able to write the plugin myself. But if someone already has a solution, it would be great!
Thanks: Håkan
Comments
Doing this with a makefile has the problem that spaces in filenames don't work at all
I've been doing this to created pdf from mscz, but are now using the batch export plugin, which does a much better and easier job
So go for doing it in a plugin...
In reply to Doing this with a makefile by Jojo-Schmitz
Well, I do use the Makefile to export to .pdf too, but as I never use file names with spaces, it is not a problem for me:-)
In reply to Well, I do use the Makefile by hk_
You might like my Makefile then
I've thought of doing something like this, too, not as an automatic makefile type of thing but just for the current score. I ended up putting it off as there was no way way to get at the current score's filename, and because transposing from within the framework is not complete. It seems you can change individual pitches, but there is no way to get at the chordnames. Also, I would have wanted to do some enharmonic "correction" of the transposition using the TPC mechanism, but that didn't seem to work, and I gather there are significant changes to how that works in 2.0.
Since I've already gone ahead and implemented a makefile-like solution for the batch export plugin (in that it figures out what needs to be done and what doesn't for that purpose; it's not an actual "make" implementation), it does seem it would be pretty easy to adapt that plugin to do a transposition - *if* you could get the transposition to work.
I can think of any number of situations where getting at the chordnames would be useful, but I also recognize that figuring put a way to represent those chords, and a way of returning chords not attached to a note, would be challenges to overcome, and again, this all changes for 2.0. So while I'd still eventually love to get at those chordnames, a "transpose" method that would be attached to the score objector perhaps the cursor (to work on a range), might be simpler to actually implement in the framework as well as be simpler for plugins to use.
In reply to I've thought of doing by Marc Sabatella
Hi,
Resurecting this thread almost 6 years after.
Maybe there has been some work on this?
Is transposition possible from the command line ?
chri
In reply to Hi, Resurecting this thread by ProfGra
Nope, transposing is not exposed to plugins or the command line
In reply to Nope, transposing is not by Jojo-Schmitz
Well.. you might be able to currently transpose from within a plugin using the related shortcut-command-name for F2/Shift-F2 being
cmd("transpose-up")
andcmd("transpose-down")
respectively.In reply to Well.. you might be able to by jeetee
And it is possible to call those from within plugins?
The shortcut F2/Shift+F2 is gone in 2.1 BTW
In reply to And it is possible to call by Jojo-Schmitz
The following works in 2.0.3 and 2.1 (2017-04-12-1313-2.1-de38cce)
In reply to The following works in 2.0.3 by jeetee
Whoho, that is great! Opens a whole new area for plugins.
In reply to Whoho, that is great! Opens a by Jojo-Schmitz
like triplets and such..Now if only i can reliably check for existing triplets, I could have another look at the retrograde plugin.
In reply to The following works in 2.0.3 by jeetee
Hey!
This seems to be great news!
Except that I'm very new to hacking MuseScore. Could someone:
1) confirm that this is some QtScript?
2) explain the steps to be able to call mscore from the command line and tell it to transpose before exporting to pdf?
chri
In reply to Hey! This seems to be great by ProfGra
1. yes, save above file with a .qml extension
2. See https://musescore.org/en/handbook/command-line-options-0, esp. the -p and -o options
In reply to 1. yes, save above file with by Jojo-Schmitz
Thanks Jojo-Schmitz,
Go to step 3 for the working procedure.
1) I saved the code to transpose.qml, in the current dir.
2) I tried different things, with no luck:
mscore file.mscz -p transpose.qml -o file.pdf
-> produces a non transposed pdf
mscore file.mscz -p transpose.qml
-> does nothing
mscore file.mscz -p non_existing.qml
-> no error message
3) Then I saved the code to /usr/share/mscore-2.0/plugins/transpose.qml
mscore file.mscz -p transpose.qml -o file.pdf
-> works great !!!
And thanks everyone!
In reply to Thanks Jojo-Schmitz, Go to by ProfGra
Well, it seems to be a problem under musescore 3.0.2 and Linux:
The script seems to transpose ( I've added som extra log messages ).
It seems not to be able to return the result ( "but no receivers connected to handle it." ).
The conversion to .pdf works, but without being transposed.
Does anyone have an idea?? I would be very greatful.
Here's the output:
$ mscore MyTune.mscz -p transpose.qml -o MyTune.pdf
0x437f870 0-92160 Master systems 0
Collect meta for
qml: In onRun
Score::startCmd(): cmd already active
0x437f870 0-92160 Master systems 13
qml: After Transpose
0x437f870 0-92160 Master systems 13
qml: After Transpose
Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
qml: After Qt.quit
Score::endCmd(): no cmd active
convert to
In reply to Well, it seems to be a… by hk_
By the way, I found out that the proposed script works well, if I run it in the plugin creator. I also did not mention that I changed the second line to:
import MuseScore 3.0
Otherwise it does not work at all.
I have read that there was some problems with the new plugin interface in MuseScore 3.0, but that they should be gone in 3.0.2. Obviosly it is not the case for scripts started from the command line.
In reply to By the way, I found out that… by hk_
Any success in running this in MuseScore 4?
the cmd("transpose-down") command is processed by MuseScore (debug output is 16:24:09.550 | INFO | main_thread | ActionsDispatcher::dispatch | try call action: transpose-down
16:24:09.550 | DEBUG | main_thread | Score::endCmd | Undo stack current macro child count: 0
) but produces no effect whatsoever.
In reply to Any success in running this… by opinsky
And apparently the -p option to run a plugin from the command line is gone in MuseScore 4
In reply to And apparently the -p option… by opinsky
Oh boy, yet another feature lost in action. Added to the (rather long) list at https://musescore.org/en/node/334701#Plugin_commandline_option
In reply to Oh boy, yet another feature… by Jojo-Schmitz
:-( FYI, --plugin apparently works, but -p don't. Will create an issue on github.
In reply to And apparently the -p option… by opinsky
Feel free to report this on GitHub, https://github.com/musescore/MuseScore/issues/new/choose