Created
January 3, 2019 17:17
-
-
Save vabarbosa/42a50a2d95aaf319dcbf7bf19fd78d2e 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
let midiOutputs | |
let midiInputs | |
// check MIDI support/availability | |
if (navigator.requestMIDIAccess) { | |
navigator.requestMIDIAccess().then(function (access) { | |
// get output devices | |
midiOutputs = Array.from(access.outputs.values()) | |
// get input devices | |
midiInputs = Array.from(access.inputs.values()) | |
midiInputs.forEach(m => { | |
// incoming MIDI message listener | |
m.value.onmidimessage = messageRcvd | |
}) | |
}) | |
} | |
// handle received MIDI message | |
function messageRcvd (message) { | |
let command = message.data[0] | |
let note = message.data[1] | |
let velocity = message.data[2] | |
// MIDI message received, do something | |
} | |
// send a MIDI message | |
function messageSend (command, note, velocity) { | |
midiOutputs.forEach(m => { | |
m.send([command, note, velocity]) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment