diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1560adc..62da373 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,7 +74,7 @@ repos: - yaml # https://reuse.software - repo: https://github.com/fsfe/reuse-tool - rev: v2.1.0 + rev: v3.0.1 hooks: - id: reuse - repo: local diff --git a/src/deck.rs b/src/deck.rs index c679b6e..b01fee1 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -28,7 +28,7 @@ pub struct Cue { pub enum PlayState { /// Paused Paused { - on_cue: bool, + playhead_on_cue: bool, }, /// Previewing while (hot) cue is pressed Previewing { @@ -45,10 +45,14 @@ impl PlayState { #[must_use] pub const fn pioneer_cue_led_state(&self) -> LedState { match self { - PlayState::Paused { on_cue: true } + PlayState::Paused { + playhead_on_cue: true, + } | PlayState::Previewing { .. } | PlayState::Playing => LedState::On, - PlayState::Paused { on_cue: false } => LedState::BlinkFast, + PlayState::Paused { + playhead_on_cue: false, + } => LedState::BlinkFast, PlayState::Ended => LedState::Off, } } @@ -63,6 +67,12 @@ impl PlayState { } } +#[derive(Debug, Clone, Copy, Default, PartialEq)] +pub struct Playhead { + pub position: Position, + pub is_playing: bool, +} + #[derive(Debug, Clone, PartialEq)] pub struct Playable { pub play_state: PlayState, @@ -101,7 +111,7 @@ impl Default for Tempo { pub struct PlaybackParams { /// Playback rate /// - /// A value of 1.0 means normal playback speed. A value of 0.0 means paused. + /// A value of 1.0 means normal playback speed. A value of 0.0 means halt. /// /// If the playback rate is negative, the media will be played backwards. /// @@ -130,9 +140,7 @@ pub struct Player { /// Cue pub cue: Cue, - /// Tempo - pub tempo: Tempo, - + /// Playback parameters pub playback_params: PlaybackParams, } @@ -142,7 +150,6 @@ pub struct Player { #[derive(Debug, Clone, Default, PartialEq)] pub struct UpdatePlayer { pub cue: Option, - pub tempo: Option, pub playback_params: Option, } @@ -153,7 +160,8 @@ pub enum Input { PlayPause(ButtonInput), Sync(ButtonInput), Position(SliderInput), - Tempo(CenterSliderInput), + RelativeTempo(CenterSliderInput), + PitchSemitones(Option), } #[cfg(feature = "observables")] @@ -164,13 +172,41 @@ pub struct Observables { pub player: discro::Publisher, } -pub trait Device { - /// Get the playhead position +#[cfg(feature = "observables")] +impl Observables { + pub fn on_playhead_changed(&mut self, playhead_on_cue: bool) { + self.playable.modify(|playable| { + let Some(playable) = playable.as_mut() else { + return false; + }; + match playable.play_state { + PlayState::Paused { + playhead_on_cue: paused_on_cue, + } => { + if playhead_on_cue != paused_on_cue { + playable.play_state = PlayState::Paused { playhead_on_cue }; + return true; + } + } + PlayState::Ended => { + playable.play_state = PlayState::Paused { playhead_on_cue }; + return true; + } + PlayState::Playing | PlayState::Previewing { .. } => (), + } + // Unchanged + false + }); + } +} + +pub trait Adapter { + /// Get the playhead #[must_use] - fn playhead(&self) -> Position; + fn playhead(&self) -> Playhead; - /// Set the playhead position - fn set_playhead(&mut self, position: Position); + /// Set the playhead + fn set_playhead_position(&mut self, position: Position); /// Update selected [`Player`] fields fn update_player(&mut self, update_player: UpdatePlayer); diff --git a/src/lib.rs b/src/lib.rs index 5f0aaea..b930a82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,7 @@ pub use self::midi::{ pub mod deck; #[cfg(feature = "observables")] pub use deck::Observables as DeckObservables; -pub use deck::{Device as DeckDevice, Input as DeckInput}; +pub use deck::{Adapter as DeckAdapter, Input as DeckInput}; #[cfg(feature = "experimental-param")] pub mod param;