pub struct Processor<G>where
G: Visitable,{ /* private fields */ }Expand description
State related to the processing of an audio graph of type G.
The Processor allows for the re-use of resources related to traversal and requesting audio from the graph. This makes it easier to avoid dynamic allocation within a high-priority audio context.
§Example
use dasp_graph::{Node, NodeData};
use petgraph;
// Chose a type of graph for audio processing.
type Graph = petgraph::graph::DiGraph<NodeData<MyNode>, (), u32>;
// Create a short-hand for our processor type.
type Processor = dasp_graph::Processor<Graph>;
fn main() {
// Create a graph and a processor with some suitable capacity to avoid dynamic allocation.
let max_nodes = 1024;
let max_edges = 1024;
let mut g = Graph::with_capacity(max_nodes, max_edges);
let mut p = Processor::with_capacity(max_nodes);
// Add some nodes and edges...
// Process all nodes within the graph that output to the node at `n_id`.
p.process(&mut g, n_id);
}Implementations§
Source§impl<G> Processor<G>where
G: Visitable,
impl<G> Processor<G>where
G: Visitable,
Sourcepub fn with_capacity(max_nodes: usize) -> Self
pub fn with_capacity(max_nodes: usize) -> Self
Construct a new graph processor from the given maximum anticipated node count.
As long as this node count is not exceeded, the Processor should never require dynamic allocation following construction.
Sourcepub fn process<T>(&mut self, graph: &mut G, node: G::NodeId)where
G: Data<NodeWeight = NodeData<T>> + DataMapMut,
for<'a> &'a G: GraphBase<NodeId = G::NodeId> + IntoNeighborsDirected,
T: Node,
pub fn process<T>(&mut self, graph: &mut G, node: G::NodeId)where
G: Data<NodeWeight = NodeData<T>> + DataMapMut,
for<'a> &'a G: GraphBase<NodeId = G::NodeId> + IntoNeighborsDirected,
T: Node,
Process audio through the subgraph ending at the node with the given ID.
Specifically, this traverses nodes in depth-first-search post order where the edges of
the graph are reversed. This is equivalent to the topological order of all nodes that are
connected to the inputs of the given node. This ensures that all inputs of each node are
visited before the node itself.
The Node::process method is called on each node as they are visited in the traversal.
Upon returning, the buffers of each visited node will contain the audio processed by their respective nodes.
Supports all graphs that implement the necessary petgraph traits and whose nodes are of
type NodeData<T> where T implements the Node trait.
Panics if there is no node for the given index.