434 lines
9.9 KiB
Rust
434 lines
9.9 KiB
Rust
use std::{collections::HashMap, net::IpAddr};
|
|
use strum_macros::{EnumCount, EnumIter};
|
|
|
|
#[cfg(feature = "serialization")]
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
// ------ Enums ------
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum DelayUnit {
|
|
Millisecond,
|
|
Meter,
|
|
Feet,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
|
pub enum InputChannel {
|
|
InA,
|
|
InB,
|
|
InC,
|
|
InD,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
|
pub enum OutputChannel {
|
|
Out1,
|
|
Out2,
|
|
Out3,
|
|
Out4,
|
|
Out5,
|
|
Out6,
|
|
Out7,
|
|
Out8,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
pub enum Channel {
|
|
Input(InputChannel),
|
|
Output(OutputChannel),
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
|
pub enum PEQBand {
|
|
B1 = 1,
|
|
B2,
|
|
B3,
|
|
B4,
|
|
B5,
|
|
B6,
|
|
B7,
|
|
B8,
|
|
B9,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum PEQFilter {
|
|
Peak,
|
|
LowShelf,
|
|
HighShelf,
|
|
Lp6Db,
|
|
Lp12Db,
|
|
Hp6Db,
|
|
Hp12Db,
|
|
AllPass1,
|
|
AllPass2,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum InputType {
|
|
Analog,
|
|
PinkNoise,
|
|
WhiteNoise,
|
|
SineWave,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct Meter {
|
|
pub rms: f32,
|
|
pub peak: f32,
|
|
pub clip: bool,
|
|
}
|
|
|
|
#[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(InputMeters, OutputMeters),
|
|
CurrentPreset(CurrentPreset),
|
|
ModifiedPreset(ModifiedPreset),
|
|
ConfigChunk(ConfigChunk),
|
|
UnknownResponse(UnknownResponse),
|
|
}
|
|
|
|
// ------ State ------
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
pub struct Gate {
|
|
pub attack: u16,
|
|
pub release: u16,
|
|
pub hold: u16,
|
|
pub threshold: f32,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
pub struct Compressor {
|
|
pub threshold: f32,
|
|
pub ratio: Ratio,
|
|
pub attack: u16,
|
|
pub release: u16,
|
|
pub knee: u16,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
pub struct Limiter {
|
|
pub threshold: f32,
|
|
pub attack: u16,
|
|
pub release: u16,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct GraphicEQ {
|
|
pub gains: HashMap<DiscreteFrequency, f32>,
|
|
pub bypass: bool,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct PEQ {
|
|
pub gain: f32,
|
|
pub frequency: f32,
|
|
pub q: f32,
|
|
pub filter_type: PEQFilter,
|
|
pub bypass: bool,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
pub struct CrossoverFilters {
|
|
pub high_pass: Crossover,
|
|
pub low_pass: Crossover,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
pub struct Crossover {
|
|
pub frequency: f32,
|
|
pub slope: CrossoverFilter,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct MatrixRoutes {
|
|
pub connected: Vec<InputChannel>,
|
|
pub gains: HashMap<InputChannel, f32>,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct PEQChain {
|
|
pub bands: HashMap<PEQBand, PEQ>,
|
|
pub bypass: bool,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct PresetBank {
|
|
pub current_index: usize,
|
|
pub names: Vec<String>,
|
|
pub modified: Vec<bool>,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct DeviceConnection {
|
|
pub host: IpAddr,
|
|
pub port: u16,
|
|
pub device_id: u8,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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<InputChannel>,
|
|
pub mute: bool,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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<OutputChannel>,
|
|
pub mute: bool,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[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(crate) fn input_state_mut(&mut self, channel: InputChannel) -> &mut InputChannelState {
|
|
self.input_states
|
|
.get_mut(&channel)
|
|
.expect("Invalid input channel state")
|
|
}
|
|
|
|
pub(crate) fn output_state_mut(&mut self, channel: OutputChannel) -> &mut OutputChannelState {
|
|
self.output_states
|
|
.get_mut(&channel)
|
|
.expect("Invalid output channel state")
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum DSPMode {
|
|
Demo,
|
|
Normal,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum ConnectionStatus {
|
|
Connected,
|
|
Disconnected,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct DSPState {
|
|
pub(crate) name: String,
|
|
pub(crate) flags: DeviceFlags,
|
|
pub(crate) presets: PresetBank,
|
|
pub(crate) current_config: DSPConfigState,
|
|
pub(crate) connection: ConnectionStatus,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct InputMeters {
|
|
pub meters: HashMap<InputChannel, Meter>,
|
|
}
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct OutputMeters {
|
|
pub meters: HashMap<OutputChannel, Meter>,
|
|
}
|