Skip to main content

RenderContext

Struct RenderContext 

Source
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

FieldSourceUsed by
sample_posI/O backend sample counterTime-aware generators, sequencers
samples_since_lastBlock sizeDelta-time computation
sample_rateI/O backend configFrequency calculations, filters
transportJACK/PipeWire transport or MIDI clockBPM-synced LFOs, sequencers, automations
speed_ratioSPA clock / DLL filterSample-rate conversion (resampling compensation)

Fields§

§sample_pos: u64

Absolute sample position since graph start.

§samples_since_last: u32

Number of samples processed in this block.

§sample_rate: f32

Current sample rate in Hz.

§transport: TransportState

Host transport state (BPM, playing flag, musical position).

§speed_ratio: f64

Hardware 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

Source

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.

Source

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.

Source

pub fn delta_seconds(&self) -> f64

Time delta of this block in seconds.

Source

pub fn absolute_seconds(&self) -> f64

Absolute time in seconds since graph start.

Source

pub fn bpm(&self) -> f32

Current BPM as f32 for backward compatibility.

Source

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

Musical beat position (requires valid BPM).

Returns None if BPM is zero.

Source

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.

Source

pub fn is_new_bar(&self) -> bool

Whether this block starts a new bar.

Source

pub fn is_new_beat(&self) -> bool

Whether this block starts a new beat.

Trait Implementations§

Source§

impl Clone for RenderContext

Source§

fn clone(&self) -> RenderContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RenderContext

Source§

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

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

impl Display for RenderContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert to &dyn std::any::Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert to &mut dyn std::any::Any
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V