A plugin to transpose a score from the command line

• Nov 17, 2011 - 09:27

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...

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 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 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 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 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 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.

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