-
Notifications
You must be signed in to change notification settings - Fork 89
/
index.html
74 lines (72 loc) · 2.03 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE HTML>
<html>
<head>
<script src="stream.js"></script>
<script src="midifile.js"></script>
<script src="replayer.js"></script>
<script src="synth.js"></script>
<script src="audio.js"></script>
<script>
function loadRemote(path, callback) {
var fetch = new XMLHttpRequest();
fetch.open('GET', path);
fetch.overrideMimeType("text/plain; charset=x-user-defined");
fetch.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
/* munge response into a binary string */
var t = this.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
ff[z] = scc(t.charCodeAt(z) & 255);
}
callback(ff.join(""));
}
}
fetch.send();
}
function play(file) {
loadRemote(file, function(data) {
midiFile = MidiFile(data);
synth = Synth(44100);
replayer = Replayer(midiFile, synth);
audio = AudioPlayer(replayer);
})
}
if(FileReader){
function cancelEvent(e){
e.stopPropagation();
e.preventDefault();
}
document.addEventListener('dragenter', cancelEvent, false);
document.addEventListener('dragover', cancelEvent, false);
document.addEventListener('drop', function(e){
cancelEvent(e);
for(var i=0;i<e.dataTransfer.files.length;++i){
var
file = e.dataTransfer.files[i]
;
if(file.type != 'audio/midi'){
continue;
}
var
reader = new FileReader()
;
reader.onload = function(e){
midiFile = MidiFile(e.target.result);
synth = Synth(44100);
replayer = Replayer(midiFile, synth);
audio = AudioPlayer(replayer);
};
reader.readAsBinaryString(file);
}
}, false);
}
</script>
</head>
<body>
<a href="javascript:void(play('minute_waltz.mid'))">Chopin - Waltz Op.61 (Minute Waltz)</a> |
<a href="javascript:void(play('rachmaninov3.mid'))">Rachmaninov - Piano Concerto No.3 (First movement)</a>
</body>
</html>