-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.html
58 lines (57 loc) · 1.78 KB
/
index.html
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
<html>
<script src="https://cdn.jsdelivr.net/combine/npm/jszip@3.1.5/dist/jszip.min.js,npm/@elastic/filesaver@1.1.2"></script>
<script>
// polyfill for older browsers
if (!Object.keys) Object.keys = function(o) {
if (o !== Object(o))
throw new TypeError('Object.keys called on a non-object');
var k = [],
p;
for (p in o)
if (Object.prototype.hasOwnProperty.call(o, p)) k.push(p);
return k;
}
</script>
<script>
/*global saveAs */
/*global JSZip */
var zip = new JSZip();
function convert2Midi() {
var files = document.getElementById('files').files;
if (files) {
for (var i = 0, f; f = files[i]; i++) {
var r = new FileReader();
r.onload = (function(f) {
return function(e) {
var view = new DataView(e.target.result);
var length = view.byteLength,
offset = 4,
startpos = 0,
endpos = length;
while (offset < length - 4) {
var marker = view.getUint32(offset, false);
if (marker == 0x4D546864) {
startpos = offset;
}
if (startpos > 0 && marker >= 0x43485300 && marker < 0x43485400) {
endpos = offset;
}
offset += 1;
}
zip.file(f.name.substr(0, f.name.lastIndexOf(".")) + ".mid", f.slice(startpos, endpos + 3), { binary: true });
zip.generateAsync({ type: "blob" }).then(function(blob) {
saveAs(blob, "MIDI.zip");
});
};
})(f);
r.readAsArrayBuffer(f);
}
}
else {
alert("Failed to load files");
}
}
</script>
<input type="file" id="files" name="files" multiple="multiple"/>
<button onclick="convert2Midi()">Convert</button>
</html>