Registers a handler fn
for incoming MIDI events that match object selector
.
A selector is either an array (or array-like) in the form of a MIDI message
[status, data1, data2]
:
on([144], fn);
on([144, 60], fn);
on([144, 60, 127], fn);
or a bit more conveniently an object of interpretive data of the form
{channel, type, name, value}
:
on({ channel: 2, type: 'noteon' }, fn);
on({ channel: 2, type: 'noteoff', name: 'C4' }, fn)
on({ channel: 2, type: 'note', name: 'C4' }, fn)
on({ channel: 4, type: 'control', name: 'modulation', value: 0 }, fn)
Note that these selector properties are progressive. A selector may not have
a type
if it has no channel
, it may not have a name
without a type
,
and may not have a value
without a name
property. Selectors pre-create
paths in a distribution tree that is optimised for incoming events to flow
through.
Finally, a selector may optionally have a property port
, the id of an
input port.
on({ port: '0123', 0: 179, 1: 64 }}, fn);
on({ port: '0123', channel: 4, type: 'control', name: 64 }}, fn);
Removes an event listener ‘fn’ from MIDI events matching object ‘selector’. Where
‘fn’ is not given, removes all handlers from events matching the selector.
off({ channel: 1, type: 'note' }, fn);
Simulates an incoming MIDI event and fires listeners with matching selectors.
Useful for debugging.
trigger(null, [128, 69, 88]);
As trigger(port, message)
, where the last 4 parameters are passed to
createMessage()
to create the MIDI message before triggering.
trigger(null, 1, 'noteon', 'A4', 0.75);