-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnode-vst-host.js
117 lines (88 loc) · 3.06 KB
/
node-vst-host.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//////////////////////////////////////////////////////////////////////////
// node-vst-host - main module
//////////////////////////////////////////////////////////////////////////
//
// Main javascript API
/* ----------------------------------------------------------------------
Object Structures
-------------------------------------------------------------------------
*/
//////////////////////////////////////////////////////////////////////////
// Namespace (lol)
var SHOW_DEBUG_PRINTS = true;
var log = function(a) { if(SHOW_DEBUG_PRINTS) console.log(a); }; // A log function we can turn off
//////////////////////////////////////////////////////////////////////////
// Constructor
var NodeVSTHost = function() {
return this;
} // end NodeVSTHost();
//////////////////////////////////////////////////////////////////////////
// Process some audio with some plugins
NodeVSTHost.prototype.processAudio = function( inputFile, outputFile, pluginNames ) {
// MrsWatson wants our plugin names in a more compact string
var strPluginNames = "";
for( iPlugin in pluginNames ) {
strPluginNames += pluginNames[iPlugin];
if( iPlugin != pluginNames.length - 1 )
strPluginNames += ";";
}
commandArgs = [
"--input", inputFile,
"--output", outputFile,
"--plugin", strPluginNames
];
console.log( commandArgs );
runWatsonCommand( commandArgs, function(results) {
console.log( results );
});
} // end NodeVSTHost.processAudio()
//////////////////////////////////////////////////////////////////////////
// List available plugins
NodeVSTHost.prototype.listPlugins = function( callback ) {
arguments = [
"--list-plugins"
];
runWatsonCommand( arguments, function(results) {
var lines = results.match(/[^\r\n]+/g),
pluginNames = [],
locations = [];
// Remove the characters that aren't part of the name
for( var iLine in lines ) {
var thisLine = lines[iLine];
// If this is just a line telling us that we don't have any
// plugins here, skip it
if( thisLine.indexOf("(Empty or non") != -1 || thisLine.indexOf("(No plugins found") != -1 ) {
continue;
}
if( thisLine.indexOf("Location '") != -1 ) {
locations.push( thisLine.substr(thisLine.indexOf("Location")) );
continue;
}
// If we've gotten this far, this is a plugin name
// Remove the junk that's there to make the prompt look good
pluginNames.push( thisLine.substr(20) );
}
callback( pluginNames );
});
} // end NodeVSTHost.processAudio()
function runCommand( command, args, end ) {
var commandContext = this,
data = "";
var spawn = require('child_process').spawn,
child = spawn( command, args );
child.stderr.on( 'data', function( buffer ) {
data += buffer.toString();
});
child.stderr.on( 'end', function() {
end( data );
});
}
function runWatsonCommand( arguments, onFinished ) {
var cmdPath = __dirname + "/MrsWatson/bin/" + process.platform + "/mrswatson.exe";
var foo = new runCommand(
cmdPath,
arguments,
onFinished || function( data ) {}
);
}
exports.host = NodeVSTHost;