Skip to content

Commit

Permalink
Added script
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Nov 19, 2024
1 parent 018e1fd commit 817155c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
7 changes: 2 additions & 5 deletions test-scripts/mxl2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ catch (e) {
}

(async function() {
try {
data = await MXML.unzip(data);
}
catch (e) {
data = await MXML.unzip(data);
if (!data) {
console.error('Cannot uncompress file:', input);
console.error(e.message);
process.exit(1);
}
try {
Expand Down
43 changes: 43 additions & 0 deletions test-scripts/xml2midi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
const fs = require('fs');
const MXML = require('../jazz-mxml');

if (process.argv.length < 3) {
console.log('Usage: ' + process.argv[1].split(/[\\/]/).slice(-1) + ' <input> [<output>]');
process.exit(0);
}

const input = process.argv[2];
const output = process.argv[3];

var data;
try {
data = fs.readFileSync(input);
}
catch (e) {
console.error('Cannot read file:', input);
console.error(e.message);
process.exit(1);
}

(async function() {
var xml = new MXML(MXML.zipInfo(data) ? await MXML.unzip(data) : new TextDecoder().decode(data));
if (!xml.isPartwise() && !xml.isTimewise()) {
console.error('Not a valid MusicXML file:', input);
process.exit(1);
}
data = xml.midi();
if (!data) {
console.error('Cannot generate MIDI');
process.exit(1);
}
try {
if (output) fs.writeFileSync(output, data.dump());
else console.log(data.toString());
}
catch (e) {
console.error('Cannot write file:', output);
console.error(e.message);
process.exit(1);
}
})();
7 changes: 2 additions & 5 deletions test-scripts/xml2mxl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ if (!xml.isPartwise() && !xml.isTimewise() && !xml.isOpus()) {
}

(async function() {
try {
data = await MXML.zip(new TextEncoder().encode(data));
}
catch (e) {
data = await MXML.zip(new TextEncoder().encode(data));
if (!data) {
console.error('Cannot uncompress file:', input);
console.error(e.message);
process.exit(1);
}
try {
Expand Down

0 comments on commit 817155c

Please sign in to comment.