Skip to main content

Graph

Struct Graph 

Source
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

Source

pub fn new() -> Self

Creates an empty graph.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn to_patch(&self) -> Patch

Returns the graph as a portable Patch of nodes and cables.

Source

pub fn cables(&self) -> &[Cable]

Returns the graph’s cables.

Source

pub fn patch_nodes(&self) -> Vec<PatchNode>

Returns the graph’s nodes as portable PatchNode records.

Source

pub fn topological_node_order(&self) -> Result<Vec<String>>

Returns the node ids in a stable topological order, failing on a cycle.

Source

pub fn node_descriptor(&self, id: &str) -> Result<&ProcessorDescriptor>

Returns the processor descriptor for a node, or an error if unknown.

Trait Implementations§

Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Graph

§

impl !Sync for Graph

§

impl !UnwindSafe for Graph

§

impl Freeze for Graph

§

impl Send for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.