Use a vizia generic UI for Crisp
This commit is contained in:
parent
4086ff724f
commit
57fb259104
|
@ -10,4 +10,4 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nih_plug = { path = "../../", features = ["assert_process_allocs"] }
|
nih_plug = { path = "../../", features = ["assert_process_allocs"] }
|
||||||
nih_plug_iced = { path = "../../nih_plug_iced" }
|
nih_plug_vizia = { path = "../../nih_plug_vizia" }
|
||||||
|
|
|
@ -14,88 +14,61 @@
|
||||||
// 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, GuiContext};
|
use nih_plug::prelude::Editor;
|
||||||
use nih_plug_iced::widgets as nih_widgets;
|
use nih_plug_vizia::vizia::*;
|
||||||
use nih_plug_iced::widgets::generic_ui::GenericUi;
|
use nih_plug_vizia::widgets::*;
|
||||||
use nih_plug_iced::*;
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::CrispParams;
|
use crate::CrispParams;
|
||||||
|
|
||||||
|
/// VIZIA uses points instead of pixels for text
|
||||||
|
const POINT_SCALE: f32 = 0.75;
|
||||||
|
|
||||||
|
#[derive(Lens)]
|
||||||
|
// TODO: Lens requires everything to be marked as `pub`
|
||||||
|
pub struct Data {
|
||||||
|
params: Pin<Arc<CrispParams>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Model for Data {}
|
||||||
|
|
||||||
// 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(crate) fn default_state() -> Arc<IcedState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
// We have a scroll bar, so we should proudly show off that we have a scroll bar
|
ViziaState::from_size(400, 330)
|
||||||
IcedState::from_size(370, 330)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(
|
pub(crate) fn create(
|
||||||
params: Pin<Arc<CrispParams>>,
|
params: Pin<Arc<CrispParams>>,
|
||||||
editor_state: Arc<IcedState>,
|
editor_state: Arc<ViziaState>,
|
||||||
) -> Option<Box<dyn Editor>> {
|
) -> Option<Box<dyn Editor>> {
|
||||||
create_iced_editor::<CrispEditor>(editor_state, params)
|
create_vizia_editor(editor_state, move |cx| {
|
||||||
}
|
Data {
|
||||||
|
params: params.clone(),
|
||||||
struct CrispEditor {
|
|
||||||
params: Pin<Arc<CrispParams>>,
|
|
||||||
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 CrispEditor {
|
|
||||||
type Executor = executor::Default;
|
|
||||||
type Message = Message;
|
|
||||||
type InitializationFlags = Pin<Arc<CrispParams>>;
|
|
||||||
|
|
||||||
fn new(
|
|
||||||
params: Self::InitializationFlags,
|
|
||||||
context: Arc<dyn GuiContext>,
|
|
||||||
) -> (Self, Command<Self::Message>) {
|
|
||||||
let editor = CrispEditor {
|
|
||||||
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),
|
|
||||||
}
|
}
|
||||||
|
.build(cx);
|
||||||
|
|
||||||
Command::none()
|
VStack::new(cx, |cx| {
|
||||||
}
|
Label::new(cx, "Crisp")
|
||||||
|
.font(assets::NOTO_SANS_THIN)
|
||||||
|
.font_size(40.0 * POINT_SCALE)
|
||||||
|
.height(Pixels(50.0))
|
||||||
|
.child_top(Stretch(1.0))
|
||||||
|
.child_bottom(Pixels(0.0))
|
||||||
|
// Make this more or less align with the parameters column
|
||||||
|
.right(Percentage(14.0));
|
||||||
|
|
||||||
fn view(&mut self) -> Element<'_, Self::Message> {
|
ScrollView::new(cx, 0.0, 0.0, false, true, |cx| {
|
||||||
GenericUi::new(&mut self.generic_ui_state, self.params.as_ref())
|
// This looks better if it's flush at the top, and then we'll just add some padding
|
||||||
.pad_scrollbar()
|
// at the top of the scroll view
|
||||||
.map(Message::ParamUpdate)
|
GenericUi::new(cx, Data::params).child_top(Pixels(0.0));
|
||||||
}
|
})
|
||||||
|
.width(Percentage(100.0))
|
||||||
fn background_color(&self) -> nih_plug_iced::Color {
|
.top(Pixels(5.0));
|
||||||
nih_plug_iced::Color {
|
})
|
||||||
r: 0.98,
|
.row_between(Pixels(0.0))
|
||||||
g: 0.98,
|
.child_left(Stretch(1.0))
|
||||||
b: 0.98,
|
.child_right(Stretch(1.0));
|
||||||
a: 1.0,
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
extern crate nih_plug;
|
extern crate nih_plug;
|
||||||
|
|
||||||
use nih_plug::prelude::*;
|
use nih_plug::prelude::*;
|
||||||
use nih_plug_iced::IcedState;
|
use nih_plug_vizia::ViziaState;
|
||||||
use pcg::Pcg32iState;
|
use pcg::Pcg32iState;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -45,7 +45,7 @@ const MAX_FILTER_FREQUENCY: f32 = 22_000.0;
|
||||||
/// 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<Arc<CrispParams>>,
|
params: Pin<Arc<CrispParams>>,
|
||||||
editor_state: Arc<IcedState>,
|
editor_state: Arc<ViziaState>,
|
||||||
|
|
||||||
/// Needed for computing the filter coefficients.
|
/// Needed for computing the filter coefficients.
|
||||||
sample_rate: f32,
|
sample_rate: f32,
|
||||||
|
|
Loading…
Reference in a new issue