Add a generic UI for Crisp
This commit is contained in:
parent
57ca8a5ccb
commit
4105a887a8
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -281,6 +281,7 @@ name = "crisp"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"nih_plug",
|
||||
"nih_plug_egui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -10,3 +10,4 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
nih_plug = { path = "../../", features = ["assert_process_allocs"] }
|
||||
nih_plug_egui = { path = "../../nih_plug_egui" }
|
||||
|
|
39
plugins/crisp/src/editor.rs
Normal file
39
plugins/crisp/src/editor.rs
Normal 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);
|
||||
});
|
||||
})
|
||||
}
|
|
@ -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<Box<CrispParams>>,
|
||||
params: Pin<Arc<CrispParams>>,
|
||||
editor_state: Arc<EguiState>,
|
||||
|
||||
/// 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<Box<dyn Editor>> {
|
||||
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
|
||||
|
|
|
@ -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> {
|
||||
EguiState::from_size(220, 330)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue