feat: decode meters clip indicators
This commit is contained in:
@@ -277,7 +277,7 @@ impl DSP408 {
|
||||
}
|
||||
|
||||
// Command `0x13` (Device Name)
|
||||
pub fn get_device_name(&mut self) -> Result<String, DSPError> {
|
||||
fn get_device_name(&mut self) -> Result<String, DSPError> {
|
||||
let request = commands::build_request_device_name();
|
||||
|
||||
let resp = self.send_recv(&request)?;
|
||||
@@ -292,7 +292,7 @@ impl DSP408 {
|
||||
}
|
||||
|
||||
// Command `0x14` (Current Preset Index)
|
||||
pub fn get_current_preset(&mut self) -> Result<u8, DSPError> {
|
||||
fn get_current_preset(&mut self) -> Result<u8, DSPError> {
|
||||
let request = commands::build_get_current_preset();
|
||||
|
||||
let resp = self.send_recv(&request)?;
|
||||
@@ -400,7 +400,7 @@ impl DSP408 {
|
||||
}
|
||||
|
||||
// Command `0x22` (Get Preset Modification Status)
|
||||
pub fn get_preset_modification_status(&mut self) -> Result<types::ModifiedPreset, DSPError> {
|
||||
fn get_preset_modification_status(&mut self) -> Result<types::ModifiedPreset, DSPError> {
|
||||
let request = commands::build_preset_modification_status();
|
||||
|
||||
let resp = self.send_recv(&request)?;
|
||||
@@ -447,8 +447,20 @@ impl DSP408 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let state = self.state_mut()?;
|
||||
let current_index = {
|
||||
let state = self.state()?;
|
||||
state.presets.current_index
|
||||
};
|
||||
|
||||
if !self.store_current_configuration(current_index, true)? {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
if !self.request_acknowledgement()? {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let state = self.state_mut()?;
|
||||
state.presets.names[state.presets.current_index] = name.to_string();
|
||||
|
||||
Ok(true)
|
||||
@@ -478,7 +490,7 @@ impl DSP408 {
|
||||
}
|
||||
|
||||
// Command `0x29` (Preset Name)
|
||||
pub fn get_preset_name(&mut self, preset_index: usize) -> Result<String, DSPError> {
|
||||
fn get_preset_name(&mut self, preset_index: usize) -> Result<String, DSPError> {
|
||||
let raw_index = mapper::preset_index_without_factory_to_raw(preset_index)?;
|
||||
|
||||
let request = commands::build_get_preset_name(raw_index)?;
|
||||
@@ -516,7 +528,7 @@ impl DSP408 {
|
||||
}
|
||||
|
||||
// Command `0x2C` (Device Flags)
|
||||
pub fn get_device_flags(&mut self) -> Result<types::DeviceFlags, DSPError> {
|
||||
fn get_device_flags(&mut self) -> Result<types::DeviceFlags, DSPError> {
|
||||
let request = commands::build_get_device_flags();
|
||||
|
||||
let resp = self.send_recv(&request)?;
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::{
|
||||
},
|
||||
types::{
|
||||
Acknowledgement, AuthenticationResult, ConfigChunk, CurrentPreset, DeviceFlags,
|
||||
DeviceInfo, DeviceResponseType, HandshakeAck, Meters, ModifiedPreset, NotImplemented,
|
||||
PresetName, UnknownResponse,
|
||||
DeviceInfo, DeviceResponseType, HandshakeAck, Meter, Meters, ModifiedPreset,
|
||||
NotImplemented, PresetName, UnknownResponse,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -170,13 +170,10 @@ pub fn map_response(frame: &Frame) -> Result<DeviceResponseType, ProtocolError>
|
||||
return Err(ProtocolError::new("Not enough bytes for meter levels"));
|
||||
}
|
||||
|
||||
let floats: Vec<f32> = (0..36)
|
||||
// Bytes 0..36 = 12 × 3-byte meter levels
|
||||
let levels: Vec<f32> = (0..36)
|
||||
.step_by(3)
|
||||
.map(|i| decode_float16(payload[i], payload[i + 1]).unwrap_or_default())
|
||||
.collect();
|
||||
|
||||
let meters: Vec<f32> = floats
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
if f < METERS_SPLIT {
|
||||
METERS_SPLIT_LEVEL_DB + (f - METERS_SPLIT) / METERS_LOW_STEP
|
||||
@@ -186,7 +183,30 @@ pub fn map_response(frame: &Frame) -> Result<DeviceResponseType, ProtocolError>
|
||||
})
|
||||
.collect();
|
||||
|
||||
return Ok(DeviceResponseType::Meters(Meters { levels: meters }));
|
||||
// Byte 36 = input clip bitmask
|
||||
let input_clip_mask = payload[36];
|
||||
|
||||
// Byte 37 = output clip bitmask
|
||||
let output_clip_mask = payload[37];
|
||||
|
||||
let channels = levels
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, level)| {
|
||||
let clip = if index < 4 {
|
||||
// InA..InD
|
||||
input_clip_mask & (1 << index) != 0
|
||||
} else {
|
||||
// Out1..Out8
|
||||
let output_index = index - 4;
|
||||
output_clip_mask & (1 << output_index) != 0
|
||||
};
|
||||
|
||||
Meter { level, clip }
|
||||
})
|
||||
.collect();
|
||||
|
||||
return Ok(DeviceResponseType::Meters(Meters { channels }));
|
||||
}
|
||||
|
||||
Ok(DeviceResponseType::UnknownResponse(UnknownResponse {
|
||||
@@ -197,6 +217,8 @@ pub fn map_response(frame: &Frame) -> Result<DeviceResponseType, ProtocolError>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn frame(command: u8, payload: Vec<u8>) -> Frame {
|
||||
@@ -415,10 +437,10 @@ mod tests {
|
||||
|
||||
match result {
|
||||
DeviceResponseType::Meters(m) => {
|
||||
assert_eq!(m.levels.len(), 12);
|
||||
assert_eq!(m.channels.len(), 12);
|
||||
|
||||
for level in m.levels {
|
||||
assert!(level.is_finite());
|
||||
for channel in m.channels {
|
||||
assert!(channel.level.is_finite());
|
||||
}
|
||||
}
|
||||
other => panic!("unexpected {:?}", other),
|
||||
|
||||
+38
-2
@@ -1,8 +1,12 @@
|
||||
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,
|
||||
@@ -10,6 +14,7 @@ pub enum DelayUnit {
|
||||
Feet,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
||||
pub enum InputChannel {
|
||||
InA,
|
||||
@@ -18,6 +23,7 @@ pub enum InputChannel {
|
||||
InD,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, EnumCount, PartialOrd, Ord)]
|
||||
pub enum OutputChannel {
|
||||
Out1,
|
||||
@@ -30,12 +36,14 @@ pub enum OutputChannel {
|
||||
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]
|
||||
@@ -57,6 +65,7 @@ pub enum Ratio {
|
||||
Limit,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub enum CrossoverFilter {
|
||||
#[default]
|
||||
@@ -96,6 +105,7 @@ pub enum PEQBand {
|
||||
B9,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum PEQFilter {
|
||||
Peak,
|
||||
@@ -109,6 +119,7 @@ pub enum PEQFilter {
|
||||
AllPass2,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||
pub enum DiscreteFrequency {
|
||||
F20,
|
||||
@@ -144,6 +155,7 @@ pub enum DiscreteFrequency {
|
||||
F20000,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum InputType {
|
||||
Analog,
|
||||
@@ -152,6 +164,7 @@ pub enum InputType {
|
||||
SineWave,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct InputSource {
|
||||
pub r#type: InputType,
|
||||
@@ -194,6 +207,7 @@ pub struct PresetName {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DeviceFlags {
|
||||
pub is_locked: bool,
|
||||
@@ -204,9 +218,17 @@ pub struct AuthenticationResult {
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Meter {
|
||||
pub level: f32,
|
||||
pub clip: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Meters {
|
||||
pub levels: Vec<f32>,
|
||||
pub channels: Vec<Meter>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -238,7 +260,7 @@ pub enum DeviceResponseType {
|
||||
}
|
||||
|
||||
// ------ State ------
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Gate {
|
||||
pub attack: u16,
|
||||
@@ -247,6 +269,7 @@ pub struct Gate {
|
||||
pub threshold: f32,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Compressor {
|
||||
pub threshold: f32,
|
||||
@@ -256,6 +279,7 @@ pub struct Compressor {
|
||||
pub knee: u16,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Limiter {
|
||||
pub threshold: f32,
|
||||
@@ -263,12 +287,14 @@ pub struct Limiter {
|
||||
pub release: u16,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct GraphicEQ {
|
||||
pub gains: Vec<f32>,
|
||||
pub bypass: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PEQ {
|
||||
pub gain: f32,
|
||||
@@ -278,30 +304,35 @@ pub struct PEQ {
|
||||
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: Vec<f32>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct PEQChain {
|
||||
pub bands: Vec<PEQ>,
|
||||
pub bypass: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PresetBank {
|
||||
pub current_index: usize,
|
||||
@@ -309,6 +340,7 @@ pub struct PresetBank {
|
||||
pub modified: Vec<bool>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct DeviceConnection {
|
||||
pub host: IpAddr,
|
||||
@@ -316,6 +348,7 @@ pub struct DeviceConnection {
|
||||
pub device_id: u8,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct InputChannelState {
|
||||
pub name: String,
|
||||
@@ -330,6 +363,7 @@ pub struct InputChannelState {
|
||||
pub mute: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct OutputChannelState {
|
||||
pub name: String,
|
||||
@@ -345,6 +379,7 @@ pub struct OutputChannelState {
|
||||
pub mute: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DSPConfigState {
|
||||
pub(crate) input_states: HashMap<InputChannel, InputChannelState>,
|
||||
@@ -367,6 +402,7 @@ impl DSPConfigState {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DSPState {
|
||||
pub(crate) name: String,
|
||||
|
||||
Reference in New Issue
Block a user