From 455585eeb6165457b2388da4cb185a8b179e1a34 Mon Sep 17 00:00:00 2001 From: LucasDLTG Date: Mon, 20 Jul 2026 22:13:51 +0200 Subject: [PATCH] refactor: reorganize client constants --- src/dsp408/client/constants.rs | 56 +++++++++++++++++----------------- src/dsp408/mapper/channel.rs | 2 +- src/dsp408/mapper/response.rs | 6 ++-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/dsp408/client/constants.rs b/src/dsp408/client/constants.rs index f8752dc..8e2519a 100644 --- a/src/dsp408/client/constants.rs +++ b/src/dsp408/client/constants.rs @@ -14,41 +14,15 @@ pub const PASSWORD_PADDING: u8 = 0x00; pub const ATTACK_MS_RANGE: RangeInclusive = 1..=999; pub const RELEASE_MS_RANGE: RangeInclusive = 10..=3000; -pub const HOLD_MS_RANGE: RangeInclusive = 10..=999; -pub const GATE_THRESHOLD_DB_RANGE: RangeInclusive = -90.0..=0.0; -pub const EQ_GAIN_DB_RANGE: RangeInclusive = -12.0..=12.0; -pub const COMPRESSOR_KNEE_DB_RANGE: RangeInclusive = 0..=12; +pub const KNEE_DB_RANGE: RangeInclusive = 0..=12; pub const THRESHOLD_DB_RANGE: RangeInclusive = -90.0..=20.0; pub const FREQUENCY_HZ_RANGE: RangeInclusive = 19.7..=20160.0; +pub const EQ_GAIN_DB_RANGE: RangeInclusive = -12.0..=12.0; pub const PEQ_Q_RANGE: RangeInclusive = 0.40..=128.0; pub const PEQ_INPUT_BAND_COUNT: usize = 8; pub const PEQ_OUTPUT_BAND_COUNT:usize = 9; - -pub const GAIN_DB_RANGE: RangeInclusive = -60.0..=12.0; -pub const GAIN_SPLIT_DB: f32 = -20.0; -pub const GAIN_LOW_STEP_DB: f32 = 0.5; -pub const GAIN_HIGH_STEP_DB: f32 = 0.1; - -pub const CHANNEL_NAME_LENGTH: usize = 8; -pub const CHANNEL_NAME_PADDING: u8 = 0x00; - -pub const METERS_SPLIT: f32 = 1.0; -pub const METERS_SPLIT_LEVEL: f32 = -18.0; -pub const METERS_LOW_STEP: f32 = 0.0104; -pub const METERS_HIGH_STEP: f32 = 0.0208; - -pub const MATRIX_GAIN_DB_RANGE: RangeInclusive = -60.0..=0.0; - -pub fn delay_range(unit: DelayUnit) -> (f32, f32) { - match unit { - DelayUnit::Millisecond => (0.000, 680.000), - DelayUnit::Meter => (0.000, 233.580), - DelayUnit::Feet => (0.000, 766.329), - } -} - pub fn peq_q_range(filter: PEQFilter) -> RangeInclusive { match filter { PEQFilter::Peak @@ -67,3 +41,29 @@ pub fn peq_q_range(filter: PEQFilter) -> RangeInclusive { } } } + +pub const GAIN_DB_RANGE: RangeInclusive = -60.0..=12.0; +pub const GAIN_SPLIT_DB: f32 = -20.0; +pub const GAIN_LOW_STEP_DB: f32 = 0.5; +pub const GAIN_HIGH_STEP_DB: f32 = 0.1; + +pub fn delay_range(unit: DelayUnit) -> (f32, f32) { + match unit { + DelayUnit::Millisecond => (0.000, 680.000), + DelayUnit::Meter => (0.000, 233.580), + DelayUnit::Feet => (0.000, 766.329), + } +} + +pub const CHANNEL_NAME_LENGTH: usize = 8; +pub const CHANNEL_NAME_PADDING: u8 = 0x00; + +pub const GATE_THRESHOLD_DB_RANGE: RangeInclusive = -90.0..=0.0; +pub const HOLD_MS_RANGE: RangeInclusive = 10..=999; + +pub const MATRIX_GAIN_DB_RANGE: RangeInclusive = -60.0..=0.0; + +pub const METERS_SPLIT: f32 = 1.0; +pub const METERS_SPLIT_LEVEL_DB: f32 = -18.0; +pub const METERS_LOW_STEP: f32 = 0.0104; +pub const METERS_HIGH_STEP: f32 = 0.0208; \ No newline at end of file diff --git a/src/dsp408/mapper/channel.rs b/src/dsp408/mapper/channel.rs index 1491cec..e9a536f 100644 --- a/src/dsp408/mapper/channel.rs +++ b/src/dsp408/mapper/channel.rs @@ -615,7 +615,7 @@ pub fn raw_to_ratio(value: u16) -> Result { pub fn knee_db_to_raw(db: u16) -> Result { validate_range( db, - client_constants::COMPRESSOR_KNEE_DB_RANGE, + client_constants::KNEE_DB_RANGE, || format!("Invalid compressor knee: {db}"), )?; diff --git a/src/dsp408/mapper/response.rs b/src/dsp408/mapper/response.rs index 5cbb920..ff358e5 100644 --- a/src/dsp408/mapper/response.rs +++ b/src/dsp408/mapper/response.rs @@ -1,4 +1,4 @@ -use crate::dsp408::client::constants::{METERS_HIGH_STEP, METERS_LOW_STEP, METERS_SPLIT, METERS_SPLIT_LEVEL}; +use crate::dsp408::client::constants::{METERS_HIGH_STEP, METERS_LOW_STEP, METERS_SPLIT, METERS_SPLIT_LEVEL_DB}; use crate::dsp408::client::types::{ Acknowledgement, AuthenticationResult, ConfigChunk, CurrentPreset, DeviceFlags, DeviceInfo, DeviceResponseType, HandshakeAck, Meters, ModifiedPreset, NotImplemented, PresetName, @@ -173,9 +173,9 @@ pub fn map_response(frame: &Frame) -> Result .into_iter() .map(|f| { if f < METERS_SPLIT { - METERS_SPLIT_LEVEL + (f - METERS_SPLIT) / METERS_LOW_STEP + METERS_SPLIT_LEVEL_DB + (f - METERS_SPLIT) / METERS_LOW_STEP } else { - METERS_SPLIT_LEVEL + (f - METERS_SPLIT) / METERS_HIGH_STEP + METERS_SPLIT_LEVEL_DB + (f - METERS_SPLIT) / METERS_HIGH_STEP } }) .collect();