pub struct RenderContext {
pub sample_pos: u64,
pub samples_since_last: u32,
pub sample_rate: f32,
pub transport: TransportState,
pub speed_ratio: f64,
}Expand description
Unified render context — passed by & reference through the entire
signal graph during one processing block.
Built by the I/O backend once per block on the stack. Contains sample-clock metadata, host transport state, and hardware clock correction factor.
§Field summary
| Field | Source | Used by |
|---|---|---|
sample_pos | I/O backend sample counter | Time-aware generators, sequencers |
samples_since_last | Block size | Delta-time computation |
sample_rate | I/O backend config | Frequency calculations, filters |
transport | JACK/PipeWire transport or MIDI clock | BPM-synced LFOs, sequencers, automations |
speed_ratio | SPA clock / DLL filter | Sample-rate conversion (resampling compensation) |
Fields§
§sample_pos: u64Absolute sample position since graph start.
samples_since_last: u32Number of samples processed in this block.
sample_rate: f32Current sample rate in Hz.
transport: TransportStateHost transport state (BPM, playing flag, musical position).
speed_ratio: f64Hardware clock correction factor.
1.0 = nominal. > 1.0 = sound card is slow (resample up).
< 1.0 = sound card is fast (resample down).
Set by PipeWire’s spa_io_clock.rate_match or a JACK DLL filter.
Implementations§
Source§impl RenderContext
impl RenderContext
Sourcepub fn new(sample_pos: u64, samples_since_last: u32, sample_rate: f32) -> Self
pub fn new(sample_pos: u64, samples_since_last: u32, sample_rate: f32) -> Self
Create a minimal render context from basic clock parameters.
Transport defaults to 120 BPM, playing, 4/4.
Sourcepub fn with_tempo(
sample_pos: u64,
samples_since_last: u32,
sample_rate: f32,
bpm: f32,
) -> Self
pub fn with_tempo( sample_pos: u64, samples_since_last: u32, sample_rate: f32, bpm: f32, ) -> Self
Create a render context with an explicit BPM.
Sourcepub fn delta_seconds(&self) -> f64
pub fn delta_seconds(&self) -> f64
Time delta of this block in seconds.
Sourcepub fn absolute_seconds(&self) -> f64
pub fn absolute_seconds(&self) -> f64
Absolute time in seconds since graph start.
Sourcepub fn beat_position(&self) -> Option<f64>
pub fn beat_position(&self) -> Option<f64>
Musical beat position (requires valid BPM).
Returns None if BPM is zero.
Sourcepub fn musical_position(&self) -> Option<(u32, u8, u8)>
pub fn musical_position(&self) -> Option<(u32, u8, u8)>
Musical position as (bar, beat_in_bar, sixteenth) triple.
Uses time_sig_num and time_sig_den from the transport state.
Sourcepub fn is_new_bar(&self) -> bool
pub fn is_new_bar(&self) -> bool
Whether this block starts a new bar.
Sourcepub fn is_new_beat(&self) -> bool
pub fn is_new_beat(&self) -> bool
Whether this block starts a new beat.
Trait Implementations§
Source§impl Clone for RenderContext
impl Clone for RenderContext
Source§fn clone(&self) -> RenderContext
fn clone(&self) -> RenderContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more