Last active
August 29, 2015 14:06
-
-
Save prusnak/b5e97d546ad3ae51c401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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