forked from andrewrk/waveform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1004 Bytes
/
index.js
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
var path = require('path');
var execFile = require('child_process').execFile;
var waveformBin = path.resolve(__dirname, "bin", "waveform");
var argNames = [ 'width', 'height', 'color-bg', 'color-center', 'color-outer' ];
var flagNames = [ 'scan' ];
module.exports = function(audiofile, pngfile, options, callback) {
var cmdline = [audiofile, pngfile];
argNames.forEach(function(argName) {
if (options.hasOwnProperty(argName)) {
var value = options[argName];
cmdline.push('--' + argName);
cmdline.push(value);
}
});
flagNames.forEach(function(flagName) {
if (options[flagName]) {
cmdline.push('--' + flagName);
}
});
execFile(waveformBin, cmdline, function(err, stdout, stderr) {
var myErr;
if (err) {
myErr = new Error("waveform binary returned error");
myErr.stdout = stdout;
myErr.stderr = stderr;
myErr.internal = err;
callback(myErr);
} else {
callback();
}
});
};