-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters