diff --git a/examples/visualizers/src/editor.rs b/examples/visualizers/src/editor.rs index 2d7fb27..8ba688a 100644 --- a/examples/visualizers/src/editor.rs +++ b/examples/visualizers/src/editor.rs @@ -1,6 +1,6 @@ use cyma::prelude::*; use cyma::{ - utils::{PeakBuffer, RingBuffer, SpectrumOutput, WaveformBuffer}, + utils::{HistogramBuffer, PeakBuffer, RingBuffer, SpectrumOutput, WaveformBuffer}, visualizers::{ Graph, Grid, Lissajous, LissajousGrid, Meter, Oscilloscope, SpectrumAnalyzer, SpectrumAnalyzerModifiers, SpectrumAnalyzerVariant, UnitRuler, Waveform, @@ -14,6 +14,7 @@ use std::sync::{Arc, Mutex}; pub(crate) struct Data { pub(crate) oscilloscope_buffer: Arc>, pub(crate) peak_buffer: Arc>, + pub(crate) histogram_buffer: Arc>, pub(crate) lissajous_buffer: Arc>>, pub(crate) spectrum: Arc>, @@ -24,6 +25,7 @@ impl Data { pub(crate) fn new( oscilloscope_buffer: Arc>, peak_buffer: Arc>, + histogram_buffer: Arc>, lissajous_buffer: Arc>>, spectrum: Arc>, waveform: Arc>>, @@ -31,6 +33,7 @@ impl Data { Self { oscilloscope_buffer, peak_buffer, + histogram_buffer, lissajous_buffer, spectrum, waveform, @@ -190,6 +193,11 @@ fn peak_graph(cx: &mut Context) { Graph::new(cx, Data::peak_buffer, (-32.0, 8.0), ValueScaling::Decibels) .color(Color::rgba(255, 255, 255, 160)) .background_color(Color::rgba(255, 255, 255, 60)); + + Histogram::new(cx, Data::histogram_buffer, (-32.0, 8.0)) + .color(Color::rgba(120, 120, 255, 160)) + .background_color(Color::rgba(120, 120, 255, 100)) + .width(Pixels(120.)); }) .background_color(Color::rgb(16, 16, 16)); diff --git a/examples/visualizers/src/lib.rs b/examples/visualizers/src/lib.rs index 1e1f2af..fd08d97 100644 --- a/examples/visualizers/src/lib.rs +++ b/examples/visualizers/src/lib.rs @@ -1,5 +1,7 @@ use cyma::prelude::*; -use cyma::utils::{PeakBuffer, RingBuffer, SpectrumInput, SpectrumOutput, WaveformBuffer}; +use cyma::utils::{ + HistogramBuffer, PeakBuffer, RingBuffer, SpectrumInput, SpectrumOutput, WaveformBuffer, +}; use nih_plug::prelude::*; use nih_plug_vizia::ViziaState; use std::{ @@ -16,6 +18,7 @@ pub struct VisualizersDemo { oscilloscope_buffer: Arc>, peak_buffer: Arc>, lissajous_buffer: Arc>>, + histogram_buffer: Arc>, spectrum_input: SpectrumInput, spectrum_output: Arc>, @@ -37,6 +40,7 @@ impl Default for VisualizersDemo { params: Arc::new(DemoParams::default()), oscilloscope_buffer: Arc::new(Mutex::new(WaveformBuffer::new(800, 5.0))), peak_buffer: Arc::new(Mutex::new(PeakBuffer::new(800, 10.0, 50.))), + histogram_buffer: Arc::new(Mutex::new(HistogramBuffer::new(512, 1.0))), lissajous_buffer: Arc::new(Mutex::new(RingBuffer::new(2048))), spectrum_input, @@ -45,7 +49,6 @@ impl Default for VisualizersDemo { // This is just some dummy data that doesn't change. waveform: Arc::new(Mutex::new( (0..256) - .into_iter() .map(|x| { let x = 2. * PI * x as f32 / 256.; 0.6 * (x).sin() + 0.3 * (x * 2.).sin() + 0.1 * (x * 4.).sin() @@ -98,6 +101,7 @@ impl Plugin for VisualizersDemo { editor::Data::new( self.oscilloscope_buffer.clone(), self.peak_buffer.clone(), + self.histogram_buffer.clone(), self.lissajous_buffer.clone(), self.spectrum_output.clone(), self.waveform.clone(), @@ -124,6 +128,12 @@ impl Plugin for VisualizersDemo { } Err(_) => return false, } + match self.histogram_buffer.lock() { + Ok(mut buffer) => { + buffer.set_sample_rate(buffer_config.sample_rate); + } + Err(_) => return false, + } self.spectrum_input .update_sample_rate(buffer_config.sample_rate); @@ -147,6 +157,10 @@ impl Plugin for VisualizersDemo { .lock() .unwrap() .enqueue_buffer(buffer, None); + self.histogram_buffer + .lock() + .unwrap() + .enqueue_buffer(buffer, None); if buffer.channels() > 1 { for mut sample in buffer.iter_samples() {