wavegraph 0.1.1

Run text patches as a remotely controlled WaveGraph audio engine
# wavegraph

[![crates.io][crate-badge]][crate]
[![Build status][ci-badge]][ci]

Play a WaveGraph text patch on macOS, 64-bit Linux or Windows. The included
[3389 patch](patches/3389.wg) has two TB-303s, a TR-808 and a TR-909. Its four
channels each have two insert slots and beat effects. The isolated 909 kick feeds the sidechain inputs.
The mixer routes the dry mix, reverb and delay to a stereo master.

The DSP library published as `wavegraph` 0.1.0 now lives in [`wavegraph-core`][core-crate].

## Play a patch

Building the host requires Rust 1.95 or later. On Debian or Ubuntu, install
`libasound2-dev` and `pkg-config` before building.
On macOS 14.2 or later and on Windows, the Rust toolchain and platform SDK
provide the build dependencies. Install the host from crates.io and start the
bundled 3389 rack.

```sh
cargo install --locked wavegraph
wavegraph
```

You can also run a patch directly from a workspace checkout.

```sh
cargo run --release --locked -p wavegraph -- wavegraph/patches/3389.wg
```

Omit the filename to play the bundled copy of 3389. Use `--tempo 128`
to change the tempo from the default 122 BPM, or `--list-outputs` to
list output devices and see the current default. Ctrl-C exits.

## Control the patch with wr

On Unix, the host listens on a per-user socket by default. In a second
terminal, install and run the client.

```sh
cargo install --locked wavegraph-remote
wr
```

To run another host, give both it and its client the same `--socket PATH`.
Use `wavegraph --no-socket` for standalone playback.

At the `wr` prompt, try

```text
graph
select acid
cc 74 95
select strip1
cc 84 127
stop
play
```

CC 74 changes the first 303's cutoff. CC 84 enables the first strip's slicer.
`play` restarts the sequences on step one. The patch keeps playing when a
client disconnects. See the [effect controls](effects.md) and the
[wr guide](../wavegraph-remote/) for the other commands.

## Playback logs

By default the host logs playback settings, the socket path and output device
at `INFO` on stderr. It also logs commands received from `wr` at `INFO`.
Each connection has its own ID. MIDI events show the decoded command and its
arguments. Graph queries include the request ID and whether the first audio
block has been accepted.

Use `-q` or `--quiet` to suppress remote traffic while retaining playback
status and warnings.

```sh
cargo run --release --locked -p wavegraph -- -q
```

`RUST_LOG` controls the overall level and accepts module filters, such as
`RUST_LOG=warn,wavegraph::audio=info`. The quiet flag also applies when
`RUST_LOG` enables verbose output. A background thread writes the logs and
can drop lines if stderr falls behind.

## Write a patch

This patch plays four sixteenth-note steps on a 303 and sends its output to
both speakers at half gain.

```text
node acid tb303 ch=1 wave=square steps=38!,-,45,-
gain trim acid.out 64
output left trim.out
output right trim.out
```

Each comma advances one sixteenth. A dash is a rest. An exclamation mark
accents a bass note or 808 hit. A drum step can combine hits, for example
`36+42`. A node with `ch=1` through `ch=16` accepts MIDI on that channel.
The [compiler grammar](../wavegraph-compiler/) describes signal connections,
gains, mixes and stereo output selection.

The FM-1 builds its [factory graph](../wavegraph-fm1/assets/rack/graph.wg)
with the same compiler. Each host supplies its own native objects. The FM-1
binds four assignable channel players and one insert rack. The desktop patch
names each instrument and strip separately. For remote discovery, use
alphanumeric node aliases of up to 32 characters.

Pass `--check FILE.wg` to compile and bind the patch without opening an audio
device. `--headless` runs the DSP at playback speed with a clocked null output.
Restart the host to pick up edits to a file.

## DSP and device playback

The DSP thread owns the bound program, instruments, effects and signal buses.
It renders 128 stereo Q23 frames at 44.1 kHz, the source rate of the 909
cymbals. The sequencer places note events at sample offsets within each block.
Live MIDI commands enter at the next render boundary.

A Tokio current-thread runtime services the audio port and optional Unix
listener. A bounded channel holds two rendered blocks. When the output queue
fills, the host retains the pending block and the DSP thread waits once the
channel fills. The same backpressure pauses the sample clock if the output
goes offline.

[`wavegraph-audio`](../wavegraph-audio/) follows the default output and converts
the graph's PCM to the device format and sample rate. CPAL drives the device
callback through CoreAudio on macOS, ALSA on Linux and WASAPI on Windows.
The host publishes the graph to `wr` after the output accepts its first
block. Each native object reports its actual ports, and the graph includes
the compiled program and both output bus bindings.

## License

Licensed under either [Apache License, Version 2.0](LICENSE-APACHE) or
[MIT License](LICENSE-MIT) at your option.

[crate-badge]: https://img.shields.io/crates/v/wavegraph?logo=rust
[crate]: https://crates.io/crates/wavegraph
[core-crate]: https://crates.io/crates/wavegraph-core
[ci-badge]: https://github.com/fm1-rust/wavegraph/actions/workflows/wavegraph.yml/badge.svg?branch=main&event=push
[ci]: https://github.com/fm1-rust/wavegraph/actions/workflows/wavegraph.yml