Export parts in any format (not PDF) using json batch converter

• Jun 16, 2020 - 08:52

I need to export every instrument in a separate file just like this ( https://i.imgur.com/XAhufdA.png ), but I have thousands of files to process, currently this can be done only with the GUI ( https://musescore.org/en/handbook/parts ) but there's no CLI option for that (only PDF), so I cannot start a batch process of any kind even programmatically.
I humbly request to allow the json batch converter to export parts in a format other than PDF, I spent the last two days testing every solution on the internet, including using programming packages such as music21, no other tool can do a clean job as MuseScore does, other tools will corrupt, miss, won't open or provide incorrect data for many files, it's incredibly frustating that the sad reality of musical file formats is that they are supposed to be standardized but in practice are not (ie. MuseScore can load but cannot save lyrics in a .MID file https://musescore.org/en/node/18874 , but for some reason other tools can and viceversa).

I'd be extremely grateful if you could implement this in MuseScore as currently there are no other reliable alternatives


Comments

In reply to by Jojo-Schmitz

Thanks for the answer, but I believe there's a misunderstanding.
Let's pretend "music.mid" contains 3 tracks/instruments, I don't want to convert "music.mid" into "music.musicxml", but into "music-piano.musicxml, music-violin.musicxml, music-flute.musicxml", one file per instrument and track automatically without manual retouching.
MuseScore can do it already from the GUI at "File" > "Parts" > "All Parts" > "OK" > "File" > "Export parts" and it will export each instrument individually to a separate files, one for every instrument, automatically.
I was looking to do the same from the CLI.

This problem was reported a year ago, can someone fix this please? It's frustrating that I cannot export parts (NOT in PDF format!) from the CLI directly, doesn't seem like rocket science as the GUI can already do it.
P.S: The new command line "--score-parts" seems to do nothing ( https://musescore.org/en/handbook/3/command-line-options ), I tried multiple files with MuseScore 3.6.2, can you show any example that works?

In reply to by AndroYD84

Following. I'm trying to do exactly the same thing. I have a collection of MuseScore projects that are being actively worked on with frequent revisions, and each time there's a change I need to export the parts as XML to be incorporated in another process. I haven't figured out yet how I'm going to extract parts from the amalgamated XML file, but at this point I'm guessing I will need to parse and manipulate the XML myself. After all, the XML I have is "part-wise" and already organized into elements. I was really hoping for an easier way.

In reply to by ian-ring

Followup to this. When MuseScore exports as XML from the CLI (using "mscore"), the resulting XML is "partwise", which means all the parts are separated, as opposed to "timewise" where each measure is defined with all the parts in each one. That makes things MUCH easier to extract parts. The XML contains a < part-list> element with < score-part> nodes, and then elsewhere there are < part> nodes with all the musical data in it. Yes it involved a little extra work than I hoped for, but it wasn't difficult to take those < part> nodes and put them into a new file.

Say you get the node from the XML, you can insert it into a template like this:

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
< score-partwise version="3.1">
< work>
< work-title> ... Put the title here ... < /work-title>
< /work>
< identification>
< creator type="composer"> ... Your Name ... < /creator>
< /identification>

< part-list>
< score-part id=" ... use the same ID as the part element below ... ">
< part-name>Tuned Beer Bottles< /part-name>
< part-abbreviation>Beer.< /part-abbreviation>
< /score-part>
< /part-list>

... put the < part> element here that you yoinked from the big XML file ...

< /score-partwise>

This worked for me, and now I have a script that will read directly from a saved MuseScore project, and generate Lilypond files for each of the orchestral parts. Woot

btw I had to put a space at the beginning of all those XML nodes because this forum does some weird formatting on anything that resembles HTML

Sorry for reviving an old thread, but I finally found a way to do this, although it's not using the batch export (still need to figure that thing out).

Here's the command I'm using:
mscore --score-parts-pdf $INPUT_FILE 2>/dev/null | jq -r '.partsBin[0]' | base64 --decode > $FILE_NAME-1-TRP.pdf

To explain it a bit:
$INPUT_FILE is a variable with my input score (mscz)
-- score-parts-pdf outputs a json to stdout with the parts of the score and some metadata
2>/dev/null is just to silence some Qt errors
jq is a command line utility to process / query json
.partsBin[0] is to use the first element of the partsBin array (so, the first part on your score, use other numbers for other parts
base64 --decode is used to decode the information to binary (for some reason, it's never said on the CLI help page that this info is base64 encoded)
$FILE_NAME is a variable I set with the output file name (basically, the input file name minus the file extension)
-1-TRP.pdf is the string I attach to the first part on the score (lead trumpet)

Obviously, we can make it so a single command exports all the parts to separate PDFs by looking at the meta data on the json and iterating over the array, but this can work as a starting point. Hope it helps!

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