Function: useMIDIInput()
function useMIDIInput(midiAccess, handlers): void;
Defined in: react/src/hooks/useMIDIInput.ts:26
Handle MIDI input events. To be used with useMIDIAccess.
The handlers are read fresh on every event, so writing them inline is fine:
the listeners are attached once per midiAccess and stay attached. Devices
plugged in later are picked up without anything having to be rebuilt.
Parameters
| Parameter | Type |
|---|---|
midiAccess | MIDIAccess | null |
handlers | MIDIInputHandlers |
Returns
void
Example
const { midiAccess } = useMIDIAccess()
useMIDIInput(midiAccess, {
onNoteOnEvent: (note, velocity) => play(note, velocity / 127),
onNoteOffEvent: (note) => stop(note),
onControlChangeEvent: (controller, value) => {
if (controller === 1) setModulation(value / 127)
},
})