1
0
Fork 0

Add an editor mode enum for Spectral Compressor

To indicate that the GUI has been expanded.
This commit is contained in:
Robbert van der Helm 2023-02-26 17:50:49 +01:00
parent ce2eab84e1
commit c9793c6901
4 changed files with 147 additions and 109 deletions

2
Cargo.lock generated
View file

@ -3756,10 +3756,12 @@ dependencies = [
name = "spectral_compressor"
version = "0.3.0"
dependencies = [
"crossbeam",
"nih_plug",
"nih_plug_vizia",
"open",
"realfft",
"serde",
]
[[package]]

View file

@ -16,4 +16,6 @@ nih_plug_vizia = { path = "../../nih_plug_vizia" }
realfft = "3.0"
# For the GUI
crossbeam = "0.8"
open = "3.0"
serde = { version = "1.0", features = ["derive"] }

View file

@ -18,15 +18,36 @@ use nih_plug::prelude::*;
use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*;
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use crate::{SpectralCompressor, SpectralCompressorParams};
/// The entire GUI's width, in logical pixels.
const EXPANDED_GUI_WIDTH: u32 = 1360;
/// The width of the GUI's main part containing the controls.
const COLLAPSED_GUI_WIDTH: u32 = 680;
/// The entire GUI's height, in logical pixels.
const GUI_HEIGHT: u32 = 535;
// I couldn't get `LayoutType::Grid` to work as expected, so we'll fake a 4x4 grid with
// hardcoded column widths
const COLUMN_WIDTH: Units = Pixels(330.0);
const DARKER_GRAY: Color = Color::rgb(0x69, 0x69, 0x69);
/// The editor's mode. Essentially just a boolean to indicate whether the visualizer is shown or
/// not.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum EditorMode {
// These serialization names are hardcoded so the variants can be renamed them later without
// breaking preset compatibility
#[serde(rename = "collapsed")]
Collapsed,
#[default]
#[serde(rename = "visualizer-shown")]
Visualizer,
}
#[derive(Lens)]
struct Data {
params: Arc<SpectralCompressorParams>,
@ -36,7 +57,7 @@ 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> {
ViziaState::new(|| (680, 535))
ViziaState::new(|| (EXPANDED_GUI_WIDTH, GUI_HEIGHT))
}
pub(crate) fn create(
@ -54,6 +75,13 @@ pub(crate) fn create(
ResizeHandle::new(cx);
HStack::new(cx, |cx| {
main_column(cx);
});
})
}
fn main_column(cx: &mut Context) {
VStack::new(cx, |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "Spectral Compressor")
@ -76,7 +104,7 @@ pub(crate) fn create(
.left(Pixels(2.0));
})
.height(Pixels(30.0))
.right(Pixels(-17.0))
.right(Pixels(-22.0))
.bottom(Pixels(-5.0))
.top(Pixels(10.0));
@ -90,9 +118,9 @@ pub(crate) fn create(
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.",
"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.",
)
.font_size(11.0)
.left(Pixels(15.0))
@ -109,8 +137,7 @@ pub(crate) fn create(
make_column(cx, "Upwards", |cx| {
// We don't want to show the 'Upwards' prefix here, but it should still be in
// the parameter name so the parameter list makes sense
let upwards_compressor_params =
Data::params.map(|p| p.compressors.upwards.clone());
let upwards_compressor_params = Data::params.map(|p| p.compressors.upwards.clone());
GenericUi::new_custom(
cx,
upwards_compressor_params.clone(),
@ -159,10 +186,10 @@ pub(crate) fn create(
.height(Auto)
.width(Stretch(1.0));
})
.width(Pixels(COLLAPSED_GUI_WIDTH as f32))
.row_between(Pixels(15.0))
.child_left(Stretch(1.0))
.child_right(Stretch(1.0));
})
}
fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context)) {

View file

@ -14,6 +14,8 @@
// 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 crossbeam::atomic::AtomicCell;
use editor::EditorMode;
use nih_plug::prelude::*;
use nih_plug_vizia::ViziaState;
use realfft::num_complex::Complex32;
@ -82,6 +84,10 @@ pub struct SpectralCompressorParams {
/// restored.
#[persist = "editor-state"]
pub editor_state: Arc<ViziaState>,
/// The mode the editor is currently in. Essentially just a fancy boolean to indicate whether
/// it's expanded or not.
#[persist = "editor-mode"]
pub editor_mode: Arc<AtomicCell<EditorMode>>,
// NOTE: These `Arc`s are only here temporarily to work around Vizia's Lens requirements so we
// can use the generic UIs
@ -239,6 +245,7 @@ impl SpectralCompressorParams {
pub fn new(compressor_bank: &compressor_bank::CompressorBank) -> Self {
SpectralCompressorParams {
editor_state: editor::default_state(),
editor_mode: Arc::default(),
// TODO: Do still enable per-block smoothing for these settings, because why not. This
// will require updating the compressor bank.