Skip to main content

Crate wavegraph_compiler

Crate wavegraph_compiler 

Source
Expand description

§wavegraph-compiler

crates.io docs.rs Build status Project Chat

Compile a WaveGraph Language (WGL) patch (.wg) to signal bytecode. The caller supplies a catalog of native object types and their named signal ports. The compiler returns the bytecode, the native object declarations in binding order, and the left and right output bus IDs. It supports no_std with alloc.

This patch averages a stereo input on the left output and sends the original right channel to the right output. The render test compiles the patch file and checks both channels through the wavegraph-dsp interpreter.

node input stereo
gain halfLeft input.left 64
gain halfRight input.right 64
mix mono halfLeft.out halfRight.out
output left mono.out
output right input.right

§Language

Write one statement per line. Whitespace separates tokens. A # anywhere starts a comment that runs to the end of the line. Blank lines are ignored. Object aliases start with an ASCII letter and can contain ASCII letters, digits and underscores. Aliases and port names are case-sensitive. In a port reference, the first dot separates the alias from the catalog’s port name.

StatementMeaning
node NAME TYPE [KEY=VALUE ...]Declare a native object. The caller interprets its constructor options.
connect SOURCE.OUTLET DESTINATION.INLETConnect a named signal outlet to a named signal inlet. Each inlet takes one source. An outlet can feed several inlets.
gain NAME SOURCE.OUTLET LEVELScale a signal by LEVEL/128 (0–255). The result is NAME.out.
mix NAME A.OUTLET B.OUTLETSum two signals with saturation. The result is NAME.out.
output left SOURCE.OUTLET, output right SOURCE.OUTLETBind the two physical outputs. Both can use the same bus.

Connections may precede declarations. Native object IDs follow declaration order. The compiler schedules producers before consumers, breaking ties by declaration order. An invalid connection, an undriven inlet, or a signal cycle produces a diagnostic with a source line. The bytecode can address 256 native objects and 256 signal buses.

On a node line, each option occupies one token. Its first = separates a nonempty key and value. Each key may appear once per node. The compiler passes options to the host in source order. For example, the desktop sequencer reads steps=36!+39,42,- as an accented 36 together with 39, then 42, then a rest. Both left and right outputs must be bound exactly once per patch.

See the grammar design notes for the rationale behind the syntax and the PEG parser.

use wavegraph_compiler::{NodeSpec, compile};

let source = "node source input\ngain half source.out 64\noutput left source.out\noutput right half.out";
let patch = compile(source, |kind| {
    (kind == "input").then_some(NodeSpec { inputs: &[], outputs: &["out"] })
})?;
assert_eq!(patch.nodes[0].alias, "source");
assert_eq!(patch.outputs, [0, 1]);

§License

The Rust code is licensed under either of

at your option.

§Contribution

Unless you explicitly state otherwise, you license any contribution you intentionally submit for inclusion in this work (as defined in the Apache-2.0 license) under both licenses above, without additional terms or conditions.

Structs§

CompileError
An error in a patch source file.
CompiledPatch
A signal schedule and the host bindings needed to run it.
Node
One native instance in the compiled program’s object table.
NodeSpec
Signal inlet and outlet names in the order declared by a native processor. Names must be distinct within each direction and addressable as patch tokens.

Functions§

compile
Compile source text against a catalog of available processor types.