Expand description
§wavegraph-remote
A Rust client for MIDI control and live graph discovery. It includes the
wr command by default. The same client operates a local wavegraph host
over a Unix socket or an FM-1 over USB MIDI.
The client sends MIDI notes, controllers, Start and Stop, and queries the running graph. On the FM-1, install the WaveGraph firmware for graph discovery and Start/Stop. Ordinary note and CC commands also work with earlier MIDI firmware.
§Features
| Features | Contents |
|---|---|
cli (default) | wr and the host client, with local socket support on Unix |
fm1 | Adds wr --fm1 and the fm1-usb MIDI transport |
std | Transport-independent host client and UnixTransport on Unix |
usb | Adds UsbTransport to the host library |
socket-cli | Alias for cli |
| No features | Bounded, allocation-free no_std protocol types and codecs for firmware |
Terminal I/O, REPL state and note audition timing live under src/bin/.
§CLI
On Unix, start the local DSP host. In a second terminal, install
wr from crates.io and run it.
cargo install --locked wavegraph-remote
wr play
wr stop
wr graph
wr --channel 3 note 36 100 250
wrBoth processes use $XDG_RUNTIME_DIR/wavegraph.sock when the runtime directory
is absolute, otherwise ~/.wavegraph.sock. Pass --socket PATH to both to
select a different socket.
To control an FM-1, build with the fm1 feature and pass --fm1. On
Debian/Ubuntu, install pkg-config and libasound2-dev before building
this feature. macOS uses CoreMIDI.
cargo install --locked --features fm1 wavegraph-remote
wr --fm1 graph
wr --fm1 --port "WaveGraph FM-1"--fm1 discovers an attached device. Add --port to select a MIDI port by
name or an unambiguous substring. With either transport, --timeout 2 sets
the graph response timeout in seconds. wr --help and wr help work offline.
The local socket carries one complete MIDI message per frame. A one-byte length prefix counts the following 1 through 112 bytes. Notes, controllers, transport commands and graph discovery use the same MIDI bytes as the USB endpoint.
With no command, wr opens a REPL. Use Up and Down to recall commands from
the current terminal session, and Left and Right to edit before pressing Enter.
This FM-1 session selects the tb303 instance listed by nodes.
wr[ch1]> nodes
wr[ch1]> select tb303
Selected tb303 on channel 3. Selection follows the channel if its instrument changes.
wr[ch3]> note 36 100 250
wr[ch3]> cc 74 90
wr[ch3]> inspect tb303
wr[ch3]> graph
wr[ch3]> quitThe channel in that example depends on the running assignments. select ALIAS
queries the current graph, resolves the alias and selects its channel. Later
commands keep addressing that channel; swapping its instrument does not silently
move the selection to another instance. select 3 and channel 3 select a
channel directly. Channels are numbered 1 through 16 in the host API and CLI;
the current FM-1 binds its four tracks to channels 1–4.
| Command | Behavior |
|---|---|
graph | Print the snapshot revision, native nodes, signal connections and outputs |
nodes / instruments | List instance aliases, types and MIDI channels |
inspect ALIAS | Print a node’s identity, channel and ordered signal/message ports |
select ALIAS / select CHANNEL | Select an instance’s current channel or a channel number |
channel [NUMBER] | Show or change the selected channel |
play / stop | Send MIDI Start (restart from the beginning) / Stop |
note NOTE [VELOCITY] [MILLISECONDS] | Audition a note; defaults to velocity 100 and 250 ms |
on NOTE [VELOCITY] / off NOTE | Send an individual note-on / note-off |
cc CONTROLLER VALUE | Send a MIDI control change on the selected channel |
panic | Send All Notes Off (CC 123) on the selected channel |
help / quit | Show commands / leave the REPL |
Notes and controllers use MIDI numbers 0–127; note-on velocity is 1–127.
note duration is timed by the host and is not sample-accurate scheduling.
MIDI Continue is not implemented. Ordinary MIDI sends report submission to the
transport, without a receipt confirming that the DSP applied the event.
On quit, EOF (Ctrl-D on an empty line), or Ctrl-C at the prompt, the REPL
releases the notes it started on their original channels even if the selection
changed. Abrupt process termination does not run this cleanup.
One-shot wr on intentionally leaves the note held for a later
wr off or wr panic. Input can also be piped into the REPL; prompts appear only
on an interactive terminal. Parse or command errors are printed and the REPL
continues; one-shot failures return a nonzero exit status.
§Library
use core::time::Duration;
use wavegraph_remote::{Client, MidiCommand, UsbTransport};
let timeout = Duration::from_secs(2);
let transport = UsbTransport::connect(None, timeout)?;
let mut remote = Client::new(transport);
let graph = remote.graph(timeout)?;
for node in &graph.nodes {
println!("{}: {} ({:?})", node.alias, node.kind, node.midi_channel);
}
if let Some(channel) = graph.node("tb303").and_then(|node| node.midi_channel) {
remote.send(MidiCommand::ControlChange {
channel,
controller: 74,
value: 90,
})?;
}
for edge in graph.connections()? {
println!("{} -> {}", edge.source, edge.destination);
}Client<T> owns any implementation of Transport. Its two operations send a
complete MIDI message and receive a complete message with a bounded wait.
Disable default features and enable std for the library alone, or usb
to include the FM-1 transport. Each transport handles its own framing,
connection lifetime and receive timeout.
§What a snapshot describes
The firmware publishes a topology revision only after an audio block using that configuration is accepted by the DAC. Each query retains one coherent copy for its entire response, even if the panel changes assignments during the transfer. The snapshot contains the nine native processes: four instrument players, the insert rack, mixer, reverb, delay and stereo master. Internal DSP inside each native process remains opaque.
Instrument aliases are short alphanumeric labels such as tb303, organ and
tr909. Duplicate types receive numeric suffixes (tb303, tb3032, …), in
channel order. Aliases are unique in a snapshot and can change after a swap.
Node::id is the object-table index; generation distinguishes instrument
assignments within the session. Neither an alias nor a channel is a persistent
instrument identity.
Graph::connections() reconstructs the signal connections from the actual
bytecode and ordered native port declarations. Port numbers include message
ports, so a signal after a message port keeps its true local index. Built-in
gain and mix operations get synthetic @gainN / @mixN labels. The active
output bindings include the firmware’s optional half-gain path. MIDI channels
are listed separately; arbitrary message-cord topology is not encoded in v1.
session is the target’s USB connection epoch, not a globally unique boot ID.
revision changes on instrument assignment/generation or signal-routing changes,
including half gain; CC values and playback do not increment it. first_frame
identifies the first accepted audio block for that revision, not the current
playhead. Reconnect and query again after losing the transport.
§Protocol and scope
Performance commands use ordinary MIDI messages. Discovery uses versioned SysEx
records in the development/noncommercial 0x7d namespace, prefixed with WG.
Each record carries a 32-bit request ID. The record sequence is Query, Begin,
Node records, contiguous bytecode chunks, then End; Error reports a target
rejection. Binary payloads use seven-bit packing. protocol exposes the shared
types and codecs so firmware and host use the same wire format.
A trusted desktop control stream can also accept an engine shutdown request.
Use Client::request_shutdown() or send a payload-free SysEx record of kind
7 with the usual request ID. For example, request 1 on a socket is
0C F0 7D 57 47 01 07 01 00 00 00 00 F7 in hexadecimal, including its
length prefix. An enabled host closes the stream and stops audio and DSP. The
embedding application can join the workers through its local handle. Ordinary
desktop RPC endpoints return Unsupported unless enabled with
Rpc::with_shutdown(). Existing FM-1 firmware ignores this record. MIDI Stop
continues to control just the musical transport.
The firmware uses fixed buffers and preserves partially accepted USB writes. Other outgoing MIDI and logs can run between complete discovery records. The client applies a total query deadline and rejects incomplete, duplicated, reordered or malformed snapshots. It ignores ordinary MIDI and other requests’ replies. The USB receive queue is bounded and reports overflow rather than returning a partial graph. Current bounds are 80 decoded payload bytes per record, 4,096 signal-bytecode bytes per snapshot and 16 physical outputs.
This version provides snapshots, MIDI parameter/event control and a stateful CLI. The local host compiles its text patch at startup. Graph editing, automatic reconnect and subscriptions remain future work. Snapshot identities and revisions provide a starting point for change notifications; v1 does not claim persistent identity, replay or pub/sub semantics.
§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.
Modules§
- protocol
- Bounded, allocation-free graph discovery and host shutdown over MIDI SysEx.
Structs§
- Channel
- A validated, human-numbered MIDI channel (1 through 16).
- Client
- A transport-independent MIDI controller and graph-discovery client.
- Connection
- One audio connection, reconstructed from the actual signal bytecode.
- Graph
- Coherent graph description returned by a running endpoint.
- Node
- A native process in a captured graph, including its current MIDI binding.
- Unix
Transport - Local stream of MIDI messages, each preceded by its length as one byte.
Messages must contain between one and
MAX_FRAMEbytes.
Enums§
- Midi
Command - Musical commands sent as ordinary MIDI, independently of graph discovery.
- Port
Kind - Kind of one ordered process port.
Traits§
- Transport
- Bidirectional transport carrying complete MIDI messages.
Functions§
- socket_
path - Resolve an explicit socket path or the per-user default shared by
wavegraphandwr. The default is$XDG_RUNTIME_DIR/wavegraph.sockwhen the runtime directory is absolute, or~/.wavegraph.sockotherwise.