pub trait FloatParamReadF32 {
// Required methods
fn read(&self) -> f32;
fn read_block<const N: usize>(&self) -> [f32; N];
fn read_into(&self, out: &mut [f32]);
fn read_after(&self, n_samples: usize) -> f32;
fn current(&self) -> f32;
fn value(&self) -> f32;
}Expand description
Precision-routed read accessors for FloatParam at f32.
The plugin prelude (truce::prelude / truce::prelude32) imports
this trait via pub use … as _;, so plugin code reads:
use truce::prelude::*;
let gain = self.params.gain.read(); // f32 - no annotation neededThe trait’s methods shadow nothing - FloatParam has no inherent
read / value / current, so name resolution picks the one
(and only one) trait that’s in scope. Importing prelude64
instead brings FloatParamReadF64 into scope and the same
source resolves to f64. Importing both preludes is a
compile error (multiple applicable items in scope) - which is
the right error for a file that hasn’t committed to a precision.
Required Methods§
Sourcefn read_block<const N: usize>(&self) -> [f32; N]
👎Deprecated since 0.53.0: use read_into(&mut scratch[..n]) instead; read_block::<N> advances the smoother by N regardless of how many samples the caller consumes, which steps the value at the next block boundary when the host’s block size isn’t a multiple of N
fn read_block<const N: usize>(&self) -> [f32; N]
use read_into(&mut scratch[..n]) instead; read_block::<N> advances the smoother by N regardless of how many samples the caller consumes, which steps the value at the next block boundary when the host’s block size isn’t a multiple of N
Advance the smoother by exactly N samples in one call,
returning the per-sample values as a stack array.
Deprecated in favour of Self::read_into, which takes a
runtime-length slice and so always advances the smoother by
the number of samples the caller actually consumes. The
const-N shape is a silent footgun: a total.min(MAX_BLOCK)
chunk ladder pulls N samples from the smoother every iteration
but only consumes n ≤ N, leaving the smoother N - n samples
ahead - audible as clicks at every block boundary on delay,
LFO-rate, and any other timing-sensitive smoothed param.
read_into(&mut scratch[..N]) is the same code shape with the
hazard removed.
Sourcefn read_into(&self, out: &mut [f32])
fn read_into(&self, out: &mut [f32])
Fill out with the next out.len() smoothed samples; advance
the smoother by out.len() (not by the slice’s capacity).
Same one atomic load + one atomic store amortization as
Self::read_block; runtime length instead of const-generic
N. The right primitive when chunking process()’s block
dynamically:
let mut delay = [0.0_f32; MAX_BLOCK];
while offset < total {
let n = (total - offset).min(MAX_BLOCK);
self.params.delay.read_into(&mut delay[..n]);
// ... consume delay[..n] for n samples ...
offset += n;
}Sourcefn read_after(&self, n_samples: usize) -> f32
fn read_after(&self, n_samples: usize) -> f32
Advance the smoother by n_samples in one call, returning
only the final value. Use for block-rate DSP - hard
gates, mode switches, anything that needs one smoothed value
per audio block. Pass buffer.num_samples() to keep the
smoother’s wall-clock convergence time matching the smoother
declaration (smooth = "exp(20)" then actually settles in
~20 ms instead of ~20 blocks). One atomic load + one atomic
store; the intermediate envelope from Self::read_block
is skipped.
Sourcefn value(&self) -> f32
fn value(&self) -> f32
Raw target value (post-set_normalized / host automation),
not the smoothed output. Use Self::read / Self::current
in the DSP loop.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".