2022-03-18 11:28:18 +11:00
|
|
|
use atomic_float::AtomicF32;
|
2022-03-22 08:28:54 +11:00
|
|
|
use nih_plug::prelude::{util, Editor};
|
2022-06-18 09:59:53 +10:00
|
|
|
use nih_plug_vizia::vizia::prelude::*;
|
2022-03-19 11:17:36 +11:00
|
|
|
use nih_plug_vizia::widgets::*;
|
2022-11-06 23:26:32 +11:00
|
|
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
|
2022-03-22 08:28:54 +11:00
|
|
|
use std::sync::atomic::Ordering;
|
2022-03-18 11:28:18 +11:00
|
|
|
use std::sync::Arc;
|
2022-03-22 08:28:54 +11:00
|
|
|
use std::time::Duration;
|
2022-03-18 11:28:18 +11:00
|
|
|
|
|
|
|
use crate::GainParams;
|
|
|
|
|
2022-03-19 11:17:36 +11:00
|
|
|
#[derive(Lens)]
|
2022-03-24 09:29:49 +11:00
|
|
|
struct Data {
|
2022-04-07 23:31:46 +10:00
|
|
|
params: Arc<GainParams>,
|
2022-03-19 11:17:36 +11:00
|
|
|
peak_meter: Arc<AtomicF32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Model for Data {}
|
|
|
|
|
2022-03-18 11:28:18 +11:00
|
|
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
|
|
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
2022-03-22 09:45:55 +11:00
|
|
|
ViziaState::from_size(200, 150)
|
2022-03-18 11:28:18 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn create(
|
2022-04-07 23:31:46 +10:00
|
|
|
params: Arc<GainParams>,
|
2022-03-18 11:28:18 +11:00
|
|
|
peak_meter: Arc<AtomicF32>,
|
|
|
|
editor_state: Arc<ViziaState>,
|
|
|
|
) -> Option<Box<dyn Editor>> {
|
2022-11-06 23:26:32 +11:00
|
|
|
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
2022-11-06 23:48:12 +11:00
|
|
|
assets::register_noto_sans_light(cx);
|
|
|
|
assets::register_noto_sans_thin(cx);
|
|
|
|
|
2022-03-19 11:17:36 +11:00
|
|
|
Data {
|
|
|
|
params: params.clone(),
|
|
|
|
peak_meter: peak_meter.clone(),
|
|
|
|
}
|
|
|
|
.build(cx);
|
2022-03-18 11:28:18 +11:00
|
|
|
|
2022-03-29 09:49:31 +11:00
|
|
|
ResizeHandle::new(cx);
|
|
|
|
|
2022-03-20 11:23:44 +11:00
|
|
|
VStack::new(cx, |cx| {
|
2022-03-18 11:28:18 +11:00
|
|
|
Label::new(cx, "Gain GUI")
|
2023-01-13 04:49:55 +11:00
|
|
|
.font_family(vec![FamilyOwned::Name(String::from(
|
|
|
|
assets::NOTO_SANS_THIN,
|
|
|
|
))])
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(30.0)
|
2022-03-18 11:28:18 +11:00
|
|
|
.height(Pixels(50.0))
|
|
|
|
.child_top(Stretch(1.0))
|
|
|
|
.child_bottom(Pixels(0.0));
|
2022-03-22 08:28:54 +11:00
|
|
|
|
2022-03-19 11:22:38 +11:00
|
|
|
// NOTE: VIZIA adds 1 pixel of additional height to these labels, so we'll need to
|
|
|
|
// compensate for that
|
2022-03-19 11:17:36 +11:00
|
|
|
Label::new(cx, "Gain").bottom(Pixels(-1.0));
|
2022-03-22 09:46:39 +11:00
|
|
|
ParamSlider::new(cx, Data::params, |params| ¶ms.gain);
|
2022-03-19 11:17:36 +11:00
|
|
|
|
2022-03-22 08:28:54 +11:00
|
|
|
PeakMeter::new(
|
|
|
|
cx,
|
|
|
|
Data::peak_meter
|
|
|
|
.map(|peak_meter| util::gain_to_db(peak_meter.load(Ordering::Relaxed))),
|
|
|
|
Some(Duration::from_millis(600)),
|
|
|
|
)
|
|
|
|
// This is how adding padding works in vizia
|
|
|
|
.top(Pixels(10.0));
|
2022-03-18 11:28:18 +11:00
|
|
|
})
|
2022-03-19 11:17:36 +11:00
|
|
|
.row_between(Pixels(0.0))
|
2022-03-18 11:28:18 +11:00
|
|
|
.child_left(Stretch(1.0))
|
|
|
|
.child_right(Stretch(1.0));
|
|
|
|
})
|
|
|
|
}
|