Struct GraphBuilder

Source
pub struct GraphBuilder<S>
where S: Sample,
{ /* private fields */ }
Expand description

Fluent builder for constructing DSP graphs.

Provides methods to add blocks, create connections, and set up modulation. Call build to finalize and prepare the graph.

Implementations§

Source§

impl<S> GraphBuilder<S>
where S: Sample,

Source

pub fn new( sample_rate: f64, buffer_size: usize, num_channels: usize, ) -> GraphBuilder<S>

Create a GraphBuilder that will construct a Graph with a given sample rate, buffer size, and number of channels.

Source

pub fn with_layout( sample_rate: f64, buffer_size: usize, layout: ChannelLayout, ) -> GraphBuilder<S>

Create a GraphBuilder with a specific channel layout.

This constructor sets both the channel count and the layout, which enables layout-aware processing for blocks like panners and decoders.

Source

pub fn add<B>(&mut self, block: B) -> BlockId
where B: Into<BlockType<S>>,

Add a block to the graph.

Accepts any block type that implements Into<BlockType<S>>.

§Example
use bbx_dsp::prelude::*;

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);
let osc = builder.add(OscillatorBlock::new(440.0, Waveform::Sine, None));
let gain = builder.add(GainBlock::new(-6.0, None));
builder.connect(osc, 0, gain, 0);
let graph = builder.build();
Source

pub fn connect( &mut self, from: BlockId, from_output: usize, to: BlockId, to_input: usize, ) -> &mut GraphBuilder<S>

Form a Connection between two particular blocks.

Source

pub fn modulate( &mut self, source: BlockId, target: BlockId, parameter: &str, ) -> &mut GraphBuilder<S>

Specify a Parameter to be modulated by a Modulator block.

Source

pub fn capture_topology(&self) -> GraphTopologySnapshot

Capture a snapshot of the current graph topology for visualization.

Returns owned data suitable for cross-thread transfer to a visualization thread. Call this before build() to capture the user-defined topology (the output block is added during build).

Source

pub fn build(self) -> Graph<S>

Prepare the final DSP Graph.

Automatically inserts a mixer before the output block when multiple terminal blocks exist, unless the developer has already provided their own mixer or output block connections.

§Panics

Panics if any block has more inputs or outputs than the realtime-safe limits (MAX_BLOCK_INPUTS or MAX_BLOCK_OUTPUTS).

Auto Trait Implementations§

§

impl<S> Freeze for GraphBuilder<S>

§

impl<S> !RefUnwindSafe for GraphBuilder<S>

§

impl<S> Send for GraphBuilder<S>

§

impl<S> Sync for GraphBuilder<S>

§

impl<S> Unpin for GraphBuilder<S>
where S: Unpin,

§

impl<S> !UnwindSafe for GraphBuilder<S>

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.