Plugin

Trait Plugin 

Source
pub trait Plugin: AudioProcessor {
    type Params: Parameters + Units + Params;

Show 19 methods // Required methods fn params(&self) -> &Self::Params; fn params_mut(&mut self) -> &mut Self::Params; fn create() -> Self where Self: Sized; // Provided methods fn midi_cc_to_param( &self, bus_index: i32, channel: i16, cc: u8, ) -> Option<u32> { ... } fn midi_cc_params(&self) -> Option<&MidiCcParams> { ... } fn on_midi_learn(&mut self, bus_index: i32, channel: i16, cc: u8) -> bool { ... } fn midi1_assignments(&self) -> &[Midi1Assignment] { ... } fn midi2_assignments(&self) -> &[Midi2Assignment] { ... } fn on_midi1_learn(&mut self, bus_index: i32, channel: u8, cc: u8) -> bool { ... } fn on_midi2_learn( &mut self, bus_index: i32, channel: u8, controller: Midi2Controller, ) -> bool { ... } fn note_expression_count(&self, bus_index: i32, channel: i16) -> usize { ... } fn note_expression_info( &self, bus_index: i32, channel: i16, index: usize, ) -> Option<NoteExpressionTypeInfo> { ... } fn note_expression_value_to_string( &self, bus_index: i32, channel: i16, type_id: u32, value: f64, ) -> String { ... } fn note_expression_string_to_value( &self, bus_index: i32, channel: i16, type_id: u32, string: &str, ) -> Option<f64> { ... } fn keyswitch_count(&self, bus_index: i32, channel: i16) -> usize { ... } fn keyswitch_info( &self, bus_index: i32, channel: i16, index: usize, ) -> Option<KeyswitchInfo> { ... } fn physical_ui_mappings( &self, bus_index: i32, channel: i16, ) -> &[PhysicalUIMap] { ... } fn enable_mpe_input_processing(&mut self, enabled: bool) -> bool { ... } fn set_mpe_input_device_settings( &mut self, settings: MpeInputDeviceSettings, ) -> bool { ... }
}
Expand description

Main plugin trait combining audio processing and parameters.

This is the primary trait that plugin authors implement to create a complete audio plugin. It combines AudioProcessor for DSP with a Parameters collection for host communication.

§Example

use beamer_core::{Plugin, AudioProcessor, Buffer, AuxiliaryBuffers, Parameters, ProcessContext};

pub struct MyGain {
    params: MyGainParams,
}

impl AudioProcessor for MyGain {
    fn setup(&mut self, _sample_rate: f64, _max_buffer_size: usize) {}

    fn process(&mut self, buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, _context: &ProcessContext) {
        let gain = self.params.gain_linear();
        for (input, output) in buffer.zip_channels() {
            for (i, o) in input.iter().zip(output.iter_mut()) {
                *o = *i * gain;
            }
        }
    }
}

impl Plugin for MyGain {
    type Params = MyGainParams;

    fn params(&self) -> &Self::Params {
        &self.params
    }

    fn create() -> Self {
        Self { params: MyGainParams::new() }
    }
}

Required Associated Types§

Source

type Params: Parameters + Units + Params

The parameter collection type for this plugin.

Required Methods§

Source

fn params(&self) -> &Self::Params

Returns a reference to the plugin’s parameters.

The VST3 wrapper uses this to communicate parameter values with the host.

Source

fn params_mut(&mut self) -> &mut Self::Params

Returns a mutable reference to the plugin’s parameters.

Used by the framework for operations like resetting smoothers after loading state. Most plugins can use the default implementation.

Source

fn create() -> Self
where Self: Sized,

Creates a new instance of the plugin with default state.

Called by the host when instantiating the plugin.

Provided Methods§

Source

fn midi_cc_to_param(&self, bus_index: i32, channel: i16, cc: u8) -> Option<u32>

Get the parameter ID mapped to a MIDI CC.

Override this to enable DAW MIDI learn for your parameters. When the DAW queries which parameter is assigned to a MIDI CC, this method is called.

§Arguments
  • bus_index - MIDI bus index (usually 0)
  • channel - MIDI channel (0-15), or -1 to query all channels
  • cc - MIDI CC number (0-127)
§Returns

Some(param_id) if this CC is mapped to a parameter, None otherwise.

§Example
fn midi_cc_to_param(&self, _bus: i32, _channel: i16, cc: u8) -> Option<u32> {
    match cc {
        cc::MOD_WHEEL => Some(PARAM_VIBRATO_DEPTH),
        cc::EXPRESSION => Some(PARAM_VOLUME),
        _ => None,
    }
}
Source

fn midi_cc_params(&self) -> Option<&MidiCcParams>

Returns MIDI CC parameters for automatic host mapping.

Override to enable MIDI CC/pitch bend/aftertouch reception via IMidiMapping. The framework will create hidden parameters that receive CC values from the host and convert them to MidiEvents before calling process_midi().

This solves the VST3 MIDI input problem where most DAWs don’t send kLegacyMIDICCOutEvent for input. Instead, they use the IMidiMapping interface to map MIDI controllers to parameters.

§Example
fn midi_cc_params(&self) -> Option<&MidiCcParams> {
    Some(&self.midi_cc_params)
}

fn create() -> Self {
    Self {
        params: MyParams::default(),
        midi_cc_params: MidiCcParams::new()
            .with_pitch_bend()
            .with_mod_wheel()
            .with_ccs(&[7, 10, 11, 64]),
    }
}
Source

fn on_midi_learn(&mut self, bus_index: i32, channel: i16, cc: u8) -> bool

Called by DAW when live MIDI CC input is received during learn mode.

Override this to implement MIDI learn in your plugin UI. When the user enables “MIDI Learn” mode and moves a MIDI CC knob, the DAW calls this method so the plugin can map that CC to a parameter.

§Arguments
  • bus_index - MIDI bus index (usually 0)
  • channel - MIDI channel (0-15)
  • cc - MIDI CC number that was moved
§Returns

true if the input was handled (learned), false otherwise.

Source

fn midi1_assignments(&self) -> &[Midi1Assignment]

Get all MIDI 1.0 CC assignments for bulk query.

Override to provide mappings for DAW queries. This is more efficient than individual midi_cc_to_param queries when there are many mappings.

Default returns empty slice (no mappings).

Source

fn midi2_assignments(&self) -> &[Midi2Assignment]

Get all MIDI 2.0 controller assignments for bulk query.

Override to provide MIDI 2.0 Registered/Assignable controller mappings.

Default returns empty slice (no mappings).

Source

fn on_midi1_learn(&mut self, bus_index: i32, channel: u8, cc: u8) -> bool

Called when MIDI 1.0 CC input is received during learn mode.

This is the MIDI 2.0 version of on_midi_learn with separate methods for MIDI 1.0 and MIDI 2.0 controllers.

Default returns false (not handled).

Source

fn on_midi2_learn( &mut self, bus_index: i32, channel: u8, controller: Midi2Controller, ) -> bool

Called when MIDI 2.0 controller input is received during learn mode.

Override to implement MIDI 2.0 controller learning.

Default returns false (not handled).

Source

fn note_expression_count(&self, bus_index: i32, channel: i16) -> usize

Returns the number of supported note expression types.

Override to advertise which note expressions your plugin supports (e.g., volume, pan, tuning for MPE instruments).

Default returns 0 (no note expressions).

Source

fn note_expression_info( &self, bus_index: i32, channel: i16, index: usize, ) -> Option<NoteExpressionTypeInfo>

Returns information about a note expression type by index.

Override to provide details about each supported expression type.

Default returns None.

Source

fn note_expression_value_to_string( &self, bus_index: i32, channel: i16, type_id: u32, value: f64, ) -> String

Converts a normalized note expression value to a display string.

Override to provide custom formatting (e.g., “2.5 semitones” for tuning).

Default returns the value as a percentage.

Source

fn note_expression_string_to_value( &self, bus_index: i32, channel: i16, type_id: u32, string: &str, ) -> Option<f64>

Parses a string to a normalized note expression value.

Override to support custom parsing.

Default returns None (parsing not supported).

Source

fn keyswitch_count(&self, bus_index: i32, channel: i16) -> usize

Returns the number of keyswitches (articulations).

Override for sample libraries and orchestral instruments that support keyswitching between articulations.

Default returns 0 (no keyswitches).

Source

fn keyswitch_info( &self, bus_index: i32, channel: i16, index: usize, ) -> Option<KeyswitchInfo>

Returns information about a keyswitch by index.

Override to provide keyswitch details for DAW expression maps.

Default returns None.

Source

fn physical_ui_mappings(&self, bus_index: i32, channel: i16) -> &[PhysicalUIMap]

Returns mappings from physical UI controllers to note expressions.

Override to define how MPE controllers (X-axis, Y-axis, Pressure) map to your plugin’s note expression types.

§Example
fn physical_ui_mappings(&self, _bus: i32, _channel: i16) -> &[PhysicalUIMap] {
    &[
        PhysicalUIMap::y_axis(note_expression::BRIGHTNESS),
        PhysicalUIMap::pressure(note_expression::EXPRESSION),
    ]
}

Default returns empty slice (no mappings).

Source

fn enable_mpe_input_processing(&mut self, enabled: bool) -> bool

Called to enable or disable MPE input processing.

Override to handle MPE enable/disable notifications from wrappers.

Default does nothing and returns true.

Source

fn set_mpe_input_device_settings( &mut self, settings: MpeInputDeviceSettings, ) -> bool

Called when the MPE input device settings change.

Override to receive MPE zone configuration from wrappers.

Default does nothing and returns true.

Implementors§