# audio_graph
DAG-based audio processing graph for DAW applications in Rust. Connects instruments, effects and buses with typed ports and automatic topological scheduling.
## Features
- **Typed ports** — Audio, MIDI and Control ports per node, validated at connection time
- **DAG scheduling** — Kahn's algorithm computes the correct processing order automatically
- **Parallel groups** — independent nodes are grouped for concurrent execution (rayon-ready)
- **Cycle detection** — connecting nodes that would create a feedback loop returns an error
- **Dynamic graph** — add and remove nodes and connections at runtime
- **Lock-free routing** — buffer routing between nodes uses no allocations per block
## Usage
```rust
use audio_graph::{AudioGraph, Node, ProcessContext};
use audio_graph::port::{Port, PortType};
use audio_graph::port::PortId;
struct MySynth;
impl Node for MySynth {
fn ports(&self) -> Vec<Port> {
vec![
Port::midi_in(0, "midi_in"),
Port::audio_out(0, "out_l"),
Port::audio_out(1, "out_r"),
]
}
fn process(&mut self, ctx: &mut ProcessContext) {
// read MIDI, write audio
}
}
let mut graph = AudioGraph::new(44100.0, 512);
let synth = graph.add_node(Box::new(MySynth));
let filter = graph.add_node(Box::new(MyFilter));
graph.connect(synth, PortId(0), filter, PortId(0), PortType::Audio)?;
graph.process_block(); // executes in correct topological order
```
## Signal types
| `Audio` | `AudioBuffer` (f32, non-interleaved) | Instrument and effect audio |
| `Midi` | `MidiBuffer` (events with sample offset) | Note and CC events |
| `Control` | `ControlBuffer` (f32 per frame) | Parameter automation |
## Part of the DAW crate ecosystem
```
audio_core_dsp
midi_clock_sync
audio_graph ← you are here
event_queue
mixer
piano_roll
plugin_host
project_io
```
## License
MIT