diff --git a/Cargo.lock b/Cargo.lock index 0c04cab4..3012a9be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,6 +281,7 @@ name = "crisp" version = "0.1.0" dependencies = [ "nih_plug", + "nih_plug_egui", ] [[package]] diff --git a/plugins/crisp/Cargo.toml b/plugins/crisp/Cargo.toml index ce1ae451..0d61fccd 100644 --- a/plugins/crisp/Cargo.toml +++ b/plugins/crisp/Cargo.toml @@ -10,3 +10,4 @@ crate-type = ["cdylib"] [dependencies] nih_plug = { path = "../../", features = ["assert_process_allocs"] } +nih_plug_egui = { path = "../../nih_plug_egui" } diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs new file mode 100644 index 00000000..b7dc029b --- /dev/null +++ b/plugins/crisp/src/editor.rs @@ -0,0 +1,39 @@ +// Crisp: a distortion plugin but not quite +// Copyright (C) 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 . + +use nih_plug::prelude::Editor; +use nih_plug_egui::widgets::generic_ui; +use nih_plug_egui::{create_egui_editor, egui, EguiState}; +use std::pin::Pin; +use std::sync::Arc; + +use crate::CrispParams; + +// Makes sense to also define this here, makes it a bit easier to keep track of +pub fn default_state() -> Arc { + EguiState::from_size(220, 330) +} + +pub fn create( + params: Pin>, + editor_state: Arc, +) -> Option> { + create_egui_editor(editor_state, (), move |egui_ctx, setter, _state| { + egui::CentralPanel::default().show(egui_ctx, |ui| { + generic_ui::create(ui, params.as_ref(), setter, generic_ui::GenericSlider); + }); + }) +} diff --git a/plugins/crisp/src/lib.rs b/plugins/crisp/src/lib.rs index d9f1433c..804a02bc 100644 --- a/plugins/crisp/src/lib.rs +++ b/plugins/crisp/src/lib.rs @@ -18,10 +18,12 @@ extern crate nih_plug; use nih_plug::prelude::*; +use nih_plug_egui::EguiState; use pcg::Pcg32iState; use std::pin::Pin; use std::sync::Arc; +mod editor; mod filter; mod pcg; @@ -38,7 +40,8 @@ const AMOUNT_GAIN_MULTIPLIER: f32 = 2.0; /// white (or filtered) noise. That other copy of the sound may have a low-pass filter applied to it /// since this effect just turns into literal noise at high frequencies. struct Crisp { - params: Pin>, + params: Pin>, + editor_state: Arc, /// Needed for computing the filter coefficients. sample_rate: f32, @@ -111,7 +114,8 @@ enum StereoMode { impl Default for Crisp { fn default() -> Self { Self { - params: Box::pin(CrispParams::default()), + params: Arc::pin(CrispParams::default()), + editor_state: editor::default_state(), sample_rate: 1.0, @@ -247,6 +251,10 @@ impl Plugin for Crisp { self.params.as_ref() } + fn editor(&self) -> Option> { + editor::create(self.params.clone(), self.editor_state.clone()) + } + fn accepts_bus_config(&self, config: &BusConfig) -> bool { // We'll add a SIMD version in a bit which only supports stereo config.num_input_channels == config.num_output_channels diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index db52cd0a..e51500a6 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use crate::DiopserParams; -// Makes sense to also definei 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 fn default_state() -> Arc { EguiState::from_size(220, 330) }