mod action;
mod command;
mod error;
mod handle;
mod looping;
mod mode;
mod queue;
mod ready;
mod state;
mod view;
pub use self::{
action::*,
error::*,
handle::*,
looping::*,
mode::*,
queue::*,
ready::*,
state::*,
view::*,
};
pub(crate) use command::*;
use crate::{constants::*, driver::tasks::message::*, events::EventStore, input::Input};
use std::{any::Any, sync::Arc, time::Duration};
use uuid::Uuid;
pub struct Track {
pub playing: PlayMode,
pub volume: f32,
pub input: Input,
pub events: EventStore,
pub loops: LoopState,
pub uuid: Uuid,
pub user_data: Arc<dyn Any + Send + Sync>,
}
impl Track {
#[must_use]
pub fn new(input: Input) -> Self {
Self::new_with_uuid(input, Uuid::new_v4())
}
#[must_use]
pub fn new_with_uuid(input: Input, uuid: Uuid) -> Self {
Self::new_with_uuid_and_data(input, uuid, Arc::new(()))
}
#[must_use]
pub fn new_with_data(input: Input, user_data: Arc<dyn Any + Send + Sync + 'static>) -> Self {
Self::new_with_uuid_and_data(input, Uuid::new_v4(), user_data)
}
#[must_use]
pub fn new_with_uuid_and_data(
input: Input,
uuid: Uuid,
user_data: Arc<dyn Any + Send + Sync + 'static>,
) -> Self {
Self {
playing: PlayMode::default(),
volume: 1.0,
input,
events: EventStore::new_local(),
loops: LoopState::Finite(nonmax::NonMaxU32::ZERO),
uuid,
user_data,
}
}
#[must_use]
pub fn play(mut self) -> Self {
self.playing = PlayMode::Play;
self
}
#[must_use]
pub fn pause(mut self) -> Self {
self.playing = PlayMode::Pause;
self
}
#[must_use]
pub fn stop(mut self) -> Self {
self.playing = PlayMode::Stop;
self
}
#[must_use]
pub fn volume(mut self, volume: f32) -> Self {
self.volume = volume;
self
}
#[must_use]
pub fn loops(mut self, loops: LoopState) -> Self {
self.loops = loops;
self
}
#[must_use]
pub fn uuid(mut self, uuid: Uuid) -> Self {
self.uuid = uuid;
self
}
pub(crate) fn into_context(self) -> (TrackHandle, TrackContext) {
let (tx, receiver) = flume::unbounded();
let handle = TrackHandle::new(tx, self.uuid, self.user_data.clone());
let context = TrackContext {
handle: handle.clone(),
track: self,
receiver,
};
(handle, context)
}
}
impl<T: Into<Input>> From<T> for Track {
fn from(val: T) -> Self {
Track::new(val.into())
}
}