From c89ca20295c500e2db987bba9b2508165a7cef11 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 6 Dec 2022 20:51:51 -0500 Subject: [PATCH] Fix cava --- common/src/cava.rs | 1 - common/src/pattern/visualizer.rs | 14 +++++++++++--- src/ui.rs | 4 ---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common/src/cava.rs b/common/src/cava.rs index 238cc43..6f30ee0 100644 --- a/common/src/cava.rs +++ b/common/src/cava.rs @@ -27,7 +27,6 @@ impl Cava { let mut cava_process = Command::new("cava") .arg("-p") .arg(config_file) - // .stdin(Stdio::piped()) .stderr(Stdio::piped()) .stdout(Stdio::piped()) .spawn() diff --git a/common/src/pattern/visualizer.rs b/common/src/pattern/visualizer.rs index fd656f8..c225ea2 100644 --- a/common/src/pattern/visualizer.rs +++ b/common/src/pattern/visualizer.rs @@ -12,12 +12,14 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct VisualizerParams { + pub from_color: Rgb, pub color: Rgb, } impl Default for VisualizerParams { fn default() -> Self { Self { + from_color: color::BLACK, color: color::WHITE, } } @@ -25,12 +27,17 @@ impl Default for VisualizerParams { impl FormRender for VisualizerParams { fn render(&self) -> String { - self.color.render("color", None) + [ + self.color.render("from_color", None), + self.color.render("color", None), + ] + .concat() } } #[derive(Debug)] pub struct Visualizer { + from_color: Rgb, color: Rgb, lights_buf: VecDeque, cava: Option, @@ -46,6 +53,7 @@ impl Visualizer { pub fn new(params: &VisualizerParams) -> Self { Self { color: params.color, + from_color: params.from_color, lights_buf: VecDeque::new(), cava: None, } @@ -58,7 +66,7 @@ impl Pattern for Visualizer { let reading = c .get_latest_reading() .into_iter() - .map(|b| color::BLACK.fade_to(self.color, b)) + .map(|b| self.from_color.fade_to(self.color, b)) .collect(); let changed = self.lights_buf != reading; @@ -76,7 +84,7 @@ impl Pattern for Visualizer { return Err(PatternError::LightCount); } - self.cava = Some(Cava::new(num_lights)?); + self.cava = Some(Cava::new(num_lights * 2)?); Ok(()) } diff --git a/src/ui.rs b/src/ui.rs index 2b56adb..8531361 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -64,10 +64,6 @@ fn parse_cmd(strip_tx: &Sender, s: &str) -> Result<(), String> { let color = parse_color(r, g, b)?; change_pattern(strip_tx, Box::new(pattern::Solid::new(&pattern::SolidParams {color}))) } - ["visualizer", c] => { - let color = parse_color(c,c,c)?; - change_pattern(strip_tx, Box::new(pattern::Visualizer::new(&pattern::VisualizerParams { color }))) - } ["c", c] => { let color = parse_color(c, c, c)?; change_pattern(strip_tx, Box::new(pattern::Solid::new(&pattern::SolidParams {color})))