Skip to main content

Easing

Struct Easing 

Source
pub struct Easing {
    pub attack: f32,
    pub release: f32,
}
Expand description

A binding’s easing time constants in seconds (ADR-0019, widened to a pair by ADR-0035).

attack applies while the incoming value is above the held one and release while it is at or below — so a percussive parameter can reach its target in a frame or two and then glide back over most of a second, which no single constant expresses at any value.

The scalar [smoothing] form builds Easing::symmetric, which is the low-pass ADR-0019 shipped: with both constants equal the direction test picks the same number either way, so the arithmetic is bit-for-bit unchanged.

Fields§

§attack: f32

Constant used while the raw value is above the held value (rising).

§release: f32

Constant used while the raw value is at or below the held value.

Implementations§

Source§

impl Easing

Source

pub const INSTANT: Self

No smoothing on either side: the value is applied instantly. The default for a parameter absent from [smoothing].

Source

pub const fn symmetric(tau: f32) -> Self

One constant in both directions — the scalar [smoothing] form.

Source

pub fn step(self, held: f32, raw: f32, dt: f32) -> f32

One frame of the one-pole envelope: ease held toward raw over dt real seconds, using whichever constant the direction of travel selects.

The single implementation of this vocabulary. The render layer’s per-binding smoother and the spectrum scene’s per-element smoother both call it, so “smoothing in seconds, frame-rate independent, asymmetric by direction” means exactly one thing everywhere (ADR-0019 / ADR-0035, Plan 0034 Phase 3).

The direction test is against the held value, not the raw signal’s own derivative: a value already above its new target releases toward it even while the input is still rising. That is the envelope-follower convention, and it is what keeps the behavior stable under a noisy input.

dt is finite and positive, as Scene::advance states it: the renderer’s sanitize_frame_dt is the only answer to a degenerate frame delta (ADR-0191), and nothing here second-guesses it. Outside that precondition the arithmetic answers: dt = 0 gives alpha = 0, which holds held, and a non-finite dt poisons one frame that the non-finite-held guard below turns back into raw on the next.

A selected constant of <= 0 (the default) or non-finite passes raw through unchanged. Total and allocation-free — it runs per element per frame.

A non-finite held or raw also passes raw through — a snap, which is what a smoother with no valid state should do (Plan 0038 Phase 9). This is not a theoretical edge: log(0) is -inf and silence produces it every time the music stops, so a [smoothing]-listed binding reaches this on ordinary material. Without the guard the arithmetic below is -inf + alpha * (-inf - -inf) = NaN, and NaN is absorbing here — raw > held is false for every raw, so the release branch is taken and the state stays NaN forever. The binding would be dead for the rest of the preset’s run, recovering only on a switch.

Both operands are checked because guarding raw alone does not fix it: a stored -inf against a finite raw selects attack and computes -inf + inf, which is NaN on the very next frame.

The ease ends by snapping to raw at its fixed point. In f32 the one-pole never arrives on its own: a frame moves held only while alpha * gap is at least half the float spacing u at held, so it stalls at a gap of about u / (2 * alpha) and stays there. A consumer that truncates the value (as usize, floor) would then draw one step low forever. So a frame that makes no progress returns raw.

The test is “no progress”, not “within some distance”, because the stall gap scales with 1 / alpha: toward 2.0 it is ~3 spacings at tau 0.1 s and 60 Hz but ~144 at tau 2 s and 144 Hz, so any fixed threshold is outside some slow ease’s stall and never fires. The fixed point always comes: alpha < 1 puts the exact sum strictly between held and raw, round-to-nearest keeps it in [held, raw], so the value moves monotonically and must reach raw or a stall in finitely many frames. The jump is at most the stall gap, about 2^-24 / alpha of the value.

alpha > 0 guards the snap. For dt / tau below roughly 3e-8, 1 - exp(-dt/tau) rounds to exactly zero and every frame makes no progress; without the guard the slowest possible ease would become an instant one. There the value holds.

Trait Implementations§

Source§

impl Clone for Easing

Source§

fn clone(&self) -> Easing

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 Easing

Source§

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

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

impl Default for Easing

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Easing

Source§

fn eq(&self, other: &Easing) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Easing

Source§

impl StructuralPartialEq for Easing

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> 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, 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.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,