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: f64Current sample rate in Hz.
Same value passed to [AudioProcessor::setup()], provided here
for convenience during processing.
num_samples: usizeNumber of samples in this processing block.
Same as [Buffer::num_samples()], provided here for convenience.
transport: TransportHost transport and timing information.
Implementations§
Source§impl<'a> ProcessContext<'a>
impl<'a> ProcessContext<'a>
Sourcepub fn new(sample_rate: f64, num_samples: usize, transport: Transport) -> Self
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.
Sourcepub fn with_midi_cc(
sample_rate: f64,
num_samples: usize,
transport: Transport,
midi_cc_state: &'a MidiCcState,
) -> Self
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.
Sourcepub fn with_empty_transport(sample_rate: f64, num_samples: usize) -> Self
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.
Sourcepub fn midi_cc(&self) -> Option<&MidiCcState>
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
}
}Sourcepub fn buffer_duration(&self) -> f64
pub fn buffer_duration(&self) -> f64
Calculates the duration of this buffer in seconds.
Trait Implementations§
Source§impl<'a> Clone for ProcessContext<'a>
impl<'a> Clone for ProcessContext<'a>
Source§fn clone(&self) -> ProcessContext<'a>
fn clone(&self) -> ProcessContext<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more