-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
61 lines (46 loc) · 1.44 KB
/
app.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
var express = require('express');
var spawn = require('child_process').spawn;
var app = express();
var config = require('./config/config.json');
var sampleMap = {
'single_sine': 'singleSine',
'linear_voice_music': '2',
'linear_voice_voice': '3',
'conv_voice_music': '8',
'conv_voice_voice': '5'
};
var scriptMap = {
'ica': config['octave_code_directory'] + '/separateUsingICA.m',
'svd': config['octave_code_directory'] + '/separateUsingSVD.m'
};
app.use(express.static('public'));
app.use(express.static(config['octave_code_directory'] + '/sound_files'));
app.get('/sanity', function (req, res) {
res.send('hello, world!');
});
app.get('/run/:algorithm/:sample', function (req, res) {
var algorithm = req.params.algorithm;
var sample = req.params.sample;
if (! (algorithm in scriptMap) || ! (sample in sampleMap)) {
res.status(404);
res.end('Not Found');
return;
}
console.log('Run: ' + algorithm.toUpperCase() + ', ' + sample);
var args = [
scriptMap[algorithm],
sampleMap[sample]
];
console.log(args);
cmd = spawn('octave', args);
cmd.stdout.on('data', function (data) {
console.log(data.toString());
});
cmd.stdout.on('close', function (code) {
console.log('Command exited with code: ' + String(code));
res.end(JSON.stringify({ 'status': 'OK', 'code': code }));
})
});
app.listen(3000, function () {
console.log('Started frontend server for cocktail party at port 3000');
});