Module knyst::graph

source ·
Expand description

Graph is the audio graph, the core of Knyst. Implement Gen and you can be a Node.

To build an audio graph, add generators (anything implementing the Gen trait) to a graph and add connections between them.

let graph_settings = GraphSettings {
    block_size: 64,
    sample_rate: 44100.,
    num_outputs: 2,
    ..Default::default()
};
let mut graph = Graph::new(graph_settings);
// Adding a node gives you an address to that node
let sine_node_address = graph.push(WavetableOscillatorOwned::new(Wavetable::sine()));
// Connecting the node to the graph output
graph.connect(sine_node_address.to_graph_out())?;
// You need to commit changes if the graph is running.
graph.commit_changes();

To produce an output from the Graph we need to turn it into a node. If you want to listen to the graph output the easiest way is to use and audio backend. Have a look at RunGraph if you want to do non-realtime synthesis or implement your own backend.

Re-exports

Modules

  • Connecting nodes/Gens in a Graph is fundamentally done through a Connection. Additionally, a NodeId has convenience functions to generate Connections and the ConnectionBundle API is often more convenient and ergonomic.
  • Provides the RunGraph struct which safely wraps a running Graph and provides access to its outputs. Used internally by implementations of AudioBackend, but it can also be used directly for custom environments or for offline processing.

Structs

  • Convenience struct to create a Gen from a closure.
  • A Graph contains nodes, which are wrappers around a dyn Gen, and connections between those nodes. Connections can eiterh be normal/forward connections or feedback connections. Graphs can themselves be used as Gens in a different Graph.
  • Convenience struct for the notation GraphInput::to(node)
  • Pass to Graph::new to set the options the Graph is created with in an ergonomic and clear way.
  • Multiply two inputs together and produce one output.
  • Handle to a Mult.
  • Handle to a NaiveSine.
  • Multiple changes to the input values of a certain node. See Change for what kinds of changes can be scheduled. All methods return Self so it can be chained:
  • A handle to an address to a specific node. This handle will be updated with the node key and the graph id once those are available. This means that a handle can be created before the node is inserted into a Graph
  • A parameter (input constant) change to be scheduled on a Graph.
  • An address to a specific Node. The graph_id is constant indepentently of where the graph is (inside some other graph), so it always points to a specific Node in a specific Graph.
  • Bundle multiple changes to multiple nodes. This is usually required to be certain that they get applied in the same frame, except if using absolute time.

Enums

Traits

  • This trait is not meant to be implemented by users. In almost all situations you instead want to implement the Gen trait.

Functions

Type Aliases

  • The graph consists of (simplified)