diff --git a/src/editor.rs b/src/editor.rs index f56602a..32935d8 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -9,8 +9,8 @@ use std::sync::{Arc, Mutex}; use cyma::{ prelude::*, - utils::{MinimaBuffer, PeakBuffer}, - visualizers::{Graph, Grid, Meter, UnitRuler}, + utils::{HistogramBuffer, MinimaBuffer, PeakBuffer}, + visualizers::{Graph, Grid, Histogram, Meter, UnitRuler}, }; // to allign the grid with the controls: @@ -24,6 +24,7 @@ struct LambData { level_buffer_r: Arc>, gr_buffer_l: Arc>, gr_buffer_r: Arc>, + histogram_buffer: Arc>, show_left: bool, show_right: bool, } @@ -55,6 +56,7 @@ pub(crate) fn create( level_buffer_r: Arc>, gr_buffer_l: Arc>, gr_buffer_r: Arc>, + histogram_buffer: Arc>, editor_state: Arc, ) -> Option> { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { @@ -71,6 +73,7 @@ pub(crate) fn create( level_buffer_r: level_buffer_r.clone(), gr_buffer_l: gr_buffer_l.clone(), gr_buffer_r: gr_buffer_r.clone(), + histogram_buffer: histogram_buffer.clone(), show_left: true, show_right: true, } @@ -439,6 +442,11 @@ fn peak_graph(cx: &mut Context) { .visibility(LambData::show_right) .color(Color::rgba(255, 0, 0, 30)) .background_color(Color::rgba(0, 0, 0, 40)); + // histogram, under the GR graph + Histogram::new(cx, LambData::histogram_buffer, (METER_MIN, METER_MAX)) + .color(Color::rgb(60, 60, 60)) + .background_color(Color::rgb(160, 160, 160)) + .width(Percentage(12.5)); // gain reduction Graph::new( cx, @@ -461,7 +469,6 @@ fn peak_graph(cx: &mut Context) { .color(Color::rgba(255, 0, 0, 255)) .background_color(Color::rgba(250, 250, 250, 50)) .fill_from_value(0.0); - // }; }); ZStack::new(cx, |cx| { diff --git a/src/lib.rs b/src/lib.rs index 81d936a..1ede951 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ mod dsp_192k; mod dsp_48k; mod dsp_96k; use buffer::*; -use cyma::utils::{MinimaBuffer, PeakBuffer, VisualizerBuffer}; +use cyma::utils::{MinimaBuffer, PeakBuffer, VisualizerBuffer, HistogramBuffer}; use default_boxed::DefaultBoxed; @@ -84,6 +84,7 @@ pub struct Lamb { level_buffer_r: Arc>, gr_buffer_l: Arc>, gr_buffer_r: Arc>, + histogram_buffer: Arc>, /// If this is set at the start of the processing cycle, then the graph duration should be updated. should_update_time_scale: Arc, @@ -107,6 +108,7 @@ impl Default for Lamb { level_buffer_r: Arc::new(Mutex::new(PeakBuffer::new(1171, 7.0, 0.0))), gr_buffer_l: Arc::new(Mutex::new(MinimaBuffer::new(1171, 7.0, 0.0))), gr_buffer_r: Arc::new(Mutex::new(MinimaBuffer::new(1171, 7.0, 0.0))), + histogram_buffer: Arc::new(Mutex::new(HistogramBuffer::new(256, 1.0))), should_update_time_scale, } } @@ -192,6 +194,13 @@ impl Plugin for Lamb { Err(_) => return false, } + match self.histogram_buffer.lock() { + Ok(mut buffer) => { + buffer.set_sample_rate(buffer_config.sample_rate); + } + Err(_) => return false, + } + // Resize buffers and perform other potentially expensive initialization operations here. // The `reset()` function is always called right after this function. You can remove this // function if you do not need it. @@ -213,6 +222,7 @@ impl Plugin for Lamb { self.level_buffer_r.clone(), self.gr_buffer_l.clone(), self.gr_buffer_r.clone(), + self.histogram_buffer.clone(), self.params.editor_state.clone(), ) } @@ -346,6 +356,10 @@ impl Plugin for Lamb { .unwrap() .enqueue(self.temp_output_buffer_gr_r[i] as f32); } + self.histogram_buffer + .lock() + .unwrap() + .enqueue_buffer(buffer, None); } ProcessStatus::Normal