pub struct GraphBuilder<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: Sample> GraphBuilder<S>
impl<S: Sample> GraphBuilder<S>
Sourcepub fn new(sample_rate: f64, buffer_size: usize, num_channels: usize) -> Self
pub fn new(sample_rate: f64, buffer_size: usize, num_channels: usize) -> Self
Create a GraphBuilder that will construct a Graph with a given
sample rate, buffer size, and number of channels.
Sourcepub fn with_layout(
sample_rate: f64,
buffer_size: usize,
layout: ChannelLayout,
) -> Self
pub fn with_layout( sample_rate: f64, buffer_size: usize, layout: ChannelLayout, ) -> Self
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.
Sourcepub fn add<B: Into<BlockType<S>>>(&mut self, block: B) -> BlockId
pub fn add<B: Into<BlockType<S>>>(&mut self, block: B) -> BlockId
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();Sourcepub fn connect(
&mut self,
from: BlockId,
from_output: usize,
to: BlockId,
to_input: usize,
) -> &mut Self
pub fn connect( &mut self, from: BlockId, from_output: usize, to: BlockId, to_input: usize, ) -> &mut Self
Form a Connection between two particular blocks.
Sourcepub fn modulate(
&mut self,
source: BlockId,
target: BlockId,
parameter: &str,
) -> &mut Self
pub fn modulate( &mut self, source: BlockId, target: BlockId, parameter: &str, ) -> &mut Self
Specify a Parameter to be modulated by a Modulator block.
Sourcepub fn capture_topology(&self) -> GraphTopologySnapshot
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).
Sourcepub fn build(self) -> Graph<S>
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).