Created
September 18, 2018 05:58
-
-
Save MAKIO135/e49ac19b64d799fb07e574078aef910c to your computer and use it in GitHub Desktop.
webMIDI
This file contains 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
<!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