Skip to content

Instantly share code, notes, and snippets.

@NHQ

NHQ/index.js Secret

Created March 9, 2015 14:56
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 NHQ/f650f7b61e8335f87a47 to your computer and use it in GitHub Desktop.
Save NHQ/f650f7b61e8335f87a47 to your computer and use it in GitHub Desktop.
web midi, if it ever works
midi = null
port = null
getMidi(function(e, m){
midi = m
console.log(midi)
var iter = midi.inputs.values()
port = iter.next()
console.log(port)
port.value.onmidimessage = function(e,d){
console.log(e, d)
}
})
function getMidi(cb){
if (midi){
process.nextTick(function(){
cb(null, midi)
})
} else if (window.navigator.requestMIDIAccess) {
window.navigator.requestMIDIAccess().then(function(res){
midi = res
cb(null, midi)
}, cb)
} else {
process.nextTick(function(){
cb('Web MIDI API not available')
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment