alpha2-model 0.9.0

Versioned project and timeline model for alpha2.
Documentation
//! The values a numeric place accepts, shared by validation and by operations that write values.

/// An inclusive range of accepted values; an unbounded end is infinite.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Domain {
    /// The least value.
    pub min: f32,
    /// The greatest value.
    pub max: f32,
}

impl Domain {
    /// Every finite value: positions, scales, rotations.
    pub const ANY: Self = Self::new(f32::NEG_INFINITY, f32::INFINITY);
    /// `0..=1`: opacities, roundness, transition progress.
    pub const UNIT: Self = Self::new(0.0, 1.0);
    /// `0..`: lengths, sizes, feathers.
    pub const NON_NEGATIVE: Self = Self::new(0.0, f32::INFINITY);
    /// `-1..=1`: pans.
    pub const PAN: Self = Self::new(-1.0, 1.0);
    /// `0..=MAX_GAIN`: clip and bus gains.
    pub const GAIN: Self = Self::new(0.0, crate::MAX_GAIN);
    /// Greater than zero: a ducker's threshold.
    pub const POSITIVE: Self = Self::new(f32::from_bits(1), f32::INFINITY);
    /// [`crate::EQ_FREQUENCY_RANGE_HZ`]: equalizer band frequencies.
    pub const EQ_FREQUENCY_HZ: Self = Self::new(
        *crate::EQ_FREQUENCY_RANGE_HZ.start(),
        *crate::EQ_FREQUENCY_RANGE_HZ.end(),
    );
    /// [`crate::EQ_Q_RANGE`]: equalizer band resonances.
    pub const EQ_Q: Self = Self::new(*crate::EQ_Q_RANGE.start(), *crate::EQ_Q_RANGE.end());
    /// Up to [`crate::MAX_EQ_GAIN_DB`] either way: equalizer band gains.
    pub const EQ_GAIN_DB: Self = Self::new(-crate::MAX_EQ_GAIN_DB, crate::MAX_EQ_GAIN_DB);
    /// [`crate::MIN_LEVEL_DB`] to 0: compressor thresholds and ducker depths.
    pub const LEVEL_DB: Self = Self::new(crate::MIN_LEVEL_DB, 0.0);
    /// 1 to [`crate::MAX_COMPRESSOR_RATIO`]: compressor ratios.
    pub const COMPRESSOR_RATIO: Self = Self::new(1.0, crate::MAX_COMPRESSOR_RATIO);
    /// 0 to [`crate::MAX_KNEE_DB`]: compressor knees.
    pub const KNEE_DB: Self = Self::new(0.0, crate::MAX_KNEE_DB);
    /// Up to [`crate::MAX_MAKEUP_DB`] either way: compressor makeup gains.
    pub const MAKEUP_DB: Self = Self::new(-crate::MAX_MAKEUP_DB, crate::MAX_MAKEUP_DB);
    /// 0 to [`crate::MAX_EXPANDER_RANGE_DB`]: expander ranges.
    pub const EXPANDER_RANGE_DB: Self = Self::new(0.0, crate::MAX_EXPANDER_RANGE_DB);
    /// 0 to [`crate::MAX_DELAY_FEEDBACK`]: delay feedbacks.
    pub const DELAY_FEEDBACK: Self = Self::new(0.0, crate::MAX_DELAY_FEEDBACK);
    /// Up to [`crate::MAX_MATRIX_GAIN`] either way: matrix gains.
    pub const MATRIX_GAIN: Self = Self::new(-crate::MAX_MATRIX_GAIN, crate::MAX_MATRIX_GAIN);
    /// The points of a polystar.
    pub const POLYSTAR_POINTS: Self =
        Self::new(crate::MIN_POLYSTAR_POINTS, crate::MAX_POLYSTAR_POINTS);

    /// The range `min..=max`.
    #[must_use]
    pub const fn new(min: f32, max: f32) -> Self {
        Self { min, max }
    }

    /// Whether `value` is finite and inside.
    #[must_use]
    pub fn contains(self, value: f32) -> bool {
        value.is_finite() && self.min <= value && value <= self.max
    }

    /// `value` moved to the nearest end when outside.
    #[must_use]
    pub const fn clamp(self, value: f32) -> f32 {
        value.clamp(self.min, self.max)
    }
}