forked from laetitia-teo/av-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi_test.html
35 lines (32 loc) · 919 Bytes
/
midi_test.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
<!DOCTYPE html>
<html>
<head>
<title>MIDI Input Example</title>
</head>
<body>
<h1>MIDI Input Example</h1>
<div id="log"></div>
<script>
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess()
.then(onMIDISuccess, onMIDIFailure);
} else {
alert("Web MIDI API is not supported in this browser.");
}
function onMIDISuccess(midiAccess) {
console.log("MIDI Access Granted");
for (var input of midiAccess.inputs.values()) {
input.onmidimessage = getMIDIMessage;
}
}
function onMIDIFailure() {
console.error("Could not access your MIDI devices.");
}
function getMIDIMessage(midiMessage) {
const [command, note, velocity] = midiMessage.data;
const log = document.getElementById('log');
log.innerHTML += `<p>Command: ${command}, Note: ${note}, Velocity: ${velocity}</p>`;
}
</script>
</body>
</html>