pub struct Graph { /* private fields */ }Expand description
A directed audio processor graph: nodes plus the cables between their ports.
Build a graph by adding nodes and connecting ports, prepare
it with a sample rate and block size, then render deterministic blocks with
process_offline. Nodes are processed in
topological order; cycles are rejected at connect time.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn add_node(
&mut self,
id: impl Into<String>,
processor: Box<dyn Processor>,
in_channels: u16,
out_channels: u16,
) -> Result<()>
pub fn add_node( &mut self, id: impl Into<String>, processor: Box<dyn Processor>, in_channels: u16, out_channels: u16, ) -> Result<()>
Adds a processor node with the given id and channel counts.
Fails if the id is empty or already present. Adding a node clears any
prepared state, requiring a fresh prepare.
Sourcepub fn connect(&mut self, from: PortUri, to: PortUri) -> Result<()>
pub fn connect(&mut self, from: PortUri, to: PortUri) -> Result<()>
Connects an output port to an input port.
Validates both endpoints and their rate contracts, and rejects the cable if it would introduce a cycle.
Sourcepub fn prepare(
&mut self,
sample_rate_hz: u32,
max_block_frames: u32,
) -> Result<()>
pub fn prepare( &mut self, sample_rate_hz: u32, max_block_frames: u32, ) -> Result<()>
Prepares every node for the given sample rate and maximum block size, sizing the scratch arena. Fails on a zero rate/size or a graph cycle.
Sourcepub fn process_offline(
&mut self,
input: &[Vec<f32>],
frames: u32,
) -> Result<Vec<Vec<f32>>>
pub fn process_offline( &mut self, input: &[Vec<f32>], frames: u32, ) -> Result<Vec<Vec<f32>>>
Renders one block offline, feeding input lanes to the source nodes and
returning the output node’s channel buffers.
Requires a prepared graph and frames no larger than the prepared block
size; each input lane must hold at least frames samples.
Sourcepub fn patch_nodes(&self) -> Vec<PatchNode>
pub fn patch_nodes(&self) -> Vec<PatchNode>
Returns the graph’s nodes as portable PatchNode records.
Sourcepub fn topological_node_order(&self) -> Result<Vec<String>>
pub fn topological_node_order(&self) -> Result<Vec<String>>
Returns the node ids in a stable topological order, failing on a cycle.
Sourcepub fn node_descriptor(&self, id: &str) -> Result<&ProcessorDescriptor>
pub fn node_descriptor(&self, id: &str) -> Result<&ProcessorDescriptor>
Returns the processor descriptor for a node, or an error if unknown.