hooks/useMIDIInput
Type Aliases
MIDIInputHandlers
type MIDIInputHandlers = object;
Defined in: dom/dist/index.d.ts:169
Every handler is given the channel last, as 0-15. MIDI channels are written 1-16 on hardware, so add one before showing it to anyone.
Properties
onAftertouchEvent?
optional onAftertouchEvent?: (note, pressure, channel) => void;
Defined in: dom/dist/index.d.ts:183
Pressure for one held note (polyphonic aftertouch).
Parameters
| Parameter | Type |
|---|---|
note | number |
pressure | number |
channel | number |
Returns
void
onChannelPressureEvent?
optional onChannelPressureEvent?: (pressure, channel) => void;
Defined in: dom/dist/index.d.ts:185
Pressure for the whole channel, sent by keyboards with one sensor.
Parameters
| Parameter | Type |
|---|---|
pressure | number |
channel | number |
Returns
void
onControlChangeEvent?
optional onControlChangeEvent?: (controller, value, channel) => void;
Defined in: dom/dist/index.d.ts:180
controller is the CC number, value is 0-127.
Parameters
| Parameter | Type |
|---|---|
controller | number |
value | number |
channel | number |
Returns
void
onNoteOffEvent?
optional onNoteOffEvent?: (note, channel) => void;
Defined in: dom/dist/index.d.ts:171
Parameters
| Parameter | Type |
|---|---|
note | number |
channel | number |
Returns
void
onNoteOnEvent?
optional onNoteOnEvent?: (note, velocity, channel) => void;
Defined in: dom/dist/index.d.ts:170
Parameters
| Parameter | Type |
|---|---|
note | number |
velocity | number |
channel | number |
Returns
void
onPitchBendEvent?
optional onPitchBendEvent?: (value, channel) => void;
Defined in: dom/dist/index.d.ts:178
The 14-bit bend, 0-16383, centred at PITCH_BEND_CENTER.
The two data bytes are little-endian — the first carries the low 7 bits — which is the other way round from every other message.
Parameters
| Parameter | Type |
|---|---|
value | number |
channel | number |
Returns
void
onProgramChangeEvent?
optional onProgramChangeEvent?: (program, channel) => void;
Defined in: dom/dist/index.d.ts:181
Parameters
| Parameter | Type |
|---|---|
program | number |
channel | number |
Returns
void
Variables
PITCH_BEND_CENTER
const PITCH_BEND_CENTER: 8192 = 8192;
Defined in: dom/dist/index.d.ts:164
Centre of the 14-bit pitch bend range: no bend.
The range is not symmetric — 0 is 8192 below centre and 16383 is 8191 above — so a wheel at rest reports exactly this rather than half of the maximum.
Functions
useMIDIInput()
function useMIDIInput(midiAccess, handlers): void;
Defined in: react/src/hooks/useMIDIInput.ts:29
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)
},
})