forked from mudcube/MIDI.js
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBasic.html
33 lines (32 loc) · 953 Bytes
/
Basic.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Play one note.</title>
</head>
<body>
<script type="text/javascript">
function load_and_play() {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "acoustic_grand_piano",
onprogress: function(state, progress) {
console.log(state, progress);
},
onsuccess: function() {
var delay = 0; // play one note every quarter second
var note = 50; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 0.75);
}
});
};
</script>
<button onclick="load_and_play()">Click Me to play a note!</button>
<p>You might need to click a few times to disable browser anti-audio protection</p>
<script src="../build/midicube.js"></script>
</body>
</html>