2022-07-14 06:27:56 +10:00
|
|
|
// Spectral Compressor: an FFT based compressor
|
2023-01-02 04:52:44 +11:00
|
|
|
// Copyright (C) 2021-2022-2023 Robbert van der Helm
|
2022-07-14 06:27:56 +10:00
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
use nih_plug::prelude::Editor;
|
|
|
|
use nih_plug_vizia::vizia::prelude::*;
|
|
|
|
use nih_plug_vizia::widgets::*;
|
2022-11-06 23:26:32 +11:00
|
|
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
|
2022-07-14 06:27:56 +10:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use crate::SpectralCompressorParams;
|
|
|
|
|
|
|
|
#[derive(Lens)]
|
|
|
|
struct Data {
|
|
|
|
params: Arc<SpectralCompressorParams>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Model for Data {}
|
|
|
|
|
|
|
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
|
|
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
2022-07-24 03:09:37 +10:00
|
|
|
ViziaState::from_size(680, 535)
|
2022-07-14 06:27:56 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn create(
|
|
|
|
params: Arc<SpectralCompressorParams>,
|
|
|
|
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-07-14 06:27:56 +10:00
|
|
|
Data {
|
|
|
|
params: params.clone(),
|
|
|
|
}
|
|
|
|
.build(cx);
|
|
|
|
|
|
|
|
ResizeHandle::new(cx);
|
|
|
|
|
2022-07-24 03:09:37 +10:00
|
|
|
// There's no real 'grid' layout, the 4x4 grid should have even column widths and row
|
|
|
|
// heights
|
|
|
|
const LEFT_COLUMN_WIDTH: Units = Pixels(330.0);
|
|
|
|
const RIGHT_COLUMN_WIDTH: Units = Pixels(330.0);
|
|
|
|
|
2022-07-14 06:27:56 +10:00
|
|
|
VStack::new(cx, |cx| {
|
|
|
|
Label::new(cx, "Spectral Compressor")
|
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(30.0)
|
2022-07-14 06:27:56 +10:00
|
|
|
.height(Pixels(50.0))
|
|
|
|
.child_top(Stretch(1.0))
|
|
|
|
.child_bottom(Pixels(0.0))
|
2022-07-24 03:09:37 +10:00
|
|
|
.right(Pixels(15.0))
|
|
|
|
.bottom(Pixels(-5.0));
|
|
|
|
|
|
|
|
HStack::new(cx, |cx| {
|
|
|
|
VStack::new(cx, |cx| {
|
|
|
|
Label::new(cx, "Globals")
|
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(23.0)
|
2022-07-24 03:09:37 +10:00
|
|
|
.left(Stretch(1.0))
|
|
|
|
.right(Pixels(10.0))
|
|
|
|
.bottom(Pixels(-10.0));
|
|
|
|
|
|
|
|
GenericUi::new(cx, Data::params.map(|p| p.global.clone()));
|
|
|
|
})
|
|
|
|
.width(LEFT_COLUMN_WIDTH)
|
|
|
|
.height(Auto);
|
|
|
|
|
|
|
|
VStack::new(cx, |cx| {
|
|
|
|
Label::new(cx, "Threshold")
|
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(23.0)
|
2022-07-24 03:09:37 +10:00
|
|
|
.left(Stretch(1.0))
|
|
|
|
.right(Pixels(10.0))
|
|
|
|
.bottom(Pixels(-10.0));
|
|
|
|
|
|
|
|
GenericUi::new(cx, Data::params.map(|p| p.threshold.clone()));
|
2022-07-25 01:13:09 +10:00
|
|
|
|
|
|
|
Label::new(
|
|
|
|
cx,
|
|
|
|
"Parameter ranges and overal gain staging are still subject to change. If \
|
|
|
|
you use this in a project, make sure to bounce things to audio just in \
|
|
|
|
case they'll sound different later.",
|
|
|
|
)
|
2022-11-18 04:17:18 +11:00
|
|
|
.font_size(11.0)
|
2022-07-25 01:13:09 +10:00
|
|
|
.left(Pixels(15.0))
|
|
|
|
.right(Pixels(5.0))
|
2023-01-08 10:03:38 +11:00
|
|
|
// The column isn't tall enough without this, for some reason
|
|
|
|
.bottom(Pixels(20.0))
|
2022-07-25 01:13:09 +10:00
|
|
|
.width(Stretch(1.0));
|
2022-07-24 03:09:37 +10:00
|
|
|
})
|
|
|
|
.width(RIGHT_COLUMN_WIDTH)
|
|
|
|
.height(Auto);
|
|
|
|
})
|
|
|
|
.height(Auto)
|
|
|
|
.width(Stretch(1.0));
|
2022-07-14 06:27:56 +10:00
|
|
|
|
2022-07-24 03:09:37 +10:00
|
|
|
HStack::new(cx, |cx| {
|
|
|
|
VStack::new(cx, |cx| {
|
2022-07-25 01:17:10 +10:00
|
|
|
Label::new(cx, "Upwards")
|
2022-07-24 03:09:37 +10:00
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(23.0)
|
2022-07-24 03:09:37 +10:00
|
|
|
.left(Stretch(1.0))
|
|
|
|
.right(Pixels(10.0))
|
|
|
|
.bottom(Pixels(-10.0));
|
|
|
|
|
2022-07-25 01:17:10 +10:00
|
|
|
// We don't want to show the 'Upwards' prefix here, but it should still be in
|
2022-07-24 03:09:37 +10:00
|
|
|
// the parameter name so the parameter list makes sense
|
2022-07-25 01:17:10 +10:00
|
|
|
let upwards_compressor_params =
|
|
|
|
Data::params.map(|p| p.compressors.upwards.clone());
|
2022-07-24 03:09:37 +10:00
|
|
|
GenericUi::new_custom(
|
|
|
|
cx,
|
2022-07-25 01:17:10 +10:00
|
|
|
upwards_compressor_params.clone(),
|
2022-07-24 03:09:37 +10:00
|
|
|
move |cx, param_ptr| {
|
2022-07-25 01:17:10 +10:00
|
|
|
let upwards_compressor_params = upwards_compressor_params.clone();
|
2022-07-24 03:09:37 +10:00
|
|
|
HStack::new(cx, move |cx| {
|
|
|
|
Label::new(
|
|
|
|
cx,
|
|
|
|
unsafe { param_ptr.name() }
|
2022-07-25 01:17:10 +10:00
|
|
|
.strip_prefix("Upwards ")
|
2022-07-24 03:09:37 +10:00
|
|
|
.expect("Expected parameter name prefix, this is a bug"),
|
|
|
|
)
|
|
|
|
.class("label");
|
|
|
|
|
2022-07-25 01:17:10 +10:00
|
|
|
GenericUi::draw_widget(cx, upwards_compressor_params, param_ptr);
|
2022-07-24 03:09:37 +10:00
|
|
|
})
|
|
|
|
.class("row");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
2022-07-25 01:17:10 +10:00
|
|
|
.width(RIGHT_COLUMN_WIDTH)
|
2022-07-24 03:09:37 +10:00
|
|
|
.height(Auto);
|
|
|
|
|
|
|
|
VStack::new(cx, |cx| {
|
2022-07-25 01:17:10 +10:00
|
|
|
Label::new(cx, "Downwards")
|
2022-07-24 03:09:37 +10:00
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-11-12 02:21:19 +11:00
|
|
|
.font_size(23.0)
|
2022-07-24 03:09:37 +10:00
|
|
|
.left(Stretch(1.0))
|
|
|
|
.right(Pixels(10.0))
|
|
|
|
.bottom(Pixels(-10.0));
|
|
|
|
|
2022-07-25 01:17:10 +10:00
|
|
|
let downwards_compressor_params =
|
|
|
|
Data::params.map(|p| p.compressors.downwards.clone());
|
2022-07-24 03:09:37 +10:00
|
|
|
GenericUi::new_custom(
|
|
|
|
cx,
|
2022-07-25 01:17:10 +10:00
|
|
|
downwards_compressor_params.clone(),
|
2022-07-24 03:09:37 +10:00
|
|
|
move |cx, param_ptr| {
|
2022-07-25 01:17:10 +10:00
|
|
|
let downwards_compressor_params = downwards_compressor_params.clone();
|
2022-07-24 03:09:37 +10:00
|
|
|
HStack::new(cx, move |cx| {
|
|
|
|
Label::new(
|
|
|
|
cx,
|
|
|
|
unsafe { param_ptr.name() }
|
2022-07-25 01:17:10 +10:00
|
|
|
.strip_prefix("Downwards ")
|
2022-07-24 03:09:37 +10:00
|
|
|
.expect("Expected parameter name prefix, this is a bug"),
|
|
|
|
)
|
|
|
|
.class("label");
|
|
|
|
|
2022-07-25 01:17:10 +10:00
|
|
|
GenericUi::draw_widget(cx, downwards_compressor_params, param_ptr);
|
2022-07-24 03:09:37 +10:00
|
|
|
})
|
|
|
|
.class("row");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
2022-07-25 01:17:10 +10:00
|
|
|
.width(LEFT_COLUMN_WIDTH)
|
2022-07-24 03:09:37 +10:00
|
|
|
.height(Auto);
|
2022-07-21 04:27:25 +10:00
|
|
|
})
|
2022-07-24 03:09:37 +10:00
|
|
|
.height(Auto)
|
|
|
|
.width(Stretch(1.0));
|
2022-07-14 06:27:56 +10:00
|
|
|
})
|
2022-07-24 03:09:37 +10:00
|
|
|
.row_between(Pixels(10.0))
|
2022-07-14 06:27:56 +10:00
|
|
|
.child_left(Stretch(1.0))
|
|
|
|
.child_right(Stretch(1.0));
|
|
|
|
})
|
|
|
|
}
|
2022-07-24 03:09:37 +10:00
|
|
|
|
|
|
|
// /// A [`ParamSlider`] row very similar to what [`GenericUi`] would produce.
|
|
|
|
// fn param_row(cx: &mut Context) {
|
|
|
|
// VStack::new(cx, content)
|
|
|
|
// }
|