diff --git a/crates/cli/src/cli_groovebox.rs b/crates/cli/src/cli_groovebox.rs index a90827f1..b001b633 100644 --- a/crates/cli/src/cli_groovebox.rs +++ b/crates/cli/src/cli_groovebox.rs @@ -33,18 +33,13 @@ impl GrooveboxCli { Tui::run(JackClient::new("tek_groovebox")?.activate_with(|jack|{ let app = tek::GrooveboxTui::try_from(jack)?; jack.read().unwrap().client().connect_ports(&app.player.midi_outs[0], &app.sampler.midi_in)?; - jack.connect_midi_from(&app.player.midi_ins[0], &self.midi_from)?; jack.connect_midi_from(&app.sampler.midi_in, &self.midi_from)?; - jack.connect_midi_to(&app.player.midi_outs[0], &self.midi_to)?; - jack.connect_audio_from(&app.sampler.audio_ins[0], &self.l_from)?; jack.connect_audio_from(&app.sampler.audio_ins[1], &self.r_from)?; - jack.connect_audio_to(&app.sampler.audio_outs[0], &self.l_to)?; jack.connect_audio_to(&app.sampler.audio_outs[1], &self.r_to)?; - Ok(app) })?)?; Ok(()) diff --git a/crates/tek/src/sampler/sample_viewer.rs b/crates/tek/src/sampler/sample_viewer.rs index 6f860746..0abd7ea9 100644 --- a/crates/tek/src/sampler/sample_viewer.rs +++ b/crates/tek/src/sampler/sample_viewer.rs @@ -1,6 +1,6 @@ use crate::*; use std::ops::Deref; -use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Points}}}; +use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Points, Line}}}; const EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)]; @@ -8,8 +8,8 @@ pub struct SampleViewer(pub Option>>); render!(|self: SampleViewer|render(|to|{ let [x, y, width, height] = to.area(); let area = Rect { x, y, width, height }; - let mut points = vec![]; - let (x_bounds, y_bounds, coords): ([f64;2], [f64;2], &[(f64,f64)]) = + let min_db = -40.0; + let (x_bounds, y_bounds, lines): ([f64;2], [f64;2], Vec) = if let Some(sample) = &self.0 { let sample = sample.read().unwrap(); let start = sample.start as f64; @@ -17,28 +17,36 @@ render!(|self: SampleViewer|render(|to|{ let length = end - start; let step = length / width as f64; let mut t = start; + let mut lines = vec![]; while t < end { let chunk = &sample.channels[0][t as usize..((t + step) as usize).min(sample.end)]; let total: f32 = chunk.iter().map(|x|x.abs()).sum(); let count = chunk.len() as f32; let meter = 10. * (total / count).log10(); - points.push((t as f64, meter as f64)); + let x = t as f64; + let y = meter as f64; + lines.push(Line::new(x, min_db, x, y, Color::Green)); t += step; } ( [sample.start as f64, sample.end as f64], - [-40., 0.], - points.as_slice() + [min_db, 0.], + lines ) } else { ( - [0.0, f64::from(width)], - [0.0, f64::from(height)], - EMPTY + [0.0, width as f64], + [0.0, height as f64], + vec![ + Line::new(0.0, 0.0, width as f64, height as f64, Color::Red), + Line::new(width as f64, 0.0, 0.0, height as f64, Color::Red), + ] ) }; Canvas::default().x_bounds(x_bounds).y_bounds(y_bounds).paint(|ctx|{ - ctx.draw(&Points { coords, color: Color::Rgb(255,0,0) }) + for line in lines.iter() { + ctx.draw(line) + } }).render(area, &mut to.buffer); Ok(()) }));