Synth event handler
The Synthesizer Event Handler
The synthesizer supports event handling. For example, the MIDI Keyboard in the demo uses handling to visualize key-presses.
It is accessible via the synth.eventHandler
property.
Managing the events
Adding event listener
- name - the type of the event. refer to the table below.
- id - unique id for the event listener. Can be anything, as long as it’s unique.
- callback. a function that gets called on the event. Callback takes an
object
argument. The properties depend on the event type. Refer to the table below.
Example:
// log every note played
synth.eventHandler.addEvent("noteon", "note-on-listener", data => {
console.log(`Note ${data.midiNote} played for channel ${data.channel} with velocity ${data.velocity}.`)
})
Removing event listener
- name - the type of the event.
- id - the unique id of the event you wish to remove.
Example:
Delaying the event system
If you need to delay the events (for example, to sync up with something), you can use the timeDelay
property.
The delay time is specified in seconds. Set to 0 to disable (instant callback). Default is 0.