ProcessContext

Struct ProcessContext 

Source
pub struct ProcessContext<'a> {
    pub sample_rate: f64,
    pub num_samples: usize,
    pub transport: Transport,
    /* private fields */
}
Expand description

Complete processing context for a single process() call.

Contains sample rate, buffer size, transport/timing information, and optional MIDI CC state for direct access to controller values. Passed as the third parameter to [AudioProcessor::process()].

§Lifetime

ProcessContext is valid only within a single process() call. Do not store references to it across calls.

§Example

impl AudioProcessor for MyDelayPlugin {
    fn process(&mut self, buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, context: &ProcessContext) {
        // Calculate tempo-synced delay time
        let delay_samples = if let Some(tempo) = context.transport.tempo {
            // Quarter note delay
            let quarter_note_sec = 60.0 / tempo;
            (quarter_note_sec * context.sample_rate) as usize
        } else {
            // Fallback: 500ms
            (0.5 * context.sample_rate) as usize
        };

        // Access MIDI CC values directly
        if let Some(cc) = context.midi_cc() {
            let mod_depth = cc.mod_wheel();
        }

        // Use context.num_samples for buffer size
        for i in 0..context.num_samples {
            // Process...
        }
    }
}

Fields§

§sample_rate: f64

Current sample rate in Hz.

Same value passed to [AudioProcessor::setup()], provided here for convenience during processing.

§num_samples: usize

Number of samples in this processing block.

Same as [Buffer::num_samples()], provided here for convenience.

§transport: Transport

Host transport and timing information.

Implementations§

Source§

impl<'a> ProcessContext<'a>

Source

pub fn new(sample_rate: f64, num_samples: usize, transport: Transport) -> Self

Creates a new ProcessContext.

This is called by the VST3 wrapper, not by plugin code.

Source

pub fn with_midi_cc( sample_rate: f64, num_samples: usize, transport: Transport, midi_cc_state: &'a MidiCcState, ) -> Self

Creates a new ProcessContext with MIDI CC state.

This is called by the VST3 wrapper when the plugin has MIDI CC config.

Source

pub fn with_empty_transport(sample_rate: f64, num_samples: usize) -> Self

Creates a context with default (empty) transport.

Used when the host doesn’t provide ProcessContext.

Source

pub fn midi_cc(&self) -> Option<&MidiCcState>

Returns MIDI CC state for direct access to controller values.

Only returns Some if the plugin returned Some(MidiCcConfig) from midi_cc_config().

§Example
fn process(&mut self, buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, context: &ProcessContext) {
    if let Some(cc) = context.midi_cc() {
        let pitch_bend = cc.pitch_bend();  // -1.0 to 1.0
        let mod_wheel = cc.mod_wheel();    // 0.0 to 1.0
        let volume = cc.cc(7);             // 0.0 to 1.0
    }
}
Source

pub fn buffer_duration(&self) -> f64

Calculates the duration of this buffer in seconds.

Source

pub fn samples_per_beat(&self) -> Option<f64>

Calculates samples per beat at the current tempo.

Returns None if tempo is unavailable.

§Example
if let Some(spb) = context.samples_per_beat() {
    let delay_samples = spb * 0.25; // 16th note delay
}

Trait Implementations§

Source§

impl<'a> Clone for ProcessContext<'a>

Source§

fn clone(&self) -> ProcessContext<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ProcessContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProcessContext<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ProcessContext<'a>

§

impl<'a> RefUnwindSafe for ProcessContext<'a>

§

impl<'a> Send for ProcessContext<'a>

§

impl<'a> Sync for ProcessContext<'a>

§

impl<'a> Unpin for ProcessContext<'a>

§

impl<'a> UnwindSafe for ProcessContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.