Skip to content

Instantly share code, notes, and snippets.

@fronterior
Created September 9, 2021 14:18
Show Gist options
  • Save fronterior/f5aa29e0698d4f7f526639936951c32c to your computer and use it in GitHub Desktop.
Save fronterior/f5aa29e0698d4f7f526639936951c32c to your computer and use it in GitHub Desktop.
// Focusrite-Novation Launchpad Mini
const midiDeviceMap = {};
const midi = await navigator.requestMIDIAccess();
midi.inputs.forEach(entry => {
const key = entry.manufacturer+entry.name+entry.version;
if (!midiDeviceMap[key]) midiDeviceMap[key] = {};
midiDeviceMap[key].input = entry;
});
midi.outputs.forEach(entry => {
const key = entry.manufacturer+entry.name+entry.version;
if (!midiDeviceMap[key]) midiDeviceMap[key] = {};
midiDeviceMap[key].output = entry;
});
for (const key in midiDeviceMap) {
const {input, output} = midiDeviceMap[key];
input.onmidimessage = ({data}) => {
const [chn, pos, vel] = data;
output.send([chn, pos, vel ? Math.floor(Math.random() * 127) + 1 : 0]);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment