use std::sync::Arc;
use ringbuf::HeapProducer;
use crate::{tween::Tween, CommandError, PlaybackRate, Volume};
use super::{sound::Shared, Command, PlaybackState};
pub struct StaticSoundHandle {
pub(super) command_producer: HeapProducer<Command>,
pub(super) shared: Arc<Shared>,
}
impl StaticSoundHandle {
pub fn state(&self) -> PlaybackState {
self.shared.state()
}
pub fn position(&self) -> f64 {
self.shared.position()
}
pub fn set_volume(
&mut self,
volume: impl Into<Volume>,
tween: Tween,
) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetVolume(volume.into(), tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn set_playback_rate(
&mut self,
playback_rate: impl Into<PlaybackRate>,
tween: Tween,
) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetPlaybackRate(playback_rate.into(), tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn set_panning(&mut self, panning: f64, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetPanning(panning, tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn pause(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Pause(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn resume(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Resume(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn stop(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Stop(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn seek_to(&mut self, position: f64) -> Result<(), CommandError> {
self.command_producer
.push(Command::SeekTo(position))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn seek_by(&mut self, amount: f64) -> Result<(), CommandError> {
self.command_producer
.push(Command::SeekBy(amount))
.map_err(|_| CommandError::CommandQueueFull)
}
}