Add an editor mode enum for Spectral Compressor
To indicate that the GUI has been expanded.
This commit is contained in:
parent
ce2eab84e1
commit
c9793c6901
4 changed files with 147 additions and 109 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3756,10 +3756,12 @@ dependencies = [
|
||||||
name = "spectral_compressor"
|
name = "spectral_compressor"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"crossbeam",
|
||||||
"nih_plug",
|
"nih_plug",
|
||||||
"nih_plug_vizia",
|
"nih_plug_vizia",
|
||||||
"open",
|
"open",
|
||||||
"realfft",
|
"realfft",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -16,4 +16,6 @@ nih_plug_vizia = { path = "../../nih_plug_vizia" }
|
||||||
realfft = "3.0"
|
realfft = "3.0"
|
||||||
|
|
||||||
# For the GUI
|
# For the GUI
|
||||||
|
crossbeam = "0.8"
|
||||||
open = "3.0"
|
open = "3.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
@ -18,15 +18,36 @@ use nih_plug::prelude::*;
|
||||||
use nih_plug_vizia::vizia::prelude::*;
|
use nih_plug_vizia::vizia::prelude::*;
|
||||||
use nih_plug_vizia::widgets::*;
|
use nih_plug_vizia::widgets::*;
|
||||||
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{SpectralCompressor, SpectralCompressorParams};
|
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
|
// I couldn't get `LayoutType::Grid` to work as expected, so we'll fake a 4x4 grid with
|
||||||
// hardcoded column widths
|
// hardcoded column widths
|
||||||
const COLUMN_WIDTH: Units = Pixels(330.0);
|
const COLUMN_WIDTH: Units = Pixels(330.0);
|
||||||
|
|
||||||
const DARKER_GRAY: Color = Color::rgb(0x69, 0x69, 0x69);
|
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)]
|
#[derive(Lens)]
|
||||||
struct Data {
|
struct Data {
|
||||||
params: Arc<SpectralCompressorParams>,
|
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
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
||||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
ViziaState::new(|| (680, 535))
|
ViziaState::new(|| (EXPANDED_GUI_WIDTH, GUI_HEIGHT))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(
|
pub(crate) fn create(
|
||||||
|
@ -54,6 +75,13 @@ pub(crate) fn create(
|
||||||
|
|
||||||
ResizeHandle::new(cx);
|
ResizeHandle::new(cx);
|
||||||
|
|
||||||
|
HStack::new(cx, |cx| {
|
||||||
|
main_column(cx);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main_column(cx: &mut Context) {
|
||||||
VStack::new(cx, |cx| {
|
VStack::new(cx, |cx| {
|
||||||
HStack::new(cx, |cx| {
|
HStack::new(cx, |cx| {
|
||||||
Label::new(cx, "Spectral Compressor")
|
Label::new(cx, "Spectral Compressor")
|
||||||
|
@ -76,7 +104,7 @@ pub(crate) fn create(
|
||||||
.left(Pixels(2.0));
|
.left(Pixels(2.0));
|
||||||
})
|
})
|
||||||
.height(Pixels(30.0))
|
.height(Pixels(30.0))
|
||||||
.right(Pixels(-17.0))
|
.right(Pixels(-22.0))
|
||||||
.bottom(Pixels(-5.0))
|
.bottom(Pixels(-5.0))
|
||||||
.top(Pixels(10.0));
|
.top(Pixels(10.0));
|
||||||
|
|
||||||
|
@ -90,9 +118,9 @@ pub(crate) fn create(
|
||||||
|
|
||||||
Label::new(
|
Label::new(
|
||||||
cx,
|
cx,
|
||||||
"Parameter ranges and overal gain staging are still subject to change. If \
|
"Parameter ranges and overal gain staging are still subject to change. If you \
|
||||||
you use this in a project, make sure to bounce things to audio just in \
|
use this in a project, make sure to bounce things to audio just in case \
|
||||||
case they'll sound different later.",
|
they'll sound different later.",
|
||||||
)
|
)
|
||||||
.font_size(11.0)
|
.font_size(11.0)
|
||||||
.left(Pixels(15.0))
|
.left(Pixels(15.0))
|
||||||
|
@ -109,8 +137,7 @@ pub(crate) fn create(
|
||||||
make_column(cx, "Upwards", |cx| {
|
make_column(cx, "Upwards", |cx| {
|
||||||
// We don't want to show the 'Upwards' prefix here, but it should still be in
|
// 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
|
// the parameter name so the parameter list makes sense
|
||||||
let upwards_compressor_params =
|
let upwards_compressor_params = Data::params.map(|p| p.compressors.upwards.clone());
|
||||||
Data::params.map(|p| p.compressors.upwards.clone());
|
|
||||||
GenericUi::new_custom(
|
GenericUi::new_custom(
|
||||||
cx,
|
cx,
|
||||||
upwards_compressor_params.clone(),
|
upwards_compressor_params.clone(),
|
||||||
|
@ -159,10 +186,10 @@ pub(crate) fn create(
|
||||||
.height(Auto)
|
.height(Auto)
|
||||||
.width(Stretch(1.0));
|
.width(Stretch(1.0));
|
||||||
})
|
})
|
||||||
|
.width(Pixels(COLLAPSED_GUI_WIDTH as f32))
|
||||||
.row_between(Pixels(15.0))
|
.row_between(Pixels(15.0))
|
||||||
.child_left(Stretch(1.0))
|
.child_left(Stretch(1.0))
|
||||||
.child_right(Stretch(1.0));
|
.child_right(Stretch(1.0));
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context)) {
|
fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context)) {
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// 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::prelude::*;
|
||||||
use nih_plug_vizia::ViziaState;
|
use nih_plug_vizia::ViziaState;
|
||||||
use realfft::num_complex::Complex32;
|
use realfft::num_complex::Complex32;
|
||||||
|
@ -82,6 +84,10 @@ pub struct SpectralCompressorParams {
|
||||||
/// restored.
|
/// restored.
|
||||||
#[persist = "editor-state"]
|
#[persist = "editor-state"]
|
||||||
pub editor_state: Arc<ViziaState>,
|
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
|
// NOTE: These `Arc`s are only here temporarily to work around Vizia's Lens requirements so we
|
||||||
// can use the generic UIs
|
// can use the generic UIs
|
||||||
|
@ -239,6 +245,7 @@ impl SpectralCompressorParams {
|
||||||
pub fn new(compressor_bank: &compressor_bank::CompressorBank) -> Self {
|
pub fn new(compressor_bank: &compressor_bank::CompressorBank) -> Self {
|
||||||
SpectralCompressorParams {
|
SpectralCompressorParams {
|
||||||
editor_state: editor::default_state(),
|
editor_state: editor::default_state(),
|
||||||
|
editor_mode: Arc::default(),
|
||||||
|
|
||||||
// TODO: Do still enable per-block smoothing for these settings, because why not. This
|
// TODO: Do still enable per-block smoothing for these settings, because why not. This
|
||||||
// will require updating the compressor bank.
|
// will require updating the compressor bank.
|
||||||
|
|
Loading…
Add table
Reference in a new issue