Skip to content

Commit

Permalink
Events: Add Play/Pause events.
Browse files Browse the repository at this point in the history
Uses much of the existing machinery to add some more PlayMode state change events—all in all, a pretty simple change.

Closes #29.
  • Loading branch information
FelixMcFelix committed Jan 17, 2021
1 parent cb2398f commit 868c44c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/driver/tasks/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub(crate) async fn runner(_interconnect: Interconnect, evt_rx: Receiver<EventMe
Mode(mode) => {
let old = state.playing;
state.playing = mode;
if old != mode && mode.is_done() {
global.fire_track_event(TrackEvent::End, i);
if old != mode {
global.fire_track_event(mode.as_track_event(), i);
}
},
Volume(vol) => {
Expand Down
8 changes: 8 additions & 0 deletions src/events/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum TrackEvent {
/// The attached track has resumed playing.
///
/// This event will not fire when a track first starts,
/// but will fire when a track changes from, e.g., paused to playing.
/// This is most relevant for queue users.
Play,
/// The attached track has been paused.
Pause,
/// The attached track has ended.
End,
/// The attached track has looped.
Expand Down
11 changes: 11 additions & 0 deletions src/tracks/mode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::events::TrackEvent;

/// Playback status of a track.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
Expand Down Expand Up @@ -29,6 +31,15 @@ impl PlayMode {
state => state,
}
}

pub(crate) fn as_track_event(self) -> TrackEvent {
use PlayMode::*;
match self {
Play => TrackEvent::Play,
Pause => TrackEvent::Pause,
Stop | End => TrackEvent::End,
}
}
}

impl Default for PlayMode {
Expand Down

0 comments on commit 868c44c

Please sign in to comment.