1
0
Fork 0

Add a generic UI for Crisp

This commit is contained in:
Robbert van der Helm 2022-03-09 15:15:09 +01:00
parent 57ca8a5ccb
commit 4105a887a8
5 changed files with 52 additions and 3 deletions

1
Cargo.lock generated
View file

@ -281,6 +281,7 @@ name = "crisp"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"nih_plug", "nih_plug",
"nih_plug_egui",
] ]
[[package]] [[package]]

View file

@ -10,3 +10,4 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
nih_plug = { path = "../../", features = ["assert_process_allocs"] } nih_plug = { path = "../../", features = ["assert_process_allocs"] }
nih_plug_egui = { path = "../../nih_plug_egui" }

View file

@ -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 <https://www.gnu.org/licenses/>.
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> {
EguiState::from_size(220, 330)
}
pub fn create(
params: Pin<Arc<CrispParams>>,
editor_state: Arc<EguiState>,
) -> Option<Box<dyn Editor>> {
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);
});
})
}

View file

@ -18,10 +18,12 @@
extern crate nih_plug; extern crate nih_plug;
use nih_plug::prelude::*; use nih_plug::prelude::*;
use nih_plug_egui::EguiState;
use pcg::Pcg32iState; use pcg::Pcg32iState;
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
mod editor;
mod filter; mod filter;
mod pcg; 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 /// 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. /// since this effect just turns into literal noise at high frequencies.
struct Crisp { struct Crisp {
params: Pin<Box<CrispParams>>, params: Pin<Arc<CrispParams>>,
editor_state: Arc<EguiState>,
/// Needed for computing the filter coefficients. /// Needed for computing the filter coefficients.
sample_rate: f32, sample_rate: f32,
@ -111,7 +114,8 @@ enum StereoMode {
impl Default for Crisp { impl Default for Crisp {
fn default() -> Self { fn default() -> Self {
Self { Self {
params: Box::pin(CrispParams::default()), params: Arc::pin(CrispParams::default()),
editor_state: editor::default_state(),
sample_rate: 1.0, sample_rate: 1.0,
@ -247,6 +251,10 @@ impl Plugin for Crisp {
self.params.as_ref() self.params.as_ref()
} }
fn editor(&self) -> Option<Box<dyn Editor>> {
editor::create(self.params.clone(), self.editor_state.clone())
}
fn accepts_bus_config(&self, config: &BusConfig) -> bool { fn accepts_bus_config(&self, config: &BusConfig) -> bool {
// We'll add a SIMD version in a bit which only supports stereo // We'll add a SIMD version in a bit which only supports stereo
config.num_input_channels == config.num_output_channels config.num_input_channels == config.num_output_channels

View file

@ -22,7 +22,7 @@ use std::sync::Arc;
use crate::DiopserParams; 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> { pub fn default_state() -> Arc<EguiState> {
EguiState::from_size(220, 330) EguiState::from_size(220, 330)
} }