Leyline audio graph illustration

Leyline

A realtime audio graph with delay compensation, and a compiler from an edit model to a graph.

Leyline is the component that routes and processes audio through a graph of nodes in realtime. It is part of Signals & Sorcery, a coherent set of Rust audio building blocks for audio apps, plugins, players and DAWs.

Repositorygithub.com/shiehn/leyline-audio-graph
LicenseMIT, free for commercial and closed-source use
StatusPlanned
LayerSignal flow (how the layers stack)
Crates (planned names)leyline

What it is

A graph describes nodes (a sampler, a plugin chain, a fader, a bus) and the connections between them. Leyline turns that description into something the audio thread can run every block, then keeps it running while the description changes.

  • Compile. A description becomes a schedule: nodes in an order that respects every connection, buffers assigned to slots so memory is reused, and parallel levels where nodes don't depend on each other.
  • Plugin delay compensation. Each node reports its latency, and Leyline adds the delays that keep every path to a mixing point aligned.
  • Incremental recompile. Nodes are matched by a stable identity you give them, so a reverb's tail, a compressor's envelope or a sampler's voices survive a change.
  • Lock-free publish. The new schedule reaches the audio thread through a mailbox and is swapped in at a block boundary. The old one is retired on a control thread.
  • Parameter commands travel on a ring and land at a sample offset.
  • One code path for live and offline, so a bounce matches what you heard.
  • The edit-model compiler. A separate, swappable, pure function turns a mixer description (channels, folders, sends, plugin chains) into a graph description. Leyline defines that description, so Tapestry or any other model can produce one.

Usage example

Illustrative sketch

Planned, not final. Taken from the READMEopen in new window.

use leyline::{GraphDesc, Node, NodeId, PrepareCfg, ProcessIo, BlockCtx};

// A custom node: prepared on a control thread, processed on the audio thread.
struct Tremolo { phase: f32, rate: f32 }

impl Node for Tremolo {
    fn prepare(&mut self, cfg: &PrepareCfg) { /* may allocate here */ }
    fn latency(&self) -> u32 { 0 }
    fn process(&mut self, io: &mut ProcessIo<'_>, ctx: &BlockCtx) {
        // audio thread: no allocation, no lock, no system call
    }
}

let mut desc = GraphDesc::new();
let player = desc.add(NodeId::from("track-1/player"), sampler_node);
let trem = desc.add(NodeId::from("track-1/tremolo"), Box::new(Tremolo::new()));
desc.connect(player, trem);
desc.connect(trem, desc.output());

let mut graph = leyline::Graph::new(48_000.0, 256);
graph.publish(&desc)?;              // compile, diff against the running schedule, hand it over

// Later, offline, with the same description:
let wav = graph.render_offline(&desc, 0..total_frames)?;

How it fits in the ecosystem

Leyline is the signal flow row. Dependencies point down, never up.

Below it: its core depends only on the floor: Runecraft (repoopen in new window) for the handoffs and arena, and Orrery (repoopen in new window) for transports. Its built-in mixer nodes wrap Cantrips (repoopen in new window), and an optional adapter turns a Summoner (repoopen in new window) chain into a plugin node, so the graph's own code names neither. It runs inside a device callback such as Aethergate's (repoopen in new window).

Above it:

What it deliberately doesn't do: no tracks or clips (those are Tapestry's, and the compiler between them is replaceable), no scheduling of musical events (Procession's job), no devices, and no large DSP library (fundsp, dasp and others are welcome as custom nodes).

Extend and display
The engine
Musical structure
Signal flow
ComponentRepositoryRoleStatus
Runecraftrunecraft-audio-coreShared contracts, realtime safety, process isolation and realtime-safe logging: the floor every other component stands onIn preparation
Orreryorrery-musical-timeTempo and meter, transports, bar, beat and sample maths, timed MIDIIn preparation
Summonersummoner-plugin-hostOut-of-process VST3 and Audio Unit plugin hosting with crash isolationIn preparation
Aethergateaethergate-audio-platformAudio devices (cpal, CoreAudio, a fake device for tests) and shared-memory metersPlanned
Leylineleyline-audio-graphA realtime audio graph with delay compensation, and a compiler from an edit model to a graphPlanned
Cantripscantrips-audio-dspBuilt-in mixer DSP: sampler, fader, pan, meters, compressorPlanned
Scriptoriumscriptorium-audio-mediaDecode and encode, a sample store, streaming voices, crash-safe recordingPlanned
Tapestrytapestry-session-modelTracks, clips, lanes and scenes; edits with undo; a crash-safe project storePlanned
Processionprocession-timeline-engineWhat plays in each block: regions, notes, automation, launchesPlanned
Grimoiregrimoire-daw-engineThe assembled engine and its headless JSON-RPC protocolPlanned
Familiarfamiliar-plugin-sdkAn SDK for plugins and panels that extend a Signals & Sorcery enginePlanned
Glyphworkglyphwork-audio-uiAudio UI widgets: meters, knobs, faders, waveformsPlanned

Status

Planned. No code yet. The repositoryopen in new window holds the design.

Target platforms: macOS, Windows and Linux. Running a graph inside a Web Audio worklet through WebAssembly is a later exploration.

Last Updated:
Contributors: shiehn