Command-line tool concatenate MuseScore XML files (akin to UNIX cat behavior) or split MuseScore XML files on a finer staff-level basis (such as solely the upper staff on a two-staff piano part).
usage: mxcat.py [-h] [--output output] [--staff staves] [--count] [--debug]
files [files ...]
- Merging was removed in MuseScore 3 because it was unstable, and there have been no successful attempts to revive it (thread 1, thread 2, thread 3, and so on... lead to dead ends).
- Generating files is limited to individual parts in MuseScore, but
mxcatis powerful enough to select staffs for each file. For instance, you could export the first 4 staves (such as the brass) into a file, and the remaining 12 staves (such as the woodwinds) into another file. This isn't supported by MuseScore! - Finally,
mxcatis a command-line tool, so it can be used for batch processing for many files. Apart from file conversion, most of MuseScore's features are limited to GUI.
- In general, mxcat will concatentate Musescore XML files and print on the standard output;
mxcatbehaves similarly to UNIXcat, where you may redirect output to another file. You can pipe to cat if you want access tocat-like options (such as -n, -v, and so on) - Keep in mind that parsing multiple large mscx files will certainly take some time.
mxcatdoes not (yet) have functionality to connect slurs and ties over different scores. If staff count is not constant over all files, you may find unexpected concatenation due to ambiguity while merging. Staves will be printed in order of increasing number.
Concatenate file1.mscx, and file2.mscx, and redirect output to result.mscx:
python mxcat.py file1.mscx file2.mscx > result.mscxConcatenate several files, but only keep the first 2 staves. Then redirect the output into result.mscx.
python mxcat.py file*.mscx --staff 1,2 > result.mscxSplit hamilton.mscx into three parts: staves 1 and 2, then staves 3 and 4, then staves 15 and 16. Finally, save the output into result_1,2.mscx, result_3,4.mscx, and result_15,16.mscx.
python mxcat.py hamilton.mscx --staff 1,2:3,4:15,16 --output result.mscxCount the number of staves in hamilton.mscx:
python mxcat.py hamilton.mscx --countSearch debug comments:
python mxcat.py out*.mscx --debug | grep "\[DEBUG\]"View help message:
python mxcat.py -h | less Numbered lines:
python mxcat.py file*.mscx | cat -n | less -Susage: mxcat.py [-h] [--output output] [--staff staves] [--count] [--debug]
files [files ...]
Concatenate Musescore XML files and print on the standard output; mxcat
behaves similarly to UNIX cat, where you may redirect output to another file.
You can pipe to cat if you want access to cat-like options (such as -n, -v,
and so on)
positional arguments:
files Files to concatenate.
optional arguments:
-h, --help show this help message and exit
--output output File to write to. Exists for cross-compatability and
multiple output. You can also use UNIX redirection >
output.mscx, instead of this argument.
--staff staves Colon and comma-separated staff-numbers to print across
multiple files, for instance --staff 0:1,2,3,4:5,6 will
create three files where the first file prints all parts,
the second file prints staves 1, 2, 3, and 4, while the
third file prints staves 5 and 6. The staff 0 indicates to
mxcat that it will print all parts. To save files, also
ensure that --output is set to a value. **Colon-separated
file output is experimental.** If multiple files are given,
mxcat will merge the files before printing.
--count Print number of staffs in the score, and exit. If multiple
files are given, only the first file will be parsed.
--debug Print debug comments into output, which is grep-able with
[DEBUG].
- Why am I getting
BrokenPipeError: [Errno 32] Broken pipewhen piping the output?- This could happen if you are redirecting the standard output to something like
less, but then you exitlesswithout reading everything fromless's input (that is, you exitlesswithout scrolling all the way down). - As a result, Python will exit with the aforementioned
BrokenPipeErrorbecause the pipe was closed before the script's output was completely written. This is natural behavior. - If this is annoying, for small files, you can try letting
cathandle it instead:
python3 mxcat.py file.mscx | cat | less- Alternatively, a more robust approach would be to redirect the output to a different file:
python3 mxcat.py file.mscx > output.tmp && less output.tmp && rm -rvf output.tmp - This could happen if you are redirecting the standard output to something like
