Skip to content

Commit

Permalink
Add histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Jun 1, 2024
1 parent 5544051 commit 950893f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -24,6 +24,7 @@ struct LambData {
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
histogram_buffer: Arc<Mutex<HistogramBuffer>>,
show_left: bool,
show_right: bool,
}
Expand Down Expand Up @@ -55,6 +56,7 @@ pub(crate) fn create(
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
histogram_buffer: Arc<Mutex<HistogramBuffer>>,
editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
Expand All @@ -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| {
Expand Down
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -84,6 +84,7 @@ pub struct Lamb {
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
histogram_buffer: Arc<Mutex<HistogramBuffer>>,

/// If this is set at the start of the processing cycle, then the graph duration should be updated.
should_update_time_scale: Arc<AtomicBool>,
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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.
Expand All @@ -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(),
)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 950893f

Please sign in to comment.