1
0
Fork 0

Use the new iced generic UI for Diopser

This handles a bit nicer than the egui UI.
This commit is contained in:
Robbert van der Helm 2022-03-16 01:20:02 +01:00
parent 24851bdc39
commit 1ddc305be5
5 changed files with 81 additions and 17 deletions

2
Cargo.lock generated
View file

@ -747,7 +747,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"fftw", "fftw",
"nih_plug", "nih_plug",
"nih_plug_egui", "nih_plug_iced",
"triple_buffer", "triple_buffer",
] ]

View file

@ -2,7 +2,7 @@
//! list of sliders and labels. //! list of sliders and labels.
use atomic_refcell::AtomicRefCell; use atomic_refcell::AtomicRefCell;
use iced_baseview::{Column, Row}; use iced_baseview::Row;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::collections::HashMap; use std::collections::HashMap;
use std::marker::PhantomData; use std::marker::PhantomData;

View file

@ -16,7 +16,7 @@ simd = ["nih_plug/simd"]
[dependencies] [dependencies]
nih_plug = { path = "../../", features = ["assert_process_allocs"] } nih_plug = { path = "../../", features = ["assert_process_allocs"] }
nih_plug_egui = { path = "../../nih_plug_egui" } nih_plug_iced = { path = "../../nih_plug_iced" }
# For the GUI # For the GUI
fftw = "0.7" fftw = "0.7"

View file

@ -14,26 +14,90 @@
// 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 nih_plug::prelude::Editor; use nih_plug::prelude::{Editor, GuiContext};
use nih_plug_egui::widgets::generic_ui; use nih_plug_iced::widgets as nih_widgets;
use nih_plug_egui::{create_egui_editor, egui, EguiState}; use nih_plug_iced::widgets::generic_ui::GenericUi;
use nih_plug_iced::*;
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use crate::DiopserParams; use crate::DiopserParams;
// 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 fn default_state() -> Arc<EguiState> { pub(crate) fn default_state() -> Arc<IcedState> {
EguiState::from_size(220, 330) IcedState::from_size(360, 300)
} }
pub fn create( pub(crate) fn create(
params: Pin<Arc<DiopserParams>>, params: Pin<Arc<DiopserParams>>,
editor_state: Arc<EguiState>, editor_state: Arc<IcedState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_egui_editor(editor_state, (), move |egui_ctx, setter, _state| { create_iced_editor::<DiopserEditor>(editor_state, params)
egui::CentralPanel::default().show(egui_ctx, |ui| { }
generic_ui::create(ui, params.as_ref(), setter, generic_ui::GenericSlider);
}); struct DiopserEditor {
}) params: Pin<Arc<DiopserParams>>,
context: Arc<dyn GuiContext>,
generic_ui_state: nih_widgets::generic_ui::State<nih_widgets::generic_ui::GenericSlider>,
}
#[derive(Debug, Clone, Copy)]
enum Message {
/// Update a parameter's value.
ParamUpdate(nih_widgets::ParamMessage),
}
impl IcedEditor for DiopserEditor {
type Executor = executor::Default;
type Message = Message;
type InitializationFlags = Pin<Arc<DiopserParams>>;
fn new(
params: Self::InitializationFlags,
context: Arc<dyn GuiContext>,
) -> (Self, Command<Self::Message>) {
let editor = DiopserEditor {
params,
context,
generic_ui_state: Default::default(),
};
(editor, Command::none())
}
fn context(&self) -> &dyn GuiContext {
self.context.as_ref()
}
fn update(
&mut self,
_window: &mut WindowQueue,
message: Self::Message,
) -> Command<Self::Message> {
match message {
Message::ParamUpdate(message) => self.handle_param_message(message),
}
Command::none()
}
fn view(&mut self) -> Element<'_, Self::Message> {
GenericUi::new(
&mut self.generic_ui_state,
self.params.as_ref(),
self.context.as_ref(),
)
.map(Message::ParamUpdate)
}
fn background_color(&self) -> nih_plug_iced::Color {
nih_plug_iced::Color {
r: 0.98,
g: 0.98,
b: 0.98,
a: 1.0,
}
}
} }

View file

@ -23,7 +23,7 @@ compile_error!("Compiling without SIMD support is currently not supported");
extern crate nih_plug; extern crate nih_plug;
use nih_plug::prelude::*; use nih_plug::prelude::*;
use nih_plug_egui::EguiState; use nih_plug_iced::IcedState;
use std::pin::Pin; use std::pin::Pin;
use std::simd::f32x2; use std::simd::f32x2;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -50,7 +50,7 @@ const MAX_AUTOMATION_STEP_SIZE: u32 = 512;
// - A proper GUI // - A proper GUI
struct Diopser { struct Diopser {
params: Pin<Arc<DiopserParams>>, params: Pin<Arc<DiopserParams>>,
editor_state: Arc<EguiState>, editor_state: Arc<IcedState>,
/// Needed for computing the filter coefficients. /// Needed for computing the filter coefficients.
sample_rate: f32, sample_rate: f32,