From 3cf7c279a83a10eb46bdc66a7b8896619bfa58b8 Mon Sep 17 00:00:00 2001 From: LucasDLTG Date: Sun, 20 Sep 2026 21:39:47 +0200 Subject: [PATCH] feat: default meters + update state on link --- src/dsp408/client/dsp408.rs | 56 +++++++++++++++++++++++++++++++++---- src/dsp408/default.rs | 38 +++++++++++++++++++++---- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/dsp408/client/dsp408.rs b/src/dsp408/client/dsp408.rs index e039e22..a936be7 100644 --- a/src/dsp408/client/dsp408.rs +++ b/src/dsp408/client/dsp408.rs @@ -10,8 +10,7 @@ use std::{ use crate::{ common::errors::DSPError, dsp408::{ - default::default_input_meters, - default::default_output_meters, + default::{default_input_meters, default_output_meters}, default_dsp_state, mapper::{ self, @@ -19,7 +18,7 @@ use crate::{ response::map_response, }, protocol::{commands, config::decode_config, frame::extract_frame}, - types::{self}, + types::self, }, }; @@ -1514,9 +1513,6 @@ impl DSP408 { if !self.request_acknowledgement()? { return Ok(false); } - - let config = self.read_config_state()?; - self.state_mut().current_config = config; } types::DSPMode::Demo => { @@ -1528,6 +1524,54 @@ impl DSP408 { } } + let state = self.state_mut(); + + match source { + types::Channel::Input(s) => { + let input_destinations: Vec = destinations + .iter() + .filter_map(|destination| match destination { + types::Channel::Input(input) => Some(*input), + types::Channel::Output(_) => None, + }) + .collect(); + + let states = &mut state.current_config.input_states; + + // Remove the source and destinations from all existing links. + for channel_state in states.values_mut() { + channel_state + .linked_channels + .retain(|channel| *channel != s && !input_destinations.contains(channel)); + } + + // Link source -> destinations. + states.get_mut(&s).unwrap().linked_channels = input_destinations; + } + + types::Channel::Output(s) => { + let output_destinations: Vec = destinations + .iter() + .filter_map(|destination| match destination { + types::Channel::Output(output) => Some(*output), + types::Channel::Input(_) => None, + }) + .collect(); + + let states = &mut state.current_config.output_states; + + // Remove the source and destinations from all existing links. + for channel_state in states.values_mut() { + channel_state + .linked_channels + .retain(|channel| *channel != s && !output_destinations.contains(channel)); + } + + // Link source -> destinations. + states.get_mut(&s).unwrap().linked_channels = output_destinations; + } + } + Ok(true) } diff --git a/src/dsp408/default.rs b/src/dsp408/default.rs index a586971..0bd0104 100644 --- a/src/dsp408/default.rs +++ b/src/dsp408/default.rs @@ -75,16 +75,44 @@ fn default_config() -> DSPConfigState { fn default_input_states() -> HashMap { [ - (InputChannel::InA, default_input_channel_state("In A")), - (InputChannel::InB, default_input_channel_state("In B")), - (InputChannel::InC, default_input_channel_state("In C")), - (InputChannel::InD, default_input_channel_state("In D")), + ( + InputChannel::InA, + default_input_channel_state("In A", false), + ), + (InputChannel::InB, default_input_channel_state("In B", true)), + ( + InputChannel::InC, + default_input_channel_state("In C", false), + ), + ( + InputChannel::InD, + default_input_channel_state("In D", false), + ), ] .into_iter() .collect() } -fn default_input_channel_state(name: &str) -> InputChannelState { +fn default_input_channel_state(name: &str, a: bool) -> InputChannelState { + if a { + return InputChannelState { + name: name.to_string(), + + gain: 0.0, + phase_inverted: false, + delay: 0.0, + + gate: default_gate(), + geq: default_graphic_eq(), + peq_chain: default_peq_chain(), + crossover: default_crossover_filters(), + + linked_channels: vec![InputChannel::InA], + // linked_channels: Vec::new(), + mute: false, + }; + } + InputChannelState { name: name.to_string(),