Skip to content

Instantly share code, notes, and snippets.

@hoqqanen
Last active December 13, 2017 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoqqanen/074794b87e3a8e16f175f5359870c76f to your computer and use it in GitHub Desktop.
Save hoqqanen/074794b87e3a8e16f175f5359870c76f to your computer and use it in GitHub Desktop.
// 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