Skip to content

Commit

Permalink
wip visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Apr 24, 2024
1 parent 202898f commit 63de431
Showing 1 changed file with 70 additions and 50 deletions.
120 changes: 70 additions & 50 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::ZoomMode;
use nih_plug::prelude::Editor;
use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::vizia::vg;
use nih_plug_vizia::vizia::style::Visibility;
use nih_plug_vizia::widgets::*;
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
use std::sync::{Arc, Mutex};
Expand All @@ -24,6 +25,8 @@ struct LambData {
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
show_left: Arc<Mutex<Visibility>>,
show_right: Arc<Mutex<Visibility>>,
}

impl LambData {
Expand All @@ -33,13 +36,17 @@ impl LambData {
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
show_left: Arc<Mutex<Visibility>>,
show_right: Arc<Mutex<Visibility>>,
) -> Self {
Self {
params,
level_buffer_l,
level_buffer_r,
gr_buffer_l,
gr_buffer_r,
show_left,
show_right,
}
}
}
Expand All @@ -59,6 +66,8 @@ pub(crate) fn create(
level_buffer_r: Arc<Mutex<PeakBuffer>>,
gr_buffer_l: Arc<Mutex<MinimaBuffer>>,
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
show_left: Arc<Mutex<Visibility>>,
show_right: Arc<Mutex<Visibility>>,
editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
Expand All @@ -75,6 +84,8 @@ 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(),
show_left: show_left.clone(),
show_right: show_right.clone(),
}
.build(cx);

Expand Down Expand Up @@ -225,13 +236,13 @@ pub(crate) fn create(
.col_between(Percentage(2.5))
.height(Auto)
.width(Percentage(100.0));
peak_graph(cx, params.show_left.value(), params.show_right.value());
peak_graph(cx);
}) // everything
.width(Percentage(95.0))
.height(Auto)
.left(Percentage(2.5))
.right(Percentage(2.5))
.class("center");
.width(Percentage(95.0))
.height(Auto)
.left(Percentage(2.5))
.right(Percentage(2.5))
.class("center");
ResizeHandle::new(cx);
})
}
Expand Down Expand Up @@ -398,7 +409,17 @@ impl<AttackReleaseDataL: Lens<Target = Arc<LambParams>>> View
}

/// Draws a peak graph with a grid backdrop, unit ruler, and a peak meter to side.
fn peak_graph(cx: &mut Context, show_left: bool, show_right: bool) {
fn peak_graph(cx: &mut Context) {
// let visibility_arc_left = LambData::show_left;
// let visibility_left = {
// let lock = visibility_arc_left.lock().unwrap(); // Lock the mutex
// *lock // Dereference the lock to get the Visibility value
// };
// let visibility_left = *LambData::show_left.lock().unwrap();
// let visibility_left = {
// let lock = lamb_data.show_left.lock().unwrap(); // Lock the mutex
// *lock // Dereference the lock to get the Visibility value
// };
HStack::new(cx, |cx| {
ZStack::new(cx, |cx| {
Grid::new(
Expand All @@ -408,53 +429,52 @@ fn peak_graph(cx: &mut Context, show_left: bool, show_right: bool) {
vec![0.0, -6.0, -12.0, -18.0, -24.0],
Orientation::Horizontal,
)
.color(Color::rgba(160, 160, 160, 60));
.color(Color::rgba(160, 160, 160, 60));

if show_left {
println!("left");
// level
Graph::new(
cx,
LambData::level_buffer_l,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.color(Color::rgba(0, 0, 255, 30))
.background_color(Color::rgba(0, 0, 0, 40));
// level
Graph::new(
cx,
LambData::level_buffer_l,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.visibility(LambData::show_left)
.color(Color::rgba(0, 0, 255, 30))
.background_color(Color::rgba(0, 0, 0, 40));

// gain reduction
Graph::new(
cx,
LambData::gr_buffer_l,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.color(Color::rgba(0, 0, 255, 255))
.background_color(Color::rgba(250, 250, 250, 40))
.fill_from(0.0);
};
if show_right {
println!("right");
// level
Graph::new(
cx,
LambData::level_buffer_r,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
// level
Graph::new(
cx,
LambData::level_buffer_r,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.visibility(LambData::show_right)
.color(Color::rgba(255, 0, 0, 30))
.background_color(Color::rgba(0, 0, 0, 40));
// gain reduction
Graph::new(
cx,
LambData::gr_buffer_r,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.color(Color::rgba(255, 0, 0, 255))
.background_color(Color::rgba(250, 250, 250, 40))
.fill_from(0.0);
};
// gain reduction
Graph::new(
cx,
LambData::gr_buffer_l,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.visibility(LambData::show_left)
.color(Color::rgba(0, 0, 255, 255))
.background_color(Color::rgba(250, 250, 250, 40))
.fill_from(0.0);
// gain reduction
Graph::new(
cx,
LambData::gr_buffer_r,
(METER_MIN, METER_MAX),
ValueScaling::Decibels,
)
.visibility(LambData::show_right)
.color(Color::rgba(255, 0, 0, 255))
.background_color(Color::rgba(250, 250, 250, 40))
.fill_from(0.0);
// };
});

ZStack::new(cx, |cx| {
Expand Down

0 comments on commit 63de431

Please sign in to comment.