Voice Rework -- Events, Track Queues (#806)
This implements a proof-of-concept for an improved audio frontend. The largest change is the introduction of events and event handling: both by time elapsed and by track events, such as ending or looping. Following on from this, the library now includes a basic, event-driven track queue system (which people seem to ask for unusually often). A new sample, `examples/13_voice_events`, demonstrates both the `TrackQueue` system and some basic events via the `~queue` and `~play_fade` commands. Locks are removed from around the control of `Audio` objects, which should allow the backend to be moved to a more granular futures-based backend solution in a cleaner way.
This commit is contained in:
31
src/tracks/state.rs
Normal file
31
src/tracks/state.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use super::*;
|
||||
|
||||
/// State of an [`Track`] object, designed to be passed to event handlers
|
||||
/// and retrieved remotely via [`TrackHandle::get_info`] or
|
||||
/// [`TrackHandle::get_info_blocking`].
|
||||
///
|
||||
/// [`Track`]: struct.Track.html
|
||||
/// [`TrackHandle::get_info`]: struct.TrackHandle.html#method.get_info
|
||||
/// [`TrackHandle::get_info_blocking`]: struct.TrackHandle.html#method.get_info_blocking
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
pub struct TrackState {
|
||||
/// Play status (e.g., active, paused, stopped) of this track.
|
||||
pub playing: PlayMode,
|
||||
/// Current volume of this track.
|
||||
pub volume: f32,
|
||||
/// Current playback position in the source.
|
||||
///
|
||||
/// This is altered by loops and seeks
|
||||
pub position: Duration,
|
||||
/// Total playback time, increasing monotonically.
|
||||
pub play_time: Duration,
|
||||
/// Remaining loops on this track.
|
||||
pub loops: LoopState,
|
||||
}
|
||||
|
||||
impl TrackState {
|
||||
pub(crate) fn step_frame(&mut self) {
|
||||
self.position += TIMESTEP_LENGTH;
|
||||
self.play_time += TIMESTEP_LENGTH;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user