Skip to content

Instantly share code, notes, and snippets.

@MAKIO135
Created September 18, 2018 05:58
Show Gist options
  • Save MAKIO135/e49ac19b64d799fb07e574078aef910c to your computer and use it in GitHub Desktop.
Save MAKIO135/e49ac19b64d799fb07e574078aef910c to your computer and use it in GitHub Desktop.
webMIDI
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Hello WebMIDI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script>
navigator.requestMIDIAccess()
.then(onMIDISuccess, onMIDIFailure);
function onMIDISuccess(midiAccess) {
for (var input of midiAccess.inputs.values()){
input.onmidimessage = getMIDIMessage;
}
}
function getMIDIMessage(midiMessage) {
var command = midiMessage.data[0];
var note = midiMessage.data[1];
var velocity = (midiMessage.data.length > 2) ? midiMessage.data[2] : 0;
console.log({command,note,velocity});
}
function onMIDIFailure() {
console.log('Could not access your MIDI devices.');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment