Formatter

Enum Formatter 

Source
pub enum Formatter {
    Float {
        precision: usize,
    },
    Decibel {
        precision: usize,
    },
    DecibelDirect {
        precision: usize,
        min_db: f64,
    },
    Frequency,
    Milliseconds {
        precision: usize,
    },
    Seconds {
        precision: usize,
    },
    Percent {
        precision: usize,
    },
    Pan,
    Ratio {
        precision: usize,
    },
    Semitones,
    Boolean,
}
Expand description

Parameter value formatter.

Defines how plain parameter values are converted to display strings and parsed back from user input.

Variants§

§

Float

Generic float with configurable precision (e.g., “1.23”).

Fields

§precision: usize

Number of decimal places.

§

Decibel

Decibel formatter for gain/level parameters.

Input is linear amplitude (0.0 = silence, 1.0 = unity). Display: “-12.0 dB”, “-inf dB”

Fields

§precision: usize

Number of decimal places.

§

DecibelDirect

Direct decibel formatter where input is already in dB.

Used by FloatParam::db() where the plain value is stored as dB. Display: “+12.0 dB”, “-60.0 dB”

Fields

§precision: usize

Number of decimal places.

§min_db: f64

Minimum dB value (below this shows “-inf dB”)

§

Frequency

Frequency formatter with automatic Hz/kHz scaling.

Display: “440 Hz”, “1.50 kHz”

§

Milliseconds

Milliseconds formatter.

Display: “10.0 ms”

Fields

§precision: usize

Number of decimal places.

§

Seconds

Seconds formatter.

Display: “1.50 s”

Fields

§precision: usize

Number of decimal places.

§

Percent

Percentage formatter.

Input is 0.0-1.0, display is 0%-100%. Display: “75%”

Fields

§precision: usize

Number of decimal places.

§

Pan

Pan formatter for stereo position.

Input is -1.0 (left) to +1.0 (right). Display: “L50”, “C”, “R50”

§

Ratio

Ratio formatter for compressors.

Display: “4.0:1”, “∞:1”

Fields

§precision: usize

Number of decimal places.

§

Semitones

Semitones formatter for pitch shifting.

Display: “+12 st”, “-7 st”, “0 st”

§

Boolean

Boolean formatter.

Display: “On”, “Off”

Implementations§

Source§

impl Formatter

Source

pub fn format(&self, value: f64) -> String

Format a plain value to a display string.

The interpretation of value depends on the formatter variant:

  • Decibel: linear amplitude (1.0 = 0 dB)
  • Frequency: Hz
  • Milliseconds: ms
  • Seconds: s
  • Percent: 0.0-1.0 (displayed as 0%-100%)
  • Pan: -1.0 to +1.0
  • Ratio: ratio value (4.0 = “4:1”)
  • Semitones: integer semitones
  • Boolean: >0.5 = On, <=0.5 = Off
Source

pub fn parse(&self, s: &str) -> Option<f64>

Parse a display string to a plain value.

Returns None if the string cannot be parsed. Accepts various formats with or without units.

Source

pub fn units(&self) -> &'static str

Get the unit string for this formatter (for ParamInfo).

Trait Implementations§

Source§

impl Clone for Formatter

Source§

fn clone(&self) -> Formatter

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Formatter

Source§

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

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

impl Default for Formatter

Source§

fn default() -> Self

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

impl PartialEq for Formatter

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Formatter

Source§

impl StructuralPartialEq for Formatter

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.