-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (67 loc) · 2.48 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
75
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- polyfill -->
<script src="./inc/shim/Base64.js" type="text/javascript"></script>
<script src="./inc/shim/Base64binary.js" type="text/javascript"></script>
<script src="./inc/shim/WebAudioAPI.js" type="text/javascript"></script>
<!-- midi.js package -->
<script src="./js/midi/audioDetect.js" type="text/javascript"></script>
<script src="./js/midi/gm.js" type="text/javascript"></script>
<script src="./js/midi/loader.js" type="text/javascript"></script>
<script src="./js/midi/plugin.audiotag.js" type="text/javascript"></script>
<script src="./js/midi/plugin.webaudio.js" type="text/javascript"></script>
<script src="./js/midi/plugin.webmidi.js" type="text/javascript"></script>
<!-- utils -->
<script src="./js/util/dom_request_xhr.js" type="text/javascript"></script>
<script src="./js/util/dom_request_script.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
function volpiano2midi(input_str, note_dur) {
//construct dictionary with pitch values
var pitch_dict = {};
pitch_dict['9'] = 43;
pitch_dict['a'] = 45;
pitch_dict['b'] = 47;
pitch_dict['c'] = 48;
pitch_dict['d'] = 50;
pitch_dict['e'] = 52;
pitch_dict['f'] = 53;
pitch_dict['g'] = 55;
pitch_dict['h'] = 57;
pitch_dict['j'] = 59;
pitch_dict['k'] = 60;
pitch_dict['l'] = 62;
pitch_dict['m'] = 64;
pitch_dict['n'] = 65;
pitch_dict['o'] = 67;
pitch_dict['p'] = 69;
pitch_dict['q'] = 71;
pitch_dict['r'] = 72;
pitch_dict['s'] = 74;
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "vowels",
onprogress: function(state, progress) {
console.log(state, progress);
},
onsuccess: function() {
MIDI.setVolume(0, 127);
//iterate through each character, check if in dictionary, play the corresponding pitch
for (var i = 0; i < input_str.length; i++) {
if (input_str.charAt(i) in pitch_dict){
MIDI.programChange(0, i%5);
MIDI.noteOn(0, pitch_dict[input_str.charAt(i)], 127, note_dur*i);
MIDI.noteOff(0, pitch_dict[input_str.charAt(i)], note_dur*(i+1));
}
}
}
});
};
</script>
<p>Volpiano snippet: <input type="text" id="myText" value="Paste Volpiano here..."></p>
<p>Tempo: <input type="range" min="20" max="160" value="90" class="slider" id="myRange"></p>
<button onclick="volpiano2midi(document.getElementById('myText').value, 60.0/document.getElementById('myRange').value);">Play</button>
</body>
</html>