fix: refactor to avoid circular dependencies
This commit is contained in:
@@ -0,0 +1,383 @@
|
||||
use std::{collections::HashMap, net::IpAddr};
|
||||
use strum_macros::{EnumIter, EnumCount};
|
||||
|
||||
// ------ Enums ------
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum DelayUnit {
|
||||
Millisecond,
|
||||
Meter,
|
||||
Feet,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
||||
pub enum InputChannel {
|
||||
InA,
|
||||
InB,
|
||||
InC,
|
||||
InD,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
||||
pub enum OutputChannel {
|
||||
Out1,
|
||||
Out2,
|
||||
Out3,
|
||||
Out4,
|
||||
Out5,
|
||||
Out6,
|
||||
Out7,
|
||||
Out8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum Channel {
|
||||
Input(InputChannel),
|
||||
Output(OutputChannel),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub enum Ratio {
|
||||
#[default]
|
||||
Ratio1_1,
|
||||
Ratio1_1_1,
|
||||
Ratio1_1_3,
|
||||
Ratio1_1_5,
|
||||
Ratio1_1_7,
|
||||
Ratio1_2,
|
||||
Ratio1_2_5,
|
||||
Ratio1_3,
|
||||
Ratio1_3_5,
|
||||
Ratio1_4,
|
||||
Ratio1_5,
|
||||
Ratio1_6,
|
||||
Ratio1_8,
|
||||
Ratio1_10,
|
||||
Ratio1_20,
|
||||
Limit,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub enum CrossoverFilter {
|
||||
#[default]
|
||||
Bypass,
|
||||
Bw6,
|
||||
Bw12,
|
||||
Bw18,
|
||||
Bw24,
|
||||
Bw30,
|
||||
Bw36,
|
||||
Bw42,
|
||||
Bw48,
|
||||
Lk12,
|
||||
Lk24,
|
||||
Lk36,
|
||||
Lk48,
|
||||
Bl6,
|
||||
Bl12,
|
||||
Bl18,
|
||||
Bl24,
|
||||
Bl30,
|
||||
Bl36,
|
||||
Bl42,
|
||||
Bl48,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||
pub enum PEQBand {
|
||||
B1 = 1,
|
||||
B2,
|
||||
B3,
|
||||
B4,
|
||||
B5,
|
||||
B6,
|
||||
B7,
|
||||
B8,
|
||||
B9,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum PEQFilter {
|
||||
Peak,
|
||||
LowShelf,
|
||||
HighShelf,
|
||||
Lp6Db,
|
||||
Lp12Db,
|
||||
Hp6Db,
|
||||
Hp12Db,
|
||||
AllPass1,
|
||||
AllPass2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||
pub enum DiscreteFrequency {
|
||||
F20,
|
||||
F25,
|
||||
F31_5,
|
||||
F40,
|
||||
F50,
|
||||
F63,
|
||||
F80,
|
||||
F100,
|
||||
F125,
|
||||
F160,
|
||||
F200,
|
||||
F250,
|
||||
F315,
|
||||
F400,
|
||||
F500,
|
||||
F630,
|
||||
F800,
|
||||
F1000,
|
||||
F1250,
|
||||
F1600,
|
||||
F2000,
|
||||
F2500,
|
||||
F3150,
|
||||
F4000,
|
||||
F5000,
|
||||
F6300,
|
||||
F8000,
|
||||
F10000,
|
||||
F12500,
|
||||
F16000,
|
||||
F20000,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum InputType {
|
||||
Analog,
|
||||
PinkNoise,
|
||||
WhiteNoise,
|
||||
SineWave,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct InputSource {
|
||||
pub r#type: InputType,
|
||||
pub frequency: DiscreteFrequency,
|
||||
}
|
||||
|
||||
// ------ Response types ------
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Acknowledgement {
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct NotImplemented;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct HandshakeAck {
|
||||
pub ack: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct DeviceInfo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct CurrentPreset {
|
||||
pub index: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ModifiedPreset {
|
||||
pub modified: Vec<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PresetName {
|
||||
pub index: u8,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DeviceFlags {
|
||||
pub is_locked: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct AuthenticationResult {
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Meters {
|
||||
pub levels: Vec<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConfigChunk {
|
||||
pub sub_index: u8,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct UnknownResponse {
|
||||
pub cmd: String,
|
||||
pub raw: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DeviceResponseType {
|
||||
Acknowledgement(Acknowledgement),
|
||||
NotImplemented(NotImplemented),
|
||||
HandshakeAck(HandshakeAck),
|
||||
DeviceInfo(DeviceInfo),
|
||||
PresetName(PresetName),
|
||||
DeviceFlags(DeviceFlags),
|
||||
AuthenticationResult(AuthenticationResult),
|
||||
Meters(Meters),
|
||||
CurrentPreset(CurrentPreset),
|
||||
ModifiedPreset(ModifiedPreset),
|
||||
ConfigChunk(ConfigChunk),
|
||||
UnknownResponse(UnknownResponse),
|
||||
}
|
||||
|
||||
// ------ State ------
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Gate {
|
||||
pub attack: u16,
|
||||
pub release: u16,
|
||||
pub hold: u16,
|
||||
pub threshold: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Compressor {
|
||||
pub threshold: f32,
|
||||
pub ratio: Ratio,
|
||||
pub attack: u16,
|
||||
pub release: u16,
|
||||
pub knee: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Limiter {
|
||||
pub threshold: f32,
|
||||
pub attack: u16,
|
||||
pub release: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct GraphicEQ {
|
||||
pub gains: Vec<f32>,
|
||||
pub bypass: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PEQ {
|
||||
pub gain: f32,
|
||||
pub frequency: f32,
|
||||
pub q: f32,
|
||||
pub filter_type: PEQFilter,
|
||||
pub bypass: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct CrossoverFilters {
|
||||
pub high_pass: Crossover,
|
||||
pub low_pass: Crossover,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Crossover {
|
||||
pub frequency: f32,
|
||||
pub slope: CrossoverFilter,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct MatrixRoutes {
|
||||
pub connected: Vec<InputChannel>,
|
||||
pub gains: Vec<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct PEQChain {
|
||||
pub bands: Vec<PEQ>,
|
||||
pub bypass: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PresetBank {
|
||||
pub current_index: usize,
|
||||
pub names: Vec<String>,
|
||||
pub modified: Vec<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct DeviceConnection {
|
||||
pub host: IpAddr,
|
||||
pub port: u16,
|
||||
pub device_id: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct InputChannelState {
|
||||
pub name: String,
|
||||
pub gain: f32,
|
||||
pub phase_inverted: bool,
|
||||
pub delay: f32,
|
||||
pub gate: Gate,
|
||||
pub geq: GraphicEQ,
|
||||
pub peq_chain: PEQChain,
|
||||
pub crossover: CrossoverFilters,
|
||||
pub linked_channels: Vec<Channel>,
|
||||
pub mute: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct OutputChannelState {
|
||||
pub name: String,
|
||||
pub matrix_routes: MatrixRoutes,
|
||||
pub crossover: CrossoverFilters,
|
||||
pub peq_chain: PEQChain,
|
||||
pub compressor: Compressor,
|
||||
pub limiter: Limiter,
|
||||
pub gain: f32,
|
||||
pub phase_inverted: bool,
|
||||
pub delay: f32,
|
||||
pub linked_channels: Vec<Channel>,
|
||||
pub mute: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DSPConfigState {
|
||||
pub(crate) input_states: HashMap<InputChannel, InputChannelState>,
|
||||
pub(crate) output_states: HashMap<OutputChannel, OutputChannelState>,
|
||||
pub(crate) input_source: InputSource,
|
||||
pub(crate) delay_unit: DelayUnit,
|
||||
}
|
||||
|
||||
impl DSPConfigState {
|
||||
pub fn input_state_mut(
|
||||
&mut self,
|
||||
channel: InputChannel,
|
||||
) -> &mut InputChannelState {
|
||||
self.input_states
|
||||
.get_mut(&channel)
|
||||
.expect("Invalid input channel state")
|
||||
}
|
||||
|
||||
pub fn output_state_mut(
|
||||
&mut self,
|
||||
channel: OutputChannel,
|
||||
) -> &mut OutputChannelState {
|
||||
self.output_states
|
||||
.get_mut(&channel)
|
||||
.expect("Invalid output channel state")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DSPState {
|
||||
pub(crate) name: String,
|
||||
pub(crate) flags: DeviceFlags,
|
||||
pub(crate) presets: PresetBank,
|
||||
|
||||
pub(crate) current_config: DSPConfigState,
|
||||
}
|
||||
Reference in New Issue
Block a user