pub struct FirewheelCtx<B: AudioBackend> { /* private fields */ }Expand description
A Firewheel context
Implementations§
Source§impl<B: AudioBackend> FirewheelCtx<B>
impl<B: AudioBackend> FirewheelCtx<B>
Sourcepub fn new(config: FirewheelConfig) -> Self
pub fn new(config: FirewheelConfig) -> Self
Create a new Firewheel context.
Sourcepub fn available_input_devices(&self) -> Vec<DeviceInfo>
pub fn available_input_devices(&self) -> Vec<DeviceInfo>
Get a list of the available audio input devices.
Sourcepub fn available_output_devices(&self) -> Vec<DeviceInfo>
pub fn available_output_devices(&self) -> Vec<DeviceInfo>
Get a list of the available audio output devices.
Sourcepub fn can_start_stream(&self) -> bool
pub fn can_start_stream(&self) -> bool
Returns true if an audio stream can be started right now.
When calling FirewheelCtx::stop_stream(), it may take some time for the
old stream to be fully stopped. This method is used to check if it has been
dropped yet.
Note, in rare cases where the audio thread crashes without cleanly dropping
its contents, this may never return true. Consider adding a timeout to
avoid deadlocking.
Sourcepub fn start_stream(
&mut self,
config: B::Config,
) -> Result<(), StartStreamError<B::StartStreamError>>
pub fn start_stream( &mut self, config: B::Config, ) -> Result<(), StartStreamError<B::StartStreamError>>
Start an audio stream for this context. Only one audio stream can exist on a context at a time.
When calling FirewheelCtx::stop_stream(), it may take some time for the
old stream to be fully stopped. Use FirewheelCtx::can_start_stream to
check if it has been dropped yet.
Note, in rare cases where the audio thread crashes without cleanly dropping its contents, this may never succeed. Consider adding a timeout to avoid deadlocking.
Sourcepub fn stop_stream(&mut self)
pub fn stop_stream(&mut self)
Stop the audio stream in this context.
Sourcepub fn is_audio_stream_running(&self) -> bool
pub fn is_audio_stream_running(&self) -> bool
Returns true if there is currently a running audio stream.
Sourcepub fn stream_info(&self) -> Option<&StreamInfo>
pub fn stream_info(&self) -> Option<&StreamInfo>
Information about the running audio stream.
Returns None if no audio stream is currently running.
Sourcepub fn clock_now(&self) -> ClockSeconds
pub fn clock_now(&self) -> ClockSeconds
The current time of the clock in the number of seconds since the stream was started.
Note, this clock is not perfectly accurate, but it is good enough for most use cases. This clock also correctly accounts for any output underflows that may occur.
Sourcepub fn clock_samples(&self) -> ClockSamples
pub fn clock_samples(&self) -> ClockSamples
The current time of the sample clock in the number of samples (of a single channel of audio) that have been processed since the beginning of the stream.
This is more accurate than the seconds clock, and is ideal for syncing events to a musical transport. Though note that this clock does not account for any output underflows that may occur.
Sourcepub fn clock_musical(&self) -> MusicalTime
pub fn clock_musical(&self) -> MusicalTime
The current musical time of the transport.
If no transport is currently active, then this will have a value of 0.
Sourcepub fn set_transport(
&mut self,
transport: Option<MusicalTransport>,
) -> Result<(), UpdateError<B::StreamError>>
pub fn set_transport( &mut self, transport: Option<MusicalTransport>, ) -> Result<(), UpdateError<B::StreamError>>
Set the musical transport to use.
If an existing musical transport is already running, then the new transport will pick up where the old one left off. This allows you to, for example, change the tempo dynamically at runtime.
If the message channel is full, then this will return an error.
Sourcepub fn start_or_restart_transport(
&mut self,
) -> Result<(), UpdateError<B::StreamError>>
pub fn start_or_restart_transport( &mut self, ) -> Result<(), UpdateError<B::StreamError>>
Start or restart the musical transport.
If the message channel is full, then this will return an error.
Sourcepub fn pause_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
pub fn pause_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
Pause the musical transport.
If the message channel is full, then this will return an error.
Sourcepub fn resume_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
pub fn resume_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
Resume the musical transport.
If the message channel is full, then this will return an error.
Sourcepub fn stop_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
pub fn stop_transport(&mut self) -> Result<(), UpdateError<B::StreamError>>
Stop the musical transport.
If the message channel is full, then this will return an error.
Sourcepub fn hard_clip_outputs(&self) -> bool
pub fn hard_clip_outputs(&self) -> bool
Whether or not outputs are being hard clipped at 0dB.
Sourcepub fn set_hard_clip_outputs(
&mut self,
hard_clip_outputs: bool,
) -> Result<(), UpdateError<B::StreamError>>
pub fn set_hard_clip_outputs( &mut self, hard_clip_outputs: bool, ) -> Result<(), UpdateError<B::StreamError>>
Set whether or not outputs should be hard clipped at 0dB to help protect the system’s speakers.
Note that most operating systems already hard clip the output, so this is usually not needed (TODO: Do research to see if this assumption is true.)
If the message channel is full, then this will return an error.
Sourcepub fn update(&mut self) -> Result<(), UpdateError<B::StreamError>>
pub fn update(&mut self) -> Result<(), UpdateError<B::StreamError>>
Update the firewheel context.
This must be called reguarly (i.e. once every frame).
Sourcepub fn graph_in_node_id(&self) -> NodeID
pub fn graph_in_node_id(&self) -> NodeID
The ID of the graph input node
Sourcepub fn graph_out_node_id(&self) -> NodeID
pub fn graph_out_node_id(&self) -> NodeID
The ID of the graph output node
Sourcepub fn add_node<T: AudioNode + 'static>(
&mut self,
node: T,
config: Option<T::Configuration>,
) -> NodeID
pub fn add_node<T: AudioNode + 'static>( &mut self, node: T, config: Option<T::Configuration>, ) -> NodeID
Add a node to the audio graph.
Sourcepub fn add_dyn_node<T: DynAudioNode + 'static>(&mut self, node: T) -> NodeID
pub fn add_dyn_node<T: DynAudioNode + 'static>(&mut self, node: T) -> NodeID
Add a node to the audio graph which implements the type-erased DynAudioNode trait.
Sourcepub fn remove_node(
&mut self,
node_id: NodeID,
) -> Result<SmallVec<[EdgeID; 4]>, ()>
pub fn remove_node( &mut self, node_id: NodeID, ) -> Result<SmallVec<[EdgeID; 4]>, ()>
Remove the given node from the audio graph.
This will automatically remove all edges from the graph that were connected to this node.
On success, this returns a list of all edges that were removed from the graph as a result of removing this node.
This will return an error if a node with the given ID does not exist in the graph, or if the ID is of the graph input or graph output node.
Sourcepub fn node_info(&self, id: NodeID) -> Option<&NodeEntry>
pub fn node_info(&self, id: NodeID) -> Option<&NodeEntry>
Get information about a node in the graph.
Sourcepub fn node_state<T: 'static>(&self, id: NodeID) -> Option<&T>
pub fn node_state<T: 'static>(&self, id: NodeID) -> Option<&T>
Get an immutable reference to the custom state of a node.
Sourcepub fn node_state_dyn(&self, id: NodeID) -> Option<&dyn Any>
pub fn node_state_dyn(&self, id: NodeID) -> Option<&dyn Any>
Get a type-erased, immutable reference to the custom state of a node.
Sourcepub fn node_state_mut<T: 'static>(&mut self, id: NodeID) -> Option<&mut T>
pub fn node_state_mut<T: 'static>(&mut self, id: NodeID) -> Option<&mut T>
Get a mutable reference to the custom state of a node.
pub fn node_state_dyn_mut(&mut self, id: NodeID) -> Option<&mut dyn Any>
Sourcepub fn nodes<'a>(&'a self) -> impl Iterator<Item = &'a NodeEntry>
pub fn nodes<'a>(&'a self) -> impl Iterator<Item = &'a NodeEntry>
Get a list of all the existing nodes in the graph.
Sourcepub fn edges<'a>(&'a self) -> impl Iterator<Item = &'a Edge>
pub fn edges<'a>(&'a self) -> impl Iterator<Item = &'a Edge>
Get a list of all the existing edges in the graph.
Sourcepub fn set_graph_channel_config(
&mut self,
channel_config: ChannelConfig,
) -> SmallVec<[EdgeID; 4]>
pub fn set_graph_channel_config( &mut self, channel_config: ChannelConfig, ) -> SmallVec<[EdgeID; 4]>
Set the number of input and output channels to and from the audio graph.
Returns the list of edges that were removed.
Sourcepub fn connect(
&mut self,
src_node: NodeID,
dst_node: NodeID,
ports_src_dst: &[(PortIdx, PortIdx)],
check_for_cycles: bool,
) -> Result<SmallVec<[EdgeID; 4]>, AddEdgeError>
pub fn connect( &mut self, src_node: NodeID, dst_node: NodeID, ports_src_dst: &[(PortIdx, PortIdx)], check_for_cycles: bool, ) -> Result<SmallVec<[EdgeID; 4]>, AddEdgeError>
Add connections (edges) between two nodes to the graph.
src_node- The ID of the source node.dst_node- The ID of the destination node.ports_src_dst- The port indices for each connection to make, where the first value in a tuple is the output port onsrc_node, and the second value in that tuple is the input port ondst_node.check_for_cycles- Iftrue, then this will run a check to see if adding these edges will create a cycle in the graph, and return an error if it does. Note, checking for cycles can be quite expensive, so avoid enabling this when calling this method many times in a row.
If successful, then this returns a list of edge IDs in order.
If this returns an error, then the audio graph has not been modified.
Sourcepub fn disconnect(
&mut self,
src_node: NodeID,
dst_node: NodeID,
ports_src_dst: &[(PortIdx, PortIdx)],
) -> bool
pub fn disconnect( &mut self, src_node: NodeID, dst_node: NodeID, ports_src_dst: &[(PortIdx, PortIdx)], ) -> bool
Remove connections (edges) between two nodes from the graph.
src_node- The ID of the source node.dst_node- The ID of the destination node.ports_src_dst- The port indices for each connection to make, where the first value in a tuple is the output port onsrc_node, and the second value in that tuple is the input port ondst_node.
If none of the edges existed in the graph, then false will be
returned.
Sourcepub fn disconnect_all_between(
&mut self,
src_node: NodeID,
dst_node: NodeID,
) -> SmallVec<[EdgeID; 4]>
pub fn disconnect_all_between( &mut self, src_node: NodeID, dst_node: NodeID, ) -> SmallVec<[EdgeID; 4]>
Remove all connections (edges) between two nodes in the graph.
src_node- The ID of the source node.dst_node- The ID of the destination node.
Sourcepub fn disconnect_by_edge_id(&mut self, edge_id: EdgeID) -> bool
pub fn disconnect_by_edge_id(&mut self, edge_id: EdgeID) -> bool
Remove a connection (edge) via the edge’s unique ID.
If the edge did not exist in this graph, then false will be returned.
Sourcepub fn cycle_detected(&mut self) -> bool
pub fn cycle_detected(&mut self) -> bool
Runs a check to see if a cycle exists in the audio graph.
Note, this method is expensive.
Sourcepub fn queue_event(&mut self, event: NodeEvent)
pub fn queue_event(&mut self, event: NodeEvent)
Queue an event to be sent to an audio node’s processor.
Note, this event will not be sent until the event queue is flushed
in FirewheelCtx::update.
Sourcepub fn queue_event_for(&mut self, node_id: NodeID, event: NodeEventType)
pub fn queue_event_for(&mut self, node_id: NodeID, event: NodeEventType)
Queue an event to be sent to an audio node’s processor.
Note, this event will not be sent until the event queue is flushed
in FirewheelCtx::update.
Source§impl<B: AudioBackend> FirewheelCtx<B>
impl<B: AudioBackend> FirewheelCtx<B>
Sourcepub fn event_queue(&mut self, id: NodeID) -> ContextQueue<'_, B>
pub fn event_queue(&mut self, id: NodeID) -> ContextQueue<'_, B>
Construct an ContextQueue for diffing.