Skip to content

Commit

Permalink
Add more deck types and traits
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jan 18, 2024
1 parent 460f919 commit 76d5852
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ anyhow = "1.0.79"
derive_more = "0.99.17"
float-cmp = "0.9.0"
futures-core = { version = "0.3.30", default-features = false }
futures-util = { version = "0.3.30", default-features = false, features = ["std"] }
futures-util = { version = "0.3.30", default-features = false, features = [
"std",
] }
# TODO: Replace with std when available.
# Tracking issue for RFC 2351: <https://github.com/rust-lang/rust/issues/53485>
is_sorted = "0.1.1"
Expand Down Expand Up @@ -50,16 +52,19 @@ pretty_env_logger = "0.5.0"
default = [
"all-controllers",
"midir",
"observables",
"blinking-led-task-tokio-rt",
"controller-thread",
]
midi = []
midir = ["dep:midir"]
jack = ["midir?/jack"]
hid = ["dep:hidapi"]
blinking-led-task = ["dep:discro", "discro/tokio", "dep:tokio", "tokio/time"]
tokio = ["dep:tokio", "discro?/tokio"]
observables = ["dep:discro"]
blinking-led-task = ["dep:discro", "tokio", "tokio/time"]
blinking-led-task-tokio-rt = ["blinking-led-task", "tokio/rt"]
controller-thread = ["dep:tokio", "tokio/rt", "tokio/time"]
controller-thread = ["tokio", "tokio/rt", "tokio/time"]

# Controller support features
# TODO: Extract each controller into a separate crate after the API has settled.
Expand Down
77 changes: 63 additions & 14 deletions src/deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::time::Duration;

use crate::{CenterSliderInput, LedState};
use crate::{ButtonInput, CenterSliderInput, LedState, SliderInput};

pub const PLAYBACK_RATE_DEFAULT: f32 = 1.0;

Expand Down Expand Up @@ -97,16 +97,16 @@ impl Default for Tempo {
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct Player {
/// Cue
pub cue: Cue,

/// Tempo
pub tempo: Tempo,

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlaybackParams {
/// Playback rate
pub playback_rate: f32,
///
/// A value of 1.0 means normal playback speed. A value of 0.0 means paused.
///
/// If the playback rate is negative, the media will be played backwards.
///
/// If the playback rate affects the pitch, depends on `pitch_semitones`.
pub rate: f32,

/// Pitch
///
Expand All @@ -116,13 +116,62 @@ pub struct Player {
pub pitch_semitones: Option<i8>,
}

impl Default for Player {
impl Default for PlaybackParams {
fn default() -> Self {
Self {
cue: Default::default(),
tempo: Default::default(),
playback_rate: PLAYBACK_RATE_DEFAULT,
rate: PLAYBACK_RATE_DEFAULT,
pitch_semitones: None,
}
}
}

#[derive(Debug, Clone, Default, PartialEq)]
pub struct Player {
/// Cue
pub cue: Cue,

/// Tempo
pub tempo: Tempo,

pub playback_params: PlaybackParams,
}

/// `Player` with all fields optional
///
/// Fields that are `None` will not be updated.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct UpdatePlayer {
pub cue: Option<Cue>,
pub tempo: Option<Tempo>,
pub playback_params: Option<PlaybackParams>,
}

/// Deck inputs
#[derive(Debug, Clone, Copy)]
pub enum Input {
Cue(ButtonInput),
PlayPause(ButtonInput),
Sync(ButtonInput),
Position(SliderInput),
Tempo(CenterSliderInput),
}

#[cfg(feature = "observables")]
#[derive(Default)]
#[allow(missing_debug_implementations)]
pub struct Observables {
pub playable: discro::Publisher<Option<Playable>>,
pub player: discro::Publisher<Player>,
}

pub trait Device {
/// Get the playhead position
#[must_use]
fn playhead(&self) -> Position;

/// Set the playhead position
fn set_playhead(&mut self, position: Position);

/// Update selected [`Player`] fields
fn update_player(&mut self, update_player: UpdatePlayer);
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ 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};

#[cfg(feature = "experimental-param")]
pub mod param;
Expand Down

0 comments on commit 76d5852

Please sign in to comment.