pub struct ClockTick {
pub sample_pos: u64,
pub samples_since_last: u32,
pub is_new_block: bool,
pub sample_rate: f32,
pub tempo: Option<f32>,
pub source: String,
pub speed_ratio: f64,
pub is_final: bool,
pub io_quantum: u32,
}Expand description
A tick of the system clock
Sent to nodes on every signal block to provide timing information and synchronize processing. This is the fundamental timing primitive in Rill.
§Fields
sample_pos- Absolute sample position since startsamples_since_last- Number of samples since the last tickis_new_block- Whether this is the start of a new blocksample_rate- Current sample rate in Hztempo- Current tempo in BPM (if available)source- Which backend produced this tick (e.g. “alsa:default”)
I/O access is handled directly through IoCapture
and IoPlayback traits — the tick carries
only timing metadata.
§Example
use rill_core::time::ClockTick;
let tick = ClockTick::new(44100, 64, 44100.0, "test".into());
assert_eq!(tick.absolute_seconds(), 1.0);
assert_eq!(tick.delta_seconds(), 64.0 / 44100.0);Fields§
§sample_pos: u64Absolute sample position since start
samples_since_last: u32Number of samples since the last tick
is_new_block: boolWhether this is the start of a new block
sample_rate: f32Current sample rate in Hz
tempo: Option<f32>Current tempo in BPM (if available)
source: StringWhich backend produced this tick (e.g. “alsa:default”, “pipewire:0”).
speed_ratio: f64Hardware clock correction factor: configured_rate / actual_rate.
1.0 = nominal (rates match). < 1.0 = hardware runs faster.
> 1.0 = hardware runs slower. Set by the backend when the
negotiated hardware rate differs from the graph’s configured rate.
is_final: boolWhether this tick should trigger a ClockTick dispatch to modules.
true by default. Chunking backends (PipeWire) set this to false
for intermediate chunks and true only for the final chunk of the
DMA buffer — avoiding 48 ClockTick dispatches per PW callback.
io_quantum: u32Number of frames the I/O backend processes per callback (its quantum).
The graph processes one block_size chunk per pass, but a backend may
batch many chunks into a single I/O callback (e.g. PipeWire delivers a
12288-frame buffer = 48 × 256 chunks). Tick-driven control producers
(sequencers/servos) that run asynchronously only see the results of a
callback after it returns, so a change reacting to a tick in the
current callback can only be rendered in the next one. Producers use
io_quantum as the sample look-ahead when stamping
SetParameter::sample_pos so the change
lands on the correct block of the next callback instead of collapsing
onto block 0. Defaults to samples_since_last (one chunk per callback).
Implementations§
Source§impl ClockTick
impl ClockTick
Sourcepub fn new(
sample_pos: u64,
samples_since_last: u32,
sample_rate: f32,
source: String,
) -> Self
pub fn new( sample_pos: u64, samples_since_last: u32, sample_rate: f32, source: String, ) -> Self
Sourcepub fn with_tempo(
sample_pos: u64,
samples_since_last: u32,
sample_rate: f32,
tempo: f32,
source: String,
) -> Self
pub fn with_tempo( sample_pos: u64, samples_since_last: u32, sample_rate: f32, tempo: f32, source: String, ) -> Self
Create a new clock tick with tempo information
§Arguments
sample_pos- Absolute sample positionsamples_since_last- Samples since last ticksample_rate- Sample rate in Hztempo- Tempo in BPMsource- Backend source name
Sourcepub fn with_io_quantum(self, io_quantum: u32) -> Self
pub fn with_io_quantum(self, io_quantum: u32) -> Self
Set the I/O backend’s per-callback quantum (frames processed per callback).
Backends that batch multiple block_size chunks into one callback set
this so asynchronous control producers know how far ahead to schedule
sample-accurate parameter changes. See io_quantum.
Sourcepub fn delta_seconds(&self) -> f32
pub fn delta_seconds(&self) -> f32
Sourcepub fn absolute_seconds(&self) -> f64
pub fn absolute_seconds(&self) -> f64
Sourcepub fn beat_position(&self) -> Option<f64>
pub fn beat_position(&self) -> Option<f64>
Get the current beat position (if tempo is available)
§Returns
Some(beat)- Current beat position (fractional)None- No tempo information available
Sourcepub fn musical_position(&self) -> Option<(u32, u8, u8)>
pub fn musical_position(&self) -> Option<(u32, u8, u8)>
Get the current bar-beat-sixteenth position (if tempo is available)
§Returns
Some((bar, beat, sixteenth))- Musical positionNone- No tempo information available