2022-03-06 05:39:52 +11:00
|
|
|
// Diopser: a phase rotation plugin
|
|
|
|
// Copyright (C) 2021-2022 Robbert van der Helm
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
use nih_plug::prelude::Editor;
|
2022-06-18 09:59:53 +10:00
|
|
|
use nih_plug_vizia::vizia::prelude::*;
|
2022-03-23 04:32:02 +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-11-05 04:32:35 +11:00
|
|
|
use std::sync::atomic::AtomicBool;
|
2022-03-06 05:39:52 +11:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use crate::DiopserParams;
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
/// VIZIA uses points instead of pixels for text
|
|
|
|
const POINT_SCALE: f32 = 0.75;
|
2022-03-06 05:39:52 +11:00
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
#[derive(Lens)]
|
2022-03-24 09:29:49 +11:00
|
|
|
struct Data {
|
2022-04-07 23:31:46 +10:00
|
|
|
params: Arc<DiopserParams>,
|
2022-11-05 04:32:35 +11:00
|
|
|
|
|
|
|
/// Whether the safe mode button is enabled. The number of filter stages is capped at 40 while
|
|
|
|
/// this is active.
|
|
|
|
safe_mode: Arc<AtomicBool>,
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
impl Model for Data {}
|
2022-03-16 11:20:02 +11:00
|
|
|
|
2022-03-23 04:32:02 +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-11-04 08:27:47 +11:00
|
|
|
ViziaState::from_size(600, 490)
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
pub(crate) fn create(
|
2022-04-07 23:31:46 +10:00
|
|
|
params: Arc<DiopserParams>,
|
2022-03-23 04:32:02 +11:00
|
|
|
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-11-04 08:27:47 +11:00
|
|
|
cx.add_theme(include_str!("theme.css"));
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
Data {
|
|
|
|
params: params.clone(),
|
2022-11-05 04:32:35 +11:00
|
|
|
|
|
|
|
safe_mode: params.safe_mode.clone(),
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
2022-03-23 04:32:02 +11:00
|
|
|
.build(cx);
|
|
|
|
|
2022-03-29 09:49:31 +11:00
|
|
|
ResizeHandle::new(cx);
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
VStack::new(cx, |cx| {
|
2022-11-04 08:27:47 +11:00
|
|
|
top_bar(cx);
|
|
|
|
spectrum_analyzer(cx);
|
|
|
|
other_params(cx);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This contain's the plugin's name, a bypass button, and some other controls.
|
|
|
|
fn top_bar(cx: &mut Context) {
|
|
|
|
HStack::new(cx, |cx| {
|
|
|
|
Label::new(cx, "Diopser")
|
|
|
|
.font(assets::NOTO_SANS_THIN)
|
|
|
|
.font_size(50.0 * POINT_SCALE)
|
|
|
|
.top(Pixels(-2.0))
|
|
|
|
.left(Pixels(7.0));
|
|
|
|
|
|
|
|
HStack::new(cx, |cx| {
|
|
|
|
// TODO: Placeholders, replace with the actual elements
|
|
|
|
Element::new(cx)
|
|
|
|
.width(Pixels(210.0))
|
|
|
|
.height(Pixels(30.0))
|
|
|
|
.border_color(Color::rgb(0x0a, 0x0a, 0x0a))
|
|
|
|
.border_width(Pixels(1.0));
|
|
|
|
|
|
|
|
Element::new(cx)
|
|
|
|
.width(Pixels(110.0))
|
|
|
|
.height(Pixels(30.0))
|
|
|
|
.left(Pixels(10.0))
|
|
|
|
.background_color(Color::rgb(0xff, 0xf2, 0x80))
|
|
|
|
.border_color(Color::rgb(0x0a, 0x0a, 0x0a))
|
|
|
|
.border_width(Pixels(1.0));
|
|
|
|
|
2022-11-05 02:12:30 +11:00
|
|
|
ParamButton::new(cx, Data::params, |params| ¶ms.bypass)
|
|
|
|
.for_bypass()
|
|
|
|
.left(Pixels(10.0));
|
2022-03-23 04:32:02 +11:00
|
|
|
})
|
2022-11-04 08:27:47 +11:00
|
|
|
.child_space(Pixels(10.0))
|
|
|
|
.left(Stretch(1.0));
|
|
|
|
})
|
|
|
|
.id("top-bar");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This shows a spectrum analyzer for the plugin's output, and also acts as an X-Y pad for the
|
|
|
|
/// frequency and resonance parameters.
|
|
|
|
fn spectrum_analyzer(cx: &mut Context) {
|
|
|
|
Label::new(cx, "When I grow up, I want to be a spectrum analyzer!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The area below the spectrum analyzer that contains all of the other parameters.
|
|
|
|
fn other_params(cx: &mut Context) {
|
|
|
|
// Just to center the old generic UI for now
|
|
|
|
ZStack::new(cx, |cx| {
|
|
|
|
GenericUi::new(cx, Data::params).width(Auto).height(Auto);
|
2022-03-23 04:32:02 +11:00
|
|
|
})
|
2022-11-04 08:27:47 +11:00
|
|
|
.width(Percentage(100.0))
|
|
|
|
.height(Stretch(1.0))
|
|
|
|
.child_space(Stretch(1.0));
|
2022-03-06 05:39:52 +11:00
|
|
|
}
|