-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsynth.js
More file actions
executable file
·59 lines (46 loc) · 1.25 KB
/
synth.js
File metadata and controls
executable file
·59 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const midiToWav = require('../src/midi2wav');
const getArgs = require('./utils/args');
try {
const args = getArgs(process.argv);
if (args.help || args.input === undefined) {
console.log(fs.readFileSync(`${__dirname}/../man/help.txt`, {encoding: 'utf8'}));
process.exit();
}
if (args.verbose) {
console.log(JSON.stringify(args, null, 2));
}
if (typeof args.input === 'string') {
fs.readFile(`${args.input}.mid`, {encoding: null}, (error, data) => {
if (error) {
throw error;
}
if (args.verbose) {
console.log('parsing MIDI...');
}
const wav = midiToWav(data, args);
if (args.DryRun) {
return console.log('dry run complete');
}
if (!wav) process.exit();
if (args.verbose) {
console.log('writing buffer...');
}
const buffer = wav.toBuffer();
fs.writeFile(`${args.output}.wav`, buffer, {encoding: null}, (error) => {
if (error) {
throw error;
}
if (args.verbose) {
console.log('success');
}
});
});
} else {
throw new ReferenceError('no input file specified');
}
} catch (error) {
console.log(error.stack);
}