Last active
December 13, 2017 01:08
-
-
Save hoqqanen/074794b87e3a8e16f175f5359870c76f to your computer and use it in GitHub Desktop.
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
// Binds events from the first midi device | |
function bindMidiHandler(myMIDIMessagehandler){ | |
var m = null; // m = MIDIAccess object for you to make calls on | |
function onsuccesscallback( access ) { | |
m = access; | |
// Things you can do with the MIDIAccess object: | |
var inputs = m.inputs; // inputs = MIDIInputMaps, you can retrieve the inputs with iterators | |
var outputs = m.outputs; // outputs = MIDIOutputMaps, you can retrieve the outputs with iterators | |
var iteratorInputs = inputs.values() // returns an iterator that loops over all inputs | |
var input = iteratorInputs.next().value // get the first input | |
if (input) { | |
input.onmidimessage = myMIDIMessagehandler; | |
} | |
}; | |
function onerrorcallback( err ) { | |
console.log( "uh-oh! Something went wrong! Error code: " + err.code ); | |
} | |
navigator.requestMIDIAccess().then( onsuccesscallback, onerrorcallback ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment