pub struct AudioNodePool<N: PoolableNode, FX: FxChain> { /* private fields */ }Expand description
A pool of audio node chains that can dynamically be assigned work.
Implementations§
Source§impl<N: PoolableNode, FX: FxChain> AudioNodePool<N, FX>
impl<N: PoolableNode, FX: FxChain> AudioNodePool<N, FX>
Sourcepub fn new<B: AudioBackend>(
num_workers: usize,
first_node: N::AudioNode,
first_node_config: Option<<N::AudioNode as AudioNode>::Configuration>,
dst_node_id: NodeID,
dst_num_channels: NonZeroChannelCount,
cx: &mut FirewheelCtx<B>,
) -> Self
pub fn new<B: AudioBackend>( num_workers: usize, first_node: N::AudioNode, first_node_config: Option<<N::AudioNode as AudioNode>::Configuration>, dst_node_id: NodeID, dst_num_channels: NonZeroChannelCount, cx: &mut FirewheelCtx<B>, ) -> Self
Construct a new sampler pool.
num_workers- The total number of workers that can work in parallel. More workers will allow more samples to be played concurrently, but will also increase processing overhead. A value of16is a good place to start.first_node- The state of the first node in each FX chain instance.first_node_config- The configuration of the first node in each FX chain instance.first_node_num_out_channels- The number of output channels in the first node.dst_node_id- The ID of the node that the last effect in each fx chain instance will connect to.dst_num_channels- The number of input channels indst_node_id.cx- The firewheel context.
pub fn num_workers(&self) -> usize
Sourcepub fn new_worker<B: AudioBackend>(
&mut self,
params: &N::AudioNode,
time: Option<EventInstant>,
steal: bool,
cx: &mut FirewheelCtx<B>,
fx_chain: impl FnOnce(&mut FxChainState<FX>, &mut FirewheelCtx<B>),
) -> Result<NewWorkerResult, NewWorkerError>
pub fn new_worker<B: AudioBackend>( &mut self, params: &N::AudioNode, time: Option<EventInstant>, steal: bool, cx: &mut FirewheelCtx<B>, fx_chain: impl FnOnce(&mut FxChainState<FX>, &mut FirewheelCtx<B>), ) -> Result<NewWorkerResult, NewWorkerError>
Queue a new work to play a sequence.
params- The parameters of the sequence to play.time- The instant these new parameters should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.steal- If this istrue, then if there are no more workers left in in the pool, the oldest one will be stopped and replaced with this new one. If this isfalse, then an error will be returned if no more workers are left.cx- The Firewheel context.fx_chain- A closure to add additional nodes to this worker instance.
This will return an error if params.playback == PlaybackState::Stop.
Sourcepub fn sync_worker_params<B: AudioBackend>(
&mut self,
worker_id: WorkerID,
params: &N::AudioNode,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
) -> bool
pub fn sync_worker_params<B: AudioBackend>( &mut self, worker_id: WorkerID, params: &N::AudioNode, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool
Sync the parameters for the given worker.
worker_id- The ID of the workerparams- The new parameter state to synctime- The instant these new parameters should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.cx- The Firewheel context
If the parameters signify that the seuquence is stopped, then this worker
will be removed and the worker_id will be invalidated.
Returns true if a worker with the given ID exists, false otherwise.
Sourcepub fn pause<B: AudioBackend>(
&mut self,
worker_id: WorkerID,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
) -> bool
pub fn pause<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool
Pause the given worker.
worker_id- The ID of the workertime- The instant that the pause should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.cx- The Firewheel context
Returns true if a worker with the given ID exists, false otherwise.
Sourcepub fn resume<B: AudioBackend>(
&mut self,
worker_id: WorkerID,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
) -> bool
pub fn resume<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool
Resume the given worker.
worker_id- The ID of the workertime- The instant that the resume should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.cx- The Firewheel context
Returns true if a worker with the given ID exists, false otherwise.
Sourcepub fn stop<B: AudioBackend>(
&mut self,
worker_id: WorkerID,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
) -> bool
pub fn stop<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool
Stop the given worker.
worker_id- The ID of the workertime- The instant that the stop should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.cx- The Firewheel context
This will remove the worker and invalidate the given worker_id.
Returns true if a worker with the given ID exists and was stopped.
Sourcepub fn pause_all<B: AudioBackend>(
&mut self,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
)
pub fn pause_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )
Pause all workers.
time- The instant that the stop should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.
Sourcepub fn resume_all<B: AudioBackend>(
&mut self,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
)
pub fn resume_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )
Resume all workers.
time- The instant that the stop should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.
Sourcepub fn stop_all<B: AudioBackend>(
&mut self,
time: Option<EventInstant>,
cx: &mut FirewheelCtx<B>,
)
pub fn stop_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )
Stop all workers.
time- The instant that the stop should take effect. If this isNone, then the parameters will take effect as soon as the node receives the event.
Sourcepub fn first_node(&self, worker_id: WorkerID) -> Option<&N::AudioNode>
pub fn first_node(&self, worker_id: WorkerID) -> Option<&N::AudioNode>
Get the first node parameters of the given worker.
Sourcepub fn first_node_state<'a, T: 'static, B: AudioBackend>(
&self,
worker_id: WorkerID,
cx: &'a FirewheelCtx<B>,
) -> Option<&'a T>
pub fn first_node_state<'a, T: 'static, B: AudioBackend>( &self, worker_id: WorkerID, cx: &'a FirewheelCtx<B>, ) -> Option<&'a T>
Get an immutable reference to the state of the first node of the given worker.
Sourcepub fn first_node_state_mut<'a, T: 'static, B: AudioBackend>(
&self,
worker_id: WorkerID,
cx: &'a mut FirewheelCtx<B>,
) -> Option<&'a mut T>
pub fn first_node_state_mut<'a, T: 'static, B: AudioBackend>( &self, worker_id: WorkerID, cx: &'a mut FirewheelCtx<B>, ) -> Option<&'a mut T>
Get a mutable reference to the state of the first node of the given worker.
pub fn fx_chain(&self, worker_id: WorkerID) -> Option<&FxChainState<FX>>
pub fn fx_chain_mut( &mut self, worker_id: WorkerID, ) -> Option<&mut FxChainState<FX>>
Sourcepub fn has_stopped<B: AudioBackend>(
&self,
worker_id: WorkerID,
cx: &FirewheelCtx<B>,
) -> bool
pub fn has_stopped<B: AudioBackend>( &self, worker_id: WorkerID, cx: &FirewheelCtx<B>, ) -> bool
Returns true if the sequence has either not started playing yet or has finished
playing.
Sourcepub fn poll<B: AudioBackend>(&mut self, cx: &FirewheelCtx<B>) -> PollResult
pub fn poll<B: AudioBackend>(&mut self, cx: &FirewheelCtx<B>) -> PollResult
Poll for the current number of active workers, and return a list of workers which have finished playing.
Calling this method is optional.
Sourcepub fn num_active_workers(&self) -> usize
pub fn num_active_workers(&self) -> usize
The total number of active workers.