Expand description
Events relating to tracks, timing, and other callers.
§Listening for events
Driver events in Songbird are composed of two parts:
- An
Event
to listen out for. These may be discrete events, or generated by timers. - An
EventHandler
to be called on receipt of an event. As event handlers may be shared between several events, the handler is called with anEventContext
describing which event was fired.
Event handlers are registered using functions such as Driver::add_global_event
,
or TrackHandle::add_event
, or. Internally, these pairs are stored
as EventData
.
§EventHandler
lifecycle
An event handler is essentially just an async function which may return
another type of event to listen out for (an Option<Event>
). For instance,
Some(Event::Cancel)
will remove that event listener, while None
won’t
change it at all.
The exception is one-off events like Event::Delayed
, which remove themselves
after one call unless an Event
override is returned.
§Global and local listeners
Global event listeners are those which are placed onto the Driver
,
while local event listeners are those which are placed on a
Track
/Handle
.
Track or timed events, when local, return a reference to the parent track. When registered globally, they fire on a per-tick basis, returning references to all relevant tracks in that 20ms window. Global/local timed events use a global timer or a track’s playback time, respectively.
CoreEvent
s may only be registered globally.
Modules§
- context_
data - Types containing the main body of an
EventContext
.
Structs§
- Event
Data - Internal representation of an event, as handled by the audio context.
- Event
Store - Storage for
EventData
, designed to be used for both local and global contexts.
Enums§
- Core
Event - Voice core events occur on receipt of voice packets and telemetry.
- Event
- Classes of event which may occur, triggering a handler at the local (track-specific) or global level.
- Event
Context - Information about which tracks or data fired an event.
- Track
Event - Track events correspond to certain actions or changes of state, such as a track finishing, looping, or being manually stopped. Voice core events occur on receipt of voice packets and telemetry.
- Untimed
Event - Track and voice core events.
Traits§
- Event
Handler - Trait to handle an event which can be fired per-track, or globally.