Skip to main content

kithara_queue/queue/
passthrough.rs

1use delegate::delegate;
2use kithara_bufpool::HasPool;
3use kithara_events::EventBus;
4use kithara_play::{CrossfadeSettings, EngineLoadSnapshot, EqBandConfig, PlayError, PlayerStatus};
5
6use super::QueueControl;
7use crate::event::QueueEvent;
8
9impl<S> QueueControl<S>
10where
11    S: HasPool<u8> + HasPool<f32> + Send + Sync + 'static,
12{
13    /// Underlying event bus used by queue and player events.
14    #[must_use]
15    pub fn bus(&self) -> &EventBus {
16        &self.bus
17    }
18
19    #[must_use]
20    pub fn crossfade_settings(&self) -> CrossfadeSettings {
21        *self
22            .crossfade_settings
23            .lock()
24            .unwrap_or_else(std::sync::PoisonError::into_inner)
25    }
26
27    /// Drain pending player-side notifications. Called by FFI tick
28    /// loops after [`Self::tick`].
29    pub fn process_notifications(&self) {
30        self.command(|queue| queue.player.process_notifications());
31    }
32
33    /// Reset all EQ bands to 0 dB.
34    ///
35    /// # Errors
36    /// Forwards `PlayError` from the underlying player.
37    pub fn reset_eq(&self) -> Result<(), PlayError> {
38        self.with_open_result(|queue| queue.player.reset_eq())
39    }
40
41    /// Update the profile captured by future transitions.
42    ///
43    /// # Errors
44    /// Returns an error when any profile value is invalid.
45    pub fn set_crossfade_settings(&self, settings: CrossfadeSettings) -> Result<(), PlayError> {
46        let settings = settings.validate()?;
47        self.with_open_result(|queue| {
48            *queue
49                .crossfade_settings
50                .lock()
51                .unwrap_or_else(std::sync::PoisonError::into_inner) = settings;
52            queue.player.set_crossfade_duration(settings.duration);
53            queue
54                .bus
55                .publish(QueueEvent::CrossfadeSettingsChanged { settings });
56            Ok(())
57        })
58    }
59
60    /// Set the default playback rate.
61    pub fn set_default_rate(&self, rate: f32) {
62        self.command(|queue| queue.player.set_default_rate(rate));
63    }
64
65    /// Set gain for an EQ band.
66    ///
67    /// # Errors
68    /// Forwards `PlayError` from the underlying player.
69    pub fn set_eq_gain(&self, band: usize, gain_db: f32) -> Result<(), PlayError> {
70        self.with_open_result(|queue| queue.player.set_eq_gain(band, gain_db))
71    }
72
73    /// Replace the live player's EQ band layout.
74    ///
75    /// # Errors
76    /// Forwards `PlayError` from the underlying player.
77    pub fn set_eq_layout(&self, layout: Vec<EqBandConfig>) -> Result<(), PlayError> {
78        self.with_open_result(|queue| queue.player.set_eq_layout(layout))
79    }
80
81    /// Set the mute flag.
82    pub fn set_muted(&self, muted: bool) {
83        self.command(|queue| queue.player.set_muted(muted));
84    }
85
86    /// Set the live playback rate (mirrors into the tempo-mode sibling
87    /// so a running key-locked stretch tracks the move).
88    pub fn set_rate(&self, rate: f32) {
89        self.command(|queue| queue.player.set_rate(rate));
90    }
91
92    /// Set the volume (0.0..=1.0).
93    pub fn set_volume(&self, volume: f32) {
94        self.command(|queue| queue.player.set_volume(volume));
95    }
96
97    delegate! {
98        to self.player {
99            /// Whether playback is active.
100            #[must_use]
101            pub fn is_playing(&self) -> bool;
102            /// Live engine playback rate (player-reported, 0.0 when paused).
103            #[must_use]
104            pub fn rate(&self) -> f32;
105            /// Default playback rate.
106            #[must_use]
107            pub fn default_rate(&self) -> f32;
108            /// Current volume (0.0..=1.0).
109            #[must_use]
110            pub fn volume(&self) -> f32;
111            /// Whether output is muted.
112            #[must_use]
113            pub fn is_muted(&self) -> bool;
114            /// Live engine playback status.
115            #[must_use]
116            pub fn status(&self) -> PlayerStatus;
117            /// Live audio-engine cost (realtime factor / load / ms).
118            #[must_use]
119            pub fn engine_load(&self) -> EngineLoadSnapshot;
120            /// Number of EQ bands.
121            #[must_use]
122            pub fn eq_band_count(&self) -> usize;
123            /// Current gain for an EQ band.
124            #[must_use]
125            pub fn eq_gain(&self, band: usize) -> Option<f32>;
126            /// Current track duration in seconds.
127            #[must_use]
128            pub fn duration_seconds(&self) -> Option<f64>;
129        }
130    }
131}