Skip to main content

Crate truce_driver

Crate truce_driver 

Source
Expand description

Headless driver for truce plugins.

Instantiate a plugin, feed it scripted audio + events for a fixed duration, capture the output. Used by:

  • Tests via truce-test - adds assertion helpers on top of the captured DriverResult.
  • The standalone host’s offline-render path - cargo truce run --no-playback parses CLI flags into an InputSource::Buffer + Script, runs PluginDriver, writes the captured audio out as WAV.
  • Plugin authors writing custom main.rs bins - batch CI renders, demo audio generation, preset rendering pipelines.

No cpal, no midir, no live-audio plumbing. The driver does:

  1. P::create()init()reset() → param set_sample_rate
    • snap_smoothers.
  2. Apply state_file bytes via plugin.load_state(...).
  3. Run the setup closure (&mut Plugin).
  4. Loop blocks: pull script events into the block window, run plugin.process(...), append the output.
  5. Capture meters / output events / per-block snapshots according to CaptureSpec.

See PluginDriver for the builder surface.

use std::time::Duration;
use truce_driver::{InputSource, PluginDriver};

let result = PluginDriver::<MyPlugin>::new()
    .sample_rate(48_000.0)
    .duration(Duration::from_secs(2))
    .input(InputSource::Constant(0.5))
    .set_param(MyParamId::Gain, 0.7)
    .script(|s| {
        s.note_on(60, 0.8);
        s.wait_ms(500);
        s.note_off(60);
    })
    .run();

Structs§

CaptureSpec
DriverResult
Captured audio + metadata + plugin instance from a PluginDriver run.
PluginDriver
Script
Sample-accurate sequence of events fed to the plugin during a run. Cursor advances via wait_ms / wait_samples; events land at the current cursor position.
SetupContext
Context passed to the PluginDriver::setup closure. Carries the driver state that’s been resolved by the time setup runs - in particular the auto-detected channel count, which would otherwise be invisible to the closure (the user’s &mut P doesn’t know).
TransportSpec
Transport state visible to the plugin’s ProcessContext.

Enums§

InputSource
What audio gets fed into the plugin’s input bus each block.
MeterCapture
MeterReadings