-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (64 loc) · 1.99 KB
/
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
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
"use strict";
const exec = require('child_process').exec
var express = require('express');
var app = express();
var fileUpload = require('express-fileupload');
app.use(fileUpload());
app.post('/upload', function(req, res) {
var sampleFile;
if (!req.files) {
res.send('No files were uploaded.');
return;
}
sampleFile = req.files.sampleFile;
var midifile = './uploads/filename.midi';
sampleFile.mv(midifile, function(err) {
if (err) {
res.status(500).send(err);
}
else {
let child = exec('./midifile/bin/midi2text '+midifile, (err, stdout, stderr) => {
let notes = stdout.split('\n').map((note) => note.split('\t')).map(noteArray=>(
{
type: noteArray[0],
startTime: noteArray[1],
duration: noteArray[2],
noteNumber: noteArray[3],
velocity: noteArray[4],
}
))
res.json({status: 'OK', data: {notes}});
})
}
});
});
app.get('/upload', function(req, res) {
var html = `
<html>
<body>
<form ref='uploadForm'
id='uploadForm'
action='/upload'
method='post'
encType="multipart/form-data">
<input type="file" name="sampleFile" />
<input type='submit' value='Upload!' />
</form>
</body>
</html>
`;
res.send(html);
})
app.get('/', function (req, res) {
console.log("asd");
var midiFile = './uploads/beet1track-medium-fast.mid';
console.log(midiFile);
let child = exec('./midifile/bin/midi2text '+midiFile, (err, stdout, stderr) => {
// console.log('this is with bash',stdout, stderr)
let notes = stdout.split('\n').map((note) => note.split('\t'))
res.send(JSON.stringify(notes)+" "+JSON.stringify(err)+JSON.stringify(stderr));
})
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});