1
0
Fork 0
nih-plug/plugins/diopser/src/editor.rs

81 lines
2.4 KiB
Rust
Raw Normal View History

2022-03-06 05:39:52 +11:00
// Diopser: a phase rotation plugin
// Copyright (C) 2021-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, GuiContext};
use nih_plug_iced::widgets::ParamMessage;
use nih_plug_iced::{create_iced_editor, Command, Element, IcedEditor, IcedState};
2022-03-06 05:39:52 +11:00
use std::pin::Pin;
use std::sync::Arc;
use crate::DiopserParams;
2022-03-10 01:15:09 +11:00
// Makes sense to also define this here, makes it a bit easier to keep track of
pub fn default_state() -> Arc<IcedState> {
IcedState::from_size(600, 400)
2022-03-06 05:39:52 +11:00
}
pub fn create(
params: Pin<Arc<DiopserParams>>,
editor_state: Arc<IcedState>,
2022-03-06 05:39:52 +11:00
) -> Option<Box<dyn Editor>> {
create_iced_editor::<DiopserEditor>(editor_state, params)
}
struct DiopserEditor {
params: Pin<Arc<DiopserParams>>,
context: Arc<dyn GuiContext>,
}
#[derive(Debug, Clone, Copy)]
enum EditorMessage {
ParamUpdate(ParamMessage),
}
impl IcedEditor for DiopserEditor {
type Executor = nih_plug_iced::executor::Default;
type Message = EditorMessage;
type InitializationFlags = Pin<Arc<DiopserParams>>;
fn new(
params: Self::InitializationFlags,
context: Arc<dyn GuiContext>,
) -> (Self, Command<Self::Message>) {
let editor = DiopserEditor { params, context };
(editor, Command::none())
}
fn context(&self) -> &dyn GuiContext {
self.context.as_ref()
}
fn update(
&mut self,
_window: &mut nih_plug_iced::WindowQueue,
message: Self::Message,
) -> Command<Self::Message> {
match message {
EditorMessage::ParamUpdate(message) => self.handle_param_message(message),
}
Command::none()
}
fn view(&mut self) -> Element<'_, Self::Message> {
nih_plug_iced::Text::new("Hello, world!").into()
}
2022-03-06 05:39:52 +11:00
}