This repository was archived by the owner on Mar 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidiFiles.js
84 lines (82 loc) · 1.62 KB
/
midiFiles.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
var fs = require("fs");
var midi = require("midi-node");
var files = [
{
name: "Super Mario Brothers",
path: "smb.mid",
track: 1
},
{
name: "Super Mario Brothers with BPM",
path: "supermario.mid",
track: 0
},
{
name: "Back to the Future",
path: "future-mod2.mid",
track: 0
},
{
name: "Star Wars - Empire",
path: "empire-mod.mid",
track: 0
},
{
name: "Indiana Jones",
path: "indy-mod.mid",
track: 0
},
{
name: "Top Gun",
path: "topgun-mod.mid",
track: 0
},
// {
// name: "Maple Leaf",
// path: "maple_m.mid",
// track: 1
// }
// {
// name: "Ghostbusters",
// path: "gbusters-mod.mid",
// track: 0
// }
// {
// name: "Star Wars",
// path: "starwars-mod.mid",
// track: 1
// },
// {
// name: "Cantina",
// path: "cantina-mod.mid",
// track: 1
// }
];
module.exports = {
allNames: function () {
return files.map(file => file.name);
},
byName: function (name) {
return new Promise(function (resolve, reject) {
for (let file of files) {
if (file.name === name) {
fs.readFile("./Resources/" + file.path, function (error, data) {
if (error) {
reject(error);
} else {
var obj = {
sequence: midi.Sequence.fromBuffer(data),
name: name,
track: file.track
};
resolve(obj);
}
});
return;
}
}
console.warn("Requested midi file that does not exist: " + name);
reject(new Error("File not found"));
});
}
};