Trait PluginDsp

Source
pub trait PluginDsp:
    Default
    + Send
    + 'static {
    // Required methods
    fn new() -> Self;
    fn prepare(&mut self, context: &DspContext);
    fn reset(&mut self);
    fn apply_parameters(&mut self, params: &[f32]);
    fn process(
        &mut self,
        inputs: &[&[f32]],
        outputs: &mut [&mut [f32]],
        midi_events: &[MidiEvent],
        context: &DspContext,
    );

    // Provided methods
    fn note_on(&mut self, note: u8, velocity: u8, sample_offset: u32) { ... }
    fn note_off(&mut self, note: u8, sample_offset: u32) { ... }
    fn control_change(&mut self, cc: u8, value: u8, sample_offset: u32) { ... }
    fn pitch_bend(&mut self, value: i16, sample_offset: u32) { ... }
}
Expand description

Trait for plugin-specific DSP implementations.

Consumers implement this trait to define their audio processing chain. The FFI layer uses this trait to manage the DSP lifecycle.

§Example

use bbx_dsp::{PluginDsp, context::DspContext};
use bbx_dsp::blocks::effectors::gain::GainBlock;

pub struct PluginGraph {
    pub gain: GainBlock<f32>,
}

impl PluginDsp for PluginGraph {
    fn new() -> Self {
        Self { gain: GainBlock::new(0.0) }
    }

    fn prepare(&mut self, context: &DspContext) {
        // Initialize blocks for the given sample rate/buffer size
    }

    fn reset(&mut self) {
        // Clear filter states, etc.
    }

    fn apply_parameters(&mut self, params: &[f32]) {
        // Map parameter array to block fields
    }

    fn process(&mut self, inputs: &[&[f32]], outputs: &mut [&mut [f32]], midi_events: &[MidiEvent], context: &DspContext) {
        // Process audio and MIDI through the chain
    }
}

Required Methods§

Source

fn new() -> Self

Create a new instance with default configuration.

Source

fn prepare(&mut self, context: &DspContext)

Prepare the DSP chain for playback.

Called when audio specs change (sample rate, buffer size, channels).

Source

fn reset(&mut self)

Reset all DSP state.

Called to clear filter histories, oscillator phases, etc.

Source

fn apply_parameters(&mut self, params: &[f32])

Apply parameter values from a flat array.

The parameter indices are plugin-specific, typically defined via generated constants from parameters.json.

Source

fn process( &mut self, inputs: &[&[f32]], outputs: &mut [&mut [f32]], midi_events: &[MidiEvent], context: &DspContext, )

Process a block of audio with MIDI events.

  • inputs: Array of input channel buffers
  • outputs: Array of output channel buffers
  • midi_events: MIDI events with sample-accurate timing (sorted by sample_offset)
  • context: DSP context with sample rate, buffer size, etc.

Provided Methods§

Source

fn note_on(&mut self, note: u8, velocity: u8, sample_offset: u32)

Called when a note-on event is received.

Default implementation does nothing (suitable for effect plugins).

Source

fn note_off(&mut self, note: u8, sample_offset: u32)

Called when a note-off event is received.

Default implementation does nothing (suitable for effect plugins).

Source

fn control_change(&mut self, cc: u8, value: u8, sample_offset: u32)

Called when a control change event is received.

Default implementation does nothing.

Source

fn pitch_bend(&mut self, value: i16, sample_offset: u32)

Called when a pitch bend event is received.

Default implementation does nothing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§