Feat: begin slight refactoring

This commit is contained in:
2026-02-01 12:38:48 +01:00
parent 5b4a6ddd14
commit c356aebfde
39 changed files with 4699 additions and 3168 deletions

View File

@@ -1,4 +1,4 @@
use crate::theme::meter;
use crate::theme;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
@@ -18,7 +18,7 @@ pub enum Orientation {
pub struct Scope<'a> {
data: &'a [f32],
orientation: Orientation,
color: Color,
color: Option<Color>,
gain: f32,
}
@@ -27,7 +27,7 @@ impl<'a> Scope<'a> {
Self {
data,
orientation: Orientation::Horizontal,
color: meter::LOW,
color: None,
gain: 1.0,
}
}
@@ -38,7 +38,7 @@ impl<'a> Scope<'a> {
}
pub fn color(mut self, c: Color) -> Self {
self.color = c;
self.color = Some(c);
self
}
}
@@ -49,11 +49,13 @@ impl Widget for Scope<'_> {
return;
}
let color = self.color.unwrap_or_else(|| theme::get().meter.low);
match self.orientation {
Orientation::Horizontal => {
render_horizontal(self.data, area, buf, self.color, self.gain)
render_horizontal(self.data, area, buf, color, self.gain)
}
Orientation::Vertical => render_vertical(self.data, area, buf, self.color, self.gain),
Orientation::Vertical => render_vertical(self.data, area, buf, color, self.gain),
}
}
}
@@ -64,7 +66,6 @@ fn render_horizontal(data: &[f32], area: Rect, buf: &mut Buffer, color: Color, g
let fine_width = width * 2;
let fine_height = height * 4;
// Auto-scale: find peak amplitude and normalize to fill height
let peak = data.iter().map(|s| s.abs()).fold(0.0f32, f32::max);
let auto_gain = if peak > 0.001 { gain / peak } else { gain };
@@ -121,7 +122,6 @@ fn render_vertical(data: &[f32], area: Rect, buf: &mut Buffer, color: Color, gai
let fine_width = width * 2;
let fine_height = height * 4;
// Auto-scale: find peak amplitude and normalize to fill width
let peak = data.iter().map(|s| s.abs()).fold(0.0f32, f32::max);
let auto_gain = if peak > 0.001 { gain / peak } else { gain };