pub struct ProcessContext {
pub sample_rate: f64,
pub num_samples: usize,
pub transport: Transport,
}Expand description
Complete processing context for a single process() call.
Contains sample rate, buffer size, and transport/timing information.
Passed as the third parameter to [AudioProcessor::process()].
§Lifetime
ProcessContext is Copy and 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
};
// 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 ProcessContext
impl ProcessContext
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_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 buffer_duration(&self) -> f64
pub fn buffer_duration(&self) -> f64
Calculates the duration of this buffer in seconds.
Trait Implementations§
Source§impl Clone for ProcessContext
impl Clone for ProcessContext
Source§fn clone(&self) -> ProcessContext
fn clone(&self) -> ProcessContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more