Skip to main content

ParamRange

Enum ParamRange 

Source
pub enum ParamRange {
    Linear {
        min: f64,
        max: f64,
    },
    Logarithmic {
        min: f64,
        max: f64,
    },
    Skewed {
        min: f64,
        max: f64,
        factor: f64,
    },
    SymmetricalSkewed {
        min: f64,
        max: f64,
        factor: f64,
        center: f64,
    },
    Discrete {
        min: i64,
        max: i64,
    },
    Enum {
        count: usize,
    },
    Reversed(&'static ParamRange),
}
Expand description

Defines how a parameter maps between plain and normalized values.

Copy because every variant is POD (scalars, or a &'static for Self::Reversed). Lets format wrappers pass info.range by value without clone() noise.

Variants§

§

Linear

Fields

§min: f64
§max: f64
§

Logarithmic

Fields

§min: f64
§max: f64
§

Skewed

Power-law taper over [min, max]: normalize(plain) = t^factor where t is the linear proportion. factor < 1.0 gives the low end of the range more of the knob (a log-like taper); factor > 1.0 gives the high end more; factor == 1.0 is Linear.

Fields

§min: f64
§max: f64
§factor: f64
§

SymmetricalSkewed

Skew anchored at center, which sits at the knob’s midpoint with each half a mirror of the other. The idiomatic shape for center-detented knobs - pan (center = 0) and EQ gain (center = 0 dB) - where the two directions should feel symmetric regardless of where center falls in [min, max].

Fields

§min: f64
§max: f64
§factor: f64
§center: f64
§

Discrete

Fields

§min: i64
§max: i64
§

Enum

Fields

§count: usize
§

Reversed(&'static ParamRange)

Wraps another range with its normalized axis flipped: the inner range’s plain max sits at the bottom of the knob and min at the top. Plain bounds and step count are the inner range’s.

Implementations§

Source§

impl ParamRange

Source

pub fn normalize(&self, plain: f64) -> f64

Map a plain value to 0.0–1.0.

Degenerate bounds - min == max for Linear / Discrete, non-positive or empty for Logarithmic, count <= 1 for Enum - collapse to 0.0. Combined with Self::denormalize returning min on the same inputs, the pair is round-trip stable: the result always converges to the bottom of the (degenerate) range rather than producing NaN or wrapping into nonsense.

Source

pub fn denormalize(&self, normalized: f64) -> f64

Map 0.0–1.0 back to a plain value.

Degenerate bounds collapse to min (or 0.0 for Enum with count <= 1). See Self::normalize for the round-trip semantics.

Source

pub fn min(&self) -> f64

Plain-value minimum.

Source

pub fn max(&self) -> f64

Plain-value maximum.

Source

pub fn step_count(&self) -> Option<NonZeroU32>

Number of discrete steps for a quantized range.

None means continuous (Linear / Logarithmic). Some(n) means the range covers n + 1 distinct values (a step count of 3 → 4 picker positions). Cross-format wrappers that serialize a 0 = continuous sentinel into a C struct should call .map(NonZeroU32::get).unwrap_or(0) at the FFI boundary.

Discrete / Enum variants with degenerate bounds (min > max, or count <= 1) return None - semantically continuous, because there’s nothing to step through.

Source

pub fn step_count_usize(&self) -> usize

step_count widened to usize with the continuous case flattened to 1. Convenience for UI code that loops over discrete values and falls back to a single step for continuous ranges.

Source

pub fn base(&self) -> &Self

The underlying range with any Self::Reversed wrapper peeled off. Reversing only flips the axis direction; the base range decides the parameter’s shape (a reversed enum is still an enum). Match on this when classifying by shape - picking a widget, a taper

  • so a reversed enum / toggle isn’t misread as a continuous knob.

Trait Implementations§

Source§

impl Clone for ParamRange

Source§

fn clone(&self) -> ParamRange

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 Copy for ParamRange

Source§

impl Debug for ParamRange

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