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/>.
|
|
|
|
|
2022-03-14 04:44:22 +11:00
|
|
|
use nih_plug::prelude::{Editor, GuiContext, Param};
|
2022-03-13 23:31:28 +11:00
|
|
|
use nih_plug_iced::widgets::ParamMessage;
|
2022-03-13 11:04:04 +11:00
|
|
|
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
|
2022-03-13 09:28:18 +11:00
|
|
|
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>>,
|
2022-03-13 09:28:18 +11:00
|
|
|
editor_state: Arc<IcedState>,
|
2022-03-06 05:39:52 +11:00
|
|
|
) -> Option<Box<dyn Editor>> {
|
2022-03-13 09:28:18 +11:00
|
|
|
create_iced_editor::<DiopserEditor>(editor_state, params)
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DiopserEditor {
|
|
|
|
params: Pin<Arc<DiopserParams>>,
|
2022-03-13 11:04:04 +11:00
|
|
|
context: Arc<dyn GuiContext>,
|
2022-03-14 04:44:22 +11:00
|
|
|
|
|
|
|
// FIXME: All of this is just to test the reactivity
|
|
|
|
button_state: nih_plug_iced::widget::button::State,
|
2022-03-13 09:28:18 +11:00
|
|
|
}
|
|
|
|
|
2022-03-13 23:31:28 +11:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2022-03-14 04:44:22 +11:00
|
|
|
enum Message {
|
|
|
|
/// Update a parameter's value.
|
2022-03-13 23:31:28 +11:00
|
|
|
ParamUpdate(ParamMessage),
|
|
|
|
}
|
|
|
|
|
2022-03-13 11:04:04 +11:00
|
|
|
impl IcedEditor for DiopserEditor {
|
2022-03-13 09:28:18 +11:00
|
|
|
type Executor = nih_plug_iced::executor::Default;
|
2022-03-14 04:44:22 +11:00
|
|
|
type Message = Message;
|
2022-03-13 11:04:04 +11:00
|
|
|
type InitializationFlags = Pin<Arc<DiopserParams>>;
|
2022-03-13 09:28:18 +11:00
|
|
|
|
2022-03-13 11:04:04 +11:00
|
|
|
fn new(
|
|
|
|
params: Self::InitializationFlags,
|
|
|
|
context: Arc<dyn GuiContext>,
|
|
|
|
) -> (Self, Command<Self::Message>) {
|
2022-03-14 04:44:22 +11:00
|
|
|
let editor = DiopserEditor {
|
|
|
|
params,
|
|
|
|
context,
|
|
|
|
button_state: Default::default(),
|
|
|
|
};
|
2022-03-13 09:28:18 +11:00
|
|
|
|
|
|
|
(editor, Command::none())
|
|
|
|
}
|
|
|
|
|
2022-03-13 23:31:28 +11:00
|
|
|
fn context(&self) -> &dyn GuiContext {
|
|
|
|
self.context.as_ref()
|
|
|
|
}
|
|
|
|
|
2022-03-13 09:28:18 +11:00
|
|
|
fn update(
|
|
|
|
&mut self,
|
2022-03-13 23:31:28 +11:00
|
|
|
_window: &mut nih_plug_iced::WindowQueue,
|
2022-03-13 09:28:18 +11:00
|
|
|
message: Self::Message,
|
|
|
|
) -> Command<Self::Message> {
|
2022-03-13 23:31:28 +11:00
|
|
|
match message {
|
2022-03-14 04:44:22 +11:00
|
|
|
Message::ParamUpdate(message) => self.handle_param_message(message),
|
2022-03-13 23:31:28 +11:00
|
|
|
}
|
|
|
|
|
2022-03-13 09:28:18 +11:00
|
|
|
Command::none()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn view(&mut self) -> Element<'_, Self::Message> {
|
2022-03-14 04:44:22 +11:00
|
|
|
nih_plug_iced::Row::new()
|
|
|
|
.height(nih_plug_iced::Length::Fill)
|
|
|
|
.align_items(nih_plug_iced::Alignment::Center)
|
|
|
|
.push(
|
|
|
|
nih_plug_iced::Column::new()
|
|
|
|
.width(nih_plug_iced::Length::Fill)
|
|
|
|
.align_items(nih_plug_iced::Alignment::Center)
|
|
|
|
.push(nih_plug_iced::Text::new(format!(
|
|
|
|
"{} filters active",
|
|
|
|
self.params.filter_stages.value
|
|
|
|
)))
|
|
|
|
.push(
|
|
|
|
nih_plug_iced::Button::new(
|
|
|
|
&mut self.button_state,
|
|
|
|
nih_plug_iced::Text::new("MAXIMUM POWAH"),
|
|
|
|
)
|
|
|
|
.on_press(Message::ParamUpdate(
|
|
|
|
ParamMessage::SetParameterNormalized(
|
|
|
|
self.params.filter_stages.as_ptr(),
|
|
|
|
1.0,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.into()
|
2022-03-13 09:28:18 +11:00
|
|
|
}
|
2022-03-06 05:39:52 +11:00
|
|
|
}
|