Spawning a Musescore process from Node JS fails - how to debug?

• Sep 15, 2021 - 09:14

I'm playing around with Musescore. Basically my goal is to write some code that will accept a full score in MusicXML format and output a separate MusicXML file plus an MP3 for each instrument in that score. There are various command line options that seem interesting, especially the batch job file format and the -j option. First I thought a job file like this would be all it took:

 [
{
    "in": "BALLADE Junior.musicxml",
    "out": [
        ["ballade-part", ".musicxml"],
        ["ballade-part", ".mp3"]
    ]
}
]

Unfortunately this seems not to work, I'm not sure if I fully understand why but I think Musescore's concept of a "part" is not applied when processing a MusicXML file with different "instruments".. or something like that? An extra step would be required to turn the "instruments" into "parts" and there's no command line argument for that?

Second try was a script passing the --score-parts command line argument - it will be more work but as long as I get the parts data I can likely write the remaining code to output MusicXML and MP3.

const { spawn } = require('child_process');
const MSCORE = 'MuseScore-3.6.2.548021370-x86_64.AppImage';
const msc = spawn(MSCORE, ['--score-parts', process.argv[2]]);
 
msc.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});
msc.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

Unfortunately this says child process exited with code 1. If I run the equivalent command from the command line it seems to work just fine. Is there a good way to see more details or debug why it would fail when spawned from Node? Or maybe someone knows a secret to make the jobfile variant work? :)

Thanks in advance!


Comments

You are certainly correct that an instrument is not a part - parts need to be generated via File / Parts. Msot likely that could be automated with a plugin, and in theory it's possible to force MuseScore to execute a plugin, but I understand there might be issues in practice, so a command script is probably better. not sure how well that interface is documented though.

Realistically, the whole project would probably be easier done as a plugin run from within MuseScore.

In reply to by Marc Sabatella

Thanks a lot for answering :) The aim is running this on a server, likely in Docker, is running a plugin inside it feasible in such a scenario? Running --score-parts seems to give me JSON data with the different instruments split into mscz files though, so if I can figure out why it crashes I can probably take things from there.

Spontaneously, dockers are run with quite few resources (cpu/mem) perhaps raise those?

If Musescore gracefully exits with code 1, it probably doesn't crashes, and the reason could be printed on standard error.
If you can do something similar for stderr, as you do here for stdout:
msc.stdout.on('data', (data) => {
console.log(stdout: ${data});
});

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