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.
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
/// Playback status of a track.
|
|
pub enum PlayMode {
|
|
/// The track is currently playing.
|
|
Play,
|
|
/// The track is currently paused, and may be resumed.
|
|
Pause,
|
|
/// The track has been manually stopped, and cannot be restarted.
|
|
Stop,
|
|
/// The track has naturally ended, and cannot be restarted.
|
|
End,
|
|
}
|
|
|
|
impl PlayMode {
|
|
/// Returns whether the track has irreversibly stopped.
|
|
pub fn is_done(self) -> bool {
|
|
matches!(self, PlayMode::Stop | PlayMode::End)
|
|
}
|
|
|
|
pub(crate) fn change_to(self, other: Self) -> PlayMode {
|
|
use PlayMode::*;
|
|
|
|
// Idea: a finished track cannot be restarted -- this action is final.
|
|
// We may want to change this in future so that seekable tracks can uncancel
|
|
// themselves, perhaps, but this requires a bit more machinery to readd...
|
|
match self {
|
|
Play | Pause => other,
|
|
state => state,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for PlayMode {
|
|
fn default() -> Self {
|
|
PlayMode::Play
|
|
}
|
|
}
|