Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
$("#midi-ui-note").text(data[1]).show();
} else {
keys.splice(keys.indexOf(data[1]), 1);
if (keys.length === 0) $("#midi-ui-note").hide();
else $("#midi-ui-note").text(keys[keys.length - 1]);
}
}
};
if (id === "-2") {
key2Midi.handler = listener;
key2Midi.enabled = true;
return;
}
key2Midi.enabled = false;
if (id === "-1") return;
const input = webmidi.getInputById(id);
if (!input) return;
midiEnv.input = input;
input.addListener("midimessage", "all", e => listener(e.data));
});
// Append current connected devices
useEffect(() => {
const _onNoteStart = e => {
onNoteStart(e.note.number, e.velocity, true);
};
const _onNoteStop = e => {
onNoteStop(e.note.number, true);
};
if (!webMidi.supported) return;
const input = webMidi.getInputById(midiDevice);
if (input) {
input.addListener("noteon", "all", _onNoteStart);
input.addListener("noteoff", "all", _onNoteStop);
}
return () => {
if (input) {
input.removeListener("noteon", "all", _onNoteStart);
input.removeListener("noteoff", "all", _onNoteStop);
}
};
}, [midiDevice, onNoteStart, onNoteStop]);