How to use the "conversion job" command-line option

• Oct 8, 2018 - 15:34

I figured out how to use the command-line option for converting a bunch of files all at once. The command-line is:

mscore [options] [filename] (Mac and Linux)
MuseScore.exe [options] [filename] (Windows)

the "conversion job" option is -j or --job and it takes a json formatted file. So, the command line on the Mac is:

/Applications/MuseScore\ 2.app/Contents//MacOS/mscore -j conversion-job.json

Here's an example of the conversion-job.json file to convert from "mscz" to "mscx" (useful for searching through a bunch of files for text entries since the mscx format contains uncompressed text):

[
{ "in":"Bagopolier_Freylekhs.mscz","out":"../xmlScores/Bagopolier_Freylekhs.mscx"},
{ "in":"Beckerman_No.14.mscz","out":"../xmlScores/Beckerman_No.14.mscx"},
{ "in":"Beckerman_No.5.mscz","out":"../xmlScores/Beckerman_No.5.mscx"},
{ "in":"Beckerman_No.6.mscz","out":"../xmlScores/Beckerman_No.6.mscx"},
{ "in":"Beckerman_No._1.mscz","out":"../xmlScores/Beckerman_No._1.mscx"}
]

Note that the last entry does not have a comma. The output file extension determines what type of conversion musescore will produce. You can create many different formats using this technique.

Enjoy!


Comments

In reply to by mirabilos

Oh fuuuuuck, -P also appends parts for scores that have no parts. Autogenerated parts, one for each instrument.

This just cost me over an hour of my night to make my scripts adapt. I now unzip the META-INF/container.xml, look for the .mscx name in the .mscz file, extract that, grep for the «lid» tag’s presence (the “best” way I could find to easily identify a score with parts, nested «Score» tags are more proper but much harder to do in shell), collect them in multiple distinct JSON files (one for mscore2 without parts, one for mscore2 with parts, one for mscore3 without… you get the idea) and run multiple -j and -P -j invocations.

In reply to by mirabilos

Looking at the source code, there’s no programmatical way at all to get at the individual parts from the command line: MuseScore::exportParts() in mscore/file.cpp is a GUI operation (not split into GUI and under-the-hood parts, and with some ugly duplication even) and not exposed via the CLI.

The PDF also does not include any indication where a part begins (e.g. as metadata). Its title does reflect that it’s “partitura and excerpts”, but that’s all.

Looking at the source code, there’s more.

You already found out that it must be a JSONArray of JSONObjects. All of the JSONObjects must have an in key, and they may have an out key. What’s new, they also may have a plugin key. The values of these keys are stringified (so probably should be JSONStrings in the first place) and passed to the conversion function.

Either out or plugin must be given, although both may be given. (The -S option may also be used in conjunction with this and is honoured.) If a plugin is given, it’s loaded (by filename, must end with .qml, is relative to the global or per-user plugin directory) and triggered (run). Then, if out is given, the score is saved/exported.

Known file types for saving/exporting are:

  • mscx, mscz
  • xml, musicxml, mxl
  • mid
  • pdf (does and auto-creates parts with -P)
  • png (does and auto-creates parts with -P)
  • svg
  • wav (RIFF WAVEfmt), ogg (Vorbis), flac, mp3
  • spos (segment), mpos (measure)
  • mlog (sanityCheck?!)

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