Contents

class

SushiDSP::RigGraph

A user-editable directed graph of IAudioNode instances, compiled to a topological order and replayed per block.

Declared in
include/SushiDSP/core/RigGraph.hpp

Static public attributes

static constexpr std::size_t kParameterRingCapacity = 1024

Maximum parameter changes that may be pending between two process() calls.

static constexpr std::size_t kMaxFanInOut = 8

Maximum outgoing edges from, or incoming edges into, any single node.

Bounds the fixed-size input-gather array RigGraph::process() uses per node.

static constexpr std::uint32_t kMaxChannels = 2

Maximum channels a node may declare on either side of its PortLayout.

Bounds every fixed-size per-channel array RigGraph::process() uses.

Static public member functions

static bool channels_adapt(std::uint32_t from_channels, std::uint32_t to_channels)

Reports whether the adaptation table covers a producer/consumer channel pair.

The table is 1 into 2 (copied), 2 into 1 (summed and halved), and n into n.

Parameters

from_channels

The producer's channel count.

to_channels

The consumer's channel count.

Returns

False when the pair has no rule, which compile() turns into a refusal.

Public member functions

RigGraph(std::uint32_t block_size, std::uint32_t max_live_buffers)

Constructs an empty rig graph.

Parameters

block_size

Frames per process() call.

max_live_buffers

Maximum transient buffers live at once during a block.

NodeHandle add_node(std::unique_ptr< IAudioNode > node)

Adds a node to the graph, unconnected.

Not real-time safe; call only off the processing thread.

Parameters

node

The node to take ownership of.

Returns

A handle identifying the node for connect() calls.

void connect(NodeHandle from, NodeHandle to)

Connects one node's output to another's input.

Not real-time safe.

Parameters

from

The upstream node.

to

The downstream node.

void compile(const PrepareInfo &info)

Topologically sorts the graph and calls prepare() on every node.

Not real-time safe; call after every add_node/connect.

Parameters

info

Sample rate, block size, and channel count for every node.

void remove_node(NodeHandle handle)

Removes a node and every edge touching it.

Not real-time safe; call only off the processing thread. The handle becomes invalid; other handles are unaffected.

Parameters

handle

The node to remove.

void disconnect(NodeHandle from, NodeHandle to)

Removes a single edge, if present.

Not real-time safe.

Parameters

from

The upstream node.

to

The downstream node.

IAudioNode * node(NodeHandle handle) const

Looks up a live node by handle.

Parameters

handle

The node's handle.

Returns

The node, or nullptr if handle is out of range or was removed.

std::vector< NodeHandle > nodes() const

Lists every live (non-removed) node handle, in add_node() order.

Returns

The live handles.

bool is_empty() const noexcept

Reports whether compile() produced an empty schedule, i.e.

the graph holds no live node and process() would write nothing. Real-time safe: reads one vector's size and allocates nothing.

Returns

True when process() would write nothing.

std::vector< NodeHandle > upstream_of(NodeHandle handle) const

Lists the handles of every node with an edge into handle, in connect() call order.

Not real-time safe; call only off the processing thread.

Parameters

handle

The downstream node to query.

Returns

The upstream handles, or an empty vector if handle has no upstream edge.

bool push_parameter_change(const ParameterChange &change)

Queues a parameter write for the next process() call.

Control thread only; lock-free and allocation-free.

Parameters

change

The node, parameter index, and value to apply.

Returns

true if queued, false if the ring is full and the change was dropped.

void process(ProcessContext &context)

Processes one block through every node in topological order.

Real-time safe.

Parameters

context

The block's output buffers and frame count.

std::uint32_t latency_samples() const

Longest path through the compiled graph, in base-rate samples: a node's latency plus the largest latency among its upstream paths, taken at the sink.

Allocation-free; call after compile(), which caches the value.

Returns

Total latency in base-rate samples.

std::uint32_t live_buffer_count() const

Reports the single-channel buffers the compiled graph needs live at once: one per node output channel, plus the reserve the edge adaptation borrows while gathering one node's inputs.

compile() sizes buffer_pool_ from it; a host may read it to size its own pool. Valid only after a successful compile().

Returns

The buffer count.