Manguebyte

Get started

From nothing to a plugin

Everything on this page comes from the repository’s README and its two example plugins, as they are at commit 46ec338. That commit comes well after the 0.2.0 release. The README’s quick start is the same as in the release; the two plugins now also state their tail with Plugin::tail_samples, which the release does not have.

Before you build on it: Manguebyte is young, 0.2.0 is its second release, and the API will change before 1.0. Plugin editors exist and are tested in CI; by hand, only Mangue Pluck’s CLAP editor has been opened in a host so far.

  1. Before you start

    You need a stable Rust toolchain, version 1.85 or newer.

    On Linux, the device backend needs the ALSA development headers, and the JACK host (feature jack) the JACK ones (libjack-jackd2-dev):

    Shell
    sudo apt install libasound2-dev
  2. Add the dependency

    Manguebyte is on crates.io, and the documentation of every crate is on docs.rs. Add it to your Cargo.toml:

    TOML
    [dependencies]
    manguebyte = "0.2"
    From README.md at commit 46ec338, as it is in the file.

    To follow the newest work on main instead, depend on the repository with a git dependency, as the README shows.

  3. Start a plugin

    Install the command-line tool, and let it write a plugin crate. The crate depends on the release cargo mangue came with; --manguebyte-git makes it follow the repository instead, and --manguebyte-path a checkout of it.

    Shell
    cargo install cargo-mangue
    cargo mangue new my-gain
    From README.md at commit 46ec338, as it is in the file.
  4. Make a sound

    A tuple of processors is itself a processor. Build a synth voice by putting three of them in a tuple, then render one second of it to a WAV file. This needs no audio hardware.

    Rust
    use manguebyte::prelude::*;
    
    fn main() -> Result<(), wav::WavError> {
        let spec = ProcessSpec { sample_rate: 48_000.0, max_block_size: 48_000, num_channels: 2 };
    
        // A tuple of processors is itself a processor.
        let mut voice = (
            Oscillator::new(Waveform::Saw, note_to_hz(45.0)),
            Filter::new(FilterShape::Lowpass, 1_200.0, 1.5),
            Gain::from_db(-12.0),
        );
        voice.prepare(&spec);
    
        let mut second = AudioBuffer::<f32>::new(2, 48_000);
        voice.process(&mut second);
    
        wav::write_file("saw.wav", &second, 48_000, WavFormat::Int16)
    }
    From README.md at commit 46ec338, as it is in the file.
  5. Play it live

    The same kind of chain, on the default output device. The closure runs on the audio thread.

    Rust
    use manguebyte::prelude::*;
    
    fn main() -> Result<(), DeviceError> {
        let device = OutputDevice::open_default()?;
        let spec = ProcessSpec {
            sample_rate: device.sample_rate(),
            max_block_size: 512,
            num_channels: device.num_channels(),
        };
    
        let mut voice = (Oscillator::new(Waveform::Sine, 440.0), Gain::<f32>::from_db(-18.0));
        voice.prepare(&spec);
    
        // The closure runs on the audio thread.
        let _stream = device.start(512, move |buffer| voice.process(buffer))?;
        std::thread::sleep(std::time::Duration::from_secs(2));
        Ok(())
    }
    From README.md at commit 46ec338, as it is in the file.
  6. Run the examples

    Clone the repository to run its examples and to build the example plugins:

    Shell
    git clone https://github.com/alessonqueirozdev-hub/manguebyte
    cd manguebyte
    
    # Render a short synth riff to a WAV file. Needs no audio hardware.
    cargo run --example render_wav -- riff.wav
    
    # Play the same riff on your speakers. The optional argument is a level in dB.
    cargo run --example play_riff -- -12
  7. Build a plugin

    plugins/pluck is a complete instrument in one file: a 16-voice plucked synth with per-note expression and modulation, automation on the exact sample, a reverb and a small editor. plugins/duck is the same for an effect: a sidechain ducker with a bypass switch that does not click and an editor with a gain-reduction meter. Each becomes a CLAP, a VST 3, an LV2 plugin and an Audio Unit with one line per format.

    Build either one into something a host can load with the framework’s command-line tool, cargo mangue, which writes a .clap and a .vst3 in each system’s layout (add --format lv2 for an .lv2 bundle, and on a Mac --format au for a .component):

    Shell
    cargo run -p cargo-mangue -- bundle -p mangue-pluck --release

    cargo mangue new my-synth --kind instrument starts a plugin of your own from a template; install copies a plugin into the user’s plugin folders, and validate runs the CLAP and VST 3 validators on it (validate --format au runs Apple’s auval on a .component). Both examples go through those validators on every commit, and were tested by hand in REAPER as CLAP and VST 3 before they had editors; since then Mangue Pluck’s CLAP editor has been opened there. plugins/divisions is an instrument with several outputs: a small organ whose Great, Swell, Choir and Pedal go out on four stereo auxiliary buses, and together on the main output. It passes the same validators in CI, and no DAW has loaded it.

  8. Declare parameters

    Parameters are fields of a struct: typed, lock-free, with ranges, units and text conversion. This is the whole declaration from the example effect.

    Rust
    /// The plugin's parameters.
    pub struct DuckParams {
        /// Sidechain level, in decibels, at which the input starts to go down.
        pub threshold: FloatParam,
        /// The most the input is turned down, in decibels.
        pub depth: FloatParam,
        /// How fast the input goes down, in milliseconds.
        pub attack: FloatParam,
        /// How fast it comes back, in milliseconds.
        pub release: FloatParam,
        /// Lets the input through untouched.
        pub bypass: BoolParam,
    }
    param_set!(DuckParams {
        threshold,
        depth,
        attack,
        release,
        bypass
    });
    From plugins/duck/src/lib.rs at commit 46ec338, as it is in the file.
  9. Test it without a host

    The same plugin runs inside a unit test through Harness, on a machine with no sound card. This test from the example instrument plays an A and checks, by FFT, that 440 Hz is what comes out.

    Rust
    #[test]
    fn plays_the_pitch_it_is_asked_for() {
        use manguebyte::dsp::fft::{Complex, RealFft};
    
        let mut harness = Harness::<Pluck>::new(RATE, 512);
        harness.params().reverb.set(0.0);
        // No resonant peak, so the fundamental is the loudest partial.
        harness.params().resonance.set(0.7);
        harness.note(0, 40_000, 69, 1.0); // A4, 440 Hz
        let sound = harness.render(32_768);
    
        let mut fft = RealFft::<f32>::new(32_768);
        let mut spectrum = vec![Complex::ZERO; fft.spectrum_len()];
        fft.forward(sound.channel(0), &mut spectrum);
        let loudest = (1..spectrum.len())
            .max_by(|&a, &b| spectrum[a].norm_sqr().total_cmp(&spectrum[b].norm_sqr()))
            .unwrap();
        let hertz = loudest as f64 * RATE / 32_768.0;
        assert!((hertz - 440.0).abs() < 2.0, "loudest partial at {hertz} Hz");
    }
    From plugins/pluck/src/lib.rs at commit 46ec338, as it is in the file.
  10. Play it without a host

    The standalone wrapper runs the instrument straight on the sound card, with any connected MIDI keyboard. The argument is the level in decibels.

    Shell
    cargo run -p mangue-pluck --features standalone --example play -- -12 hold