Skip to content

Instantly share code, notes, and snippets.

@lukewestby
Created October 11, 2015 20:40
Show Gist options
  • Save lukewestby/21ec4489e6ab0e51f5b3 to your computer and use it in GitHub Desktop.
Save lukewestby/21ec4489e6ab0e51f5b3 to your computer and use it in GitHub Desktop.
Get MIDI input and output devices from the Web MIDI API by name
function findMidiDevices(name) {
return navigator
.requestMIDIAccess()
.then((midiAccess) => {
let input, output;
midiAccess.inputs.forEach((currentInput) => {
if(currentInput.name === name) input = currentInput;
});
midiAccess.outputs.forEach((currentOutput) => {
if(currentOutput.name === name) output = currentOutput;
})
return { input, output };
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment