Skip to content

Instantly share code, notes, and snippets.

@prusnak
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prusnak/b5e97d546ad3ae51c401 to your computer and use it in GitHub Desktop.
Save prusnak/b5e97d546ad3ae51c401 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>WebMIDI Demo</title>
</head>
<body>
<textarea id="out" cols="120" rows="40"></textarea>
<script type="text/javascript">
function write(text) {
var out = document.getElementById('out');
out.value += text + '\n';
out.scrollTop = out.scrollHeight;
}
function msg(event) {
// meaning of 3 bytes: http://www.indiana.edu/~emusic/etext/MIDI/chapter3_MIDI4.shtml
write(event.receivedTime + " " + event.data[0] + " " + event.data[1] + " " + event.data[2]);
}
navigator.requestMIDIAccess().then(
function(access) {
var inputs = access.inputs();
if (inputs.length < 1) {
console.log('no midi inputs found');
return;
}
var input = inputs[0];
input.onmidimessage = msg;
console.log('ready', input);
},
function() {
console.log('error');
}
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment