Skip to content

Commit 6dd08e4

Browse files
committed
WIP
1 parent 7a01b57 commit 6dd08e4

File tree

16 files changed

+1982
-1244
lines changed

16 files changed

+1982
-1244
lines changed

Cargo.lock

Lines changed: 1447 additions & 841 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ description = "A simple but modern API-agnostic audio plugin framework"
1111
repository = "https://github.com/robbert-vdh/nih-plug"
1212

1313
[workspace]
14+
resolver = "2"
15+
1416
members = [
1517
"nih_plug_derive",
1618
"nih_plug_egui",

nih_plug_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ quote = "1.0"
1414
proc-macro2 = "1.0"
1515

1616
[dev-dependencies]
17-
nih_plug = { path = ".." }
17+
nih_plug = { path = "..", default-features = false }

nih_plug_egui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ egui-default-features = ["egui/default"]
1717
opengl = []
1818

1919
[dependencies]
20-
nih_plug = { path = ".." }
20+
nih_plug = { path = "..", default-features = false }
2121

2222
# The currently targeted version of baseview uses a different version of
2323
# `raw_window_handle` than NIH-plug, so we need to manually convert between them

nih_plug_iced/Cargo.toml

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "ISC"
88
description = "An adapter to use iced GUIs with NIH-plug"
99

1010
[features]
11-
default = ["opengl"]
11+
default = []
1212

1313
# NOTE: wgpu support has been removed from the iced-baseview fork out because
1414
# this old iced version uses a wgpu version that doesn't pin the web-sys
@@ -20,53 +20,33 @@ default = ["opengl"]
2020
# wgpu = ["iced_baseview/wgpu", "baseview/opengl"]
2121
# Use OpenGL instead of wgpu for the rendering. This should increase platform
2222
# compatibility at the cost of some iced features not being available.
23-
opengl = ["iced_baseview/glow"]
23+
# opengl = ["iced_baseview/glow"]
2424

2525
# Enables a debug view in native platforms (press F12)
2626
debug = ["iced_baseview/debug"]
2727

28-
# # Enables the `Image` widget, only supported by the wgpu backend
29-
# wgpu_image = ["iced_baseview/wgpu_image"]
30-
# # Enables the `Svg` widget, only supported by the wgpu backend
31-
# wgpu_svg = ["iced_baseview/wgpu_svg"]
32-
33-
# # Enables the `Canvas` widget for the wgpu backend
34-
# wgpu_canvas = ["iced_baseview/wgpu_canvas"]
35-
# Enables the `Canvas` widget for the OpenGL backend
36-
opengl_canvas = ["iced_baseview/glow_canvas"]
37-
38-
# # Enables the `QRCode` widget for the wgpu backend
39-
# wgpu_qr_code = ["iced_baseview/wgpu_qr_code"]
40-
# Enables the `QRCode` widget for the OpenGL backend
41-
opengl_qr_code = ["iced_baseview/glow_qr_code"]
42-
43-
# # Enables using system fonts for the wgpu backend
44-
# wgpu_default_system_font = ["iced_baseview/wgpu_default_system_font"]
45-
# Enables using system fonts for the OpenGL backend
46-
opengl_default_system_font = ["iced_baseview/glow_default_system_font"]
47-
48-
# Enables advanced color conversion via `palette`
49-
palette = ["iced_baseview/palette"]
50-
51-
# Enables `tokio` as the `executor::Default` on native platforms
52-
tokio = ["iced_baseview/tokio"]
53-
# Enables `async-std` as the `executor::Default` on native platforms
54-
async-std = ["iced_baseview/async-std"]
55-
# Enables `smol` as the `executor::Default` on native platforms
56-
smol = ["iced_baseview/smol"]
28+
wgpu = ["iced_baseview/wgpu"]
29+
# Enables the `Image` widget, only supported by the wgpu backend
30+
image = ["iced_baseview/image"]
31+
# Enables the `Svg` widget, only supported by the wgpu backend
32+
svg = ["iced_baseview/svg"]
33+
# Enables the `Canvas` widget for the wgpu backend
34+
canvas = ["iced_baseview/canvas"]
5735

5836
[dependencies]
59-
nih_plug = { path = ".." }
37+
nih_plug = { path = "..", default-features = false }
6038
nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }
6139

6240
# The currently targeted version of baseview uses a different version of
6341
# `raw_window_handle` than NIH-plug, so we need to manually convert between them
64-
raw-window-handle = "0.4"
42+
raw-window-handle = "0.5"
6543

6644
atomic_refcell = "0.1"
67-
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
45+
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "fdb43ea" }
6846
crossbeam = "0.8"
69-
# This targets iced 0.4
70-
iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default_features = false }
47+
# This targets iced 0.10
48+
iced_baseview = { git = "https://github.com/BillyDM/iced_baseview.git", rev = "4feacc03bc1135023f73167093aea953a858a7c2", default_features = false }
49+
futures-util = "0.3"
50+
7151
# To make the state persistable
7252
serde = { version = "1.0", features = ["derive"] }

nih_plug_iced/src/assets.rs

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
11
//! Binary assets for use with `nih_plug_iced`.
22
3-
use crate::Font;
3+
use std::borrow::Cow;
44

5+
use crate::core::Font;
6+
7+
use iced_baseview::runtime::{font, Command};
58
// This module provides a re-export and simple font wrappers around the re-exported fonts.
69
pub use nih_plug_assets::*;
710

8-
pub const NOTO_SANS_REGULAR: Font = Font::External {
9-
name: "Noto Sans Regular",
10-
bytes: fonts::NOTO_SANS_REGULAR,
11-
};
12-
13-
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::External {
14-
name: "Noto Sans Regular Italic",
15-
bytes: fonts::NOTO_SANS_REGULAR_ITALIC,
16-
};
17-
18-
pub const NOTO_SANS_THIN: Font = Font::External {
19-
name: "Noto Sans Thin",
20-
bytes: fonts::NOTO_SANS_THIN,
21-
};
22-
23-
pub const NOTO_SANS_THIN_ITALIC: Font = Font::External {
24-
name: "Noto Sans Thin Italic",
25-
bytes: fonts::NOTO_SANS_THIN_ITALIC,
26-
};
27-
28-
pub const NOTO_SANS_LIGHT: Font = Font::External {
29-
name: "Noto Sans Light",
30-
bytes: fonts::NOTO_SANS_LIGHT,
31-
};
32-
33-
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::External {
34-
name: "Noto Sans Light Italic",
35-
bytes: fonts::NOTO_SANS_LIGHT_ITALIC,
36-
};
37-
38-
pub const NOTO_SANS_BOLD: Font = Font::External {
39-
name: "Noto Sans Bold",
40-
bytes: fonts::NOTO_SANS_BOLD,
41-
};
42-
43-
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::External {
44-
name: "Noto Sans Bold Italic",
45-
bytes: fonts::NOTO_SANS_BOLD_ITALIC,
46-
};
11+
pub const NOTO_SANS_REGULAR: Font = Font::with_name("Noto Sans Regular");
12+
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::with_name("Noto Sans Regular Italic");
13+
pub const NOTO_SANS_THIN: Font = Font::with_name("Noto Sans Thin");
14+
pub const NOTO_SANS_THIN_ITALIC: Font = Font::with_name("Noto Sans Thin Italic");
15+
pub const NOTO_SANS_LIGHT: Font = Font::with_name("Noto Sans Light");
16+
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::with_name("Noto Sans Light Italic");
17+
pub const NOTO_SANS_BOLD: Font = Font::with_name("Noto Sans Bold");
18+
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::with_name("Noto Sans Bold Italic");
19+
20+
/// Useful for initializing the Settings, like this:
21+
/// ```rust
22+
/// Settings {
23+
/// ...
24+
/// fonts: noto_sans_fonts_data().into_iter().collect(),
25+
/// }
26+
/// ```
27+
pub const fn noto_sans_fonts_data() -> [Cow<'static, [u8]>; 8] {
28+
[
29+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR),
30+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR_ITALIC),
31+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN),
32+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN_ITALIC),
33+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT),
34+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT_ITALIC),
35+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD),
36+
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD_ITALIC),
37+
]
38+
}

nih_plug_iced/src/editor.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
//! And [`Editor`] implementation for iced.
22
3-
use baseview::{WindowOpenOptions, WindowScalePolicy};
3+
use ::baseview::{WindowOpenOptions, WindowScalePolicy};
44
use crossbeam::atomic::AtomicCell;
55
use crossbeam::channel;
6-
pub use iced_baseview::*;
6+
use iced_baseview::settings::IcedBaseviewSettings;
77
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle};
88
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
9-
use std::sync::atomic::Ordering;
9+
use std::{borrow::Cow, sync::atomic::Ordering};
1010
use std::sync::Arc;
1111

1212
use crate::{wrapper, IcedEditor, IcedState, ParameterUpdate};
1313

14+
pub use iced_baseview::*;
15+
1416
/// An [`Editor`] implementation that renders an iced [`Application`].
1517
pub(crate) struct IcedEditorWrapper<E: IcedEditor> {
1618
pub(crate) iced_state: Arc<IcedState>,
1719
pub(crate) initialization_flags: E::InitializationFlags,
20+
pub(crate) fonts: Vec<Cow<'static, [u8]>>,
1821

1922
/// The scaling factor reported by the host, if any. On macOS this will never be set and we
2023
/// should use the system scaling factor instead.
@@ -33,17 +36,17 @@ unsafe impl HasRawWindowHandle for ParentWindowHandleAdapter {
3336
fn raw_window_handle(&self) -> RawWindowHandle {
3437
match self.0 {
3538
ParentWindowHandle::X11Window(window) => {
36-
let mut handle = raw_window_handle::XcbHandle::empty();
39+
let mut handle = raw_window_handle::XcbWindowHandle::empty();
3740
handle.window = window;
3841
RawWindowHandle::Xcb(handle)
3942
}
4043
ParentWindowHandle::AppKitNsView(ns_view) => {
41-
let mut handle = raw_window_handle::AppKitHandle::empty();
44+
let mut handle = raw_window_handle::AppKitWindowHandle::empty();
4245
handle.ns_view = ns_view;
4346
RawWindowHandle::AppKit(handle)
4447
}
4548
ParentWindowHandle::Win32Hwnd(hwnd) => {
46-
let mut handle = raw_window_handle::Win32Handle::empty();
49+
let mut handle = raw_window_handle::Win32WindowHandle::empty();
4750
handle.hwnd = hwnd;
4851
RawWindowHandle::Win32(handle)
4952
}
@@ -62,7 +65,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
6265

6366
// TODO: iced_baseview does not have gracefuly error handling for context creation failures.
6467
// This will panic if the context could not be created.
65-
let window = IcedWindow::<wrapper::IcedEditorWrapperApplication<E>>::open_parented(
68+
let window = iced_baseview::open_parented::<wrapper::IcedEditorWrapperApplication<E>, _>(
6669
&ParentWindowHandleAdapter(parent),
6770
Settings {
6871
window: WindowOpenOptions {
@@ -96,8 +99,8 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
9699
// FIXME: Rust analyzer always thinks baseview/opengl is enabled even if we
97100
// don't explicitly enable it, so you'd get a compile error if this line
98101
// is missing
99-
#[cfg(not(feature = "opengl"))]
100-
gl_config: None,
102+
// #[cfg(not(feature = "opengl"))]
103+
// gl_config: None,
101104
},
102105
iced_baseview: IcedBaseviewSettings {
103106
ignore_non_modifier_keys: false,
@@ -109,6 +112,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
109112
self.parameter_updates_receiver.clone(),
110113
self.initialization_flags.clone(),
111114
),
115+
fonts: self.fonts.clone(),
112116
},
113117
);
114118

@@ -154,7 +158,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
154158
/// The window handle used for [`IcedEditorWrapper`].
155159
struct IcedEditorHandle<Message: 'static + Send> {
156160
iced_state: Arc<IcedState>,
157-
window: iced_baseview::WindowHandle<Message>,
161+
window: iced_baseview::window::WindowHandle<Message>,
158162
}
159163

160164
/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around

nih_plug_iced/src/lib.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,20 @@
8989
//! }
9090
//! ```
9191
92-
use baseview::WindowScalePolicy;
92+
use ::baseview::WindowScalePolicy;
9393
use crossbeam::atomic::AtomicCell;
9494
use crossbeam::channel;
95+
use iced_baseview::core::{Color, Element, Font};
96+
use iced_baseview::futures::{Executor, Subscription};
97+
use iced_baseview::graphics::Antialiasing;
98+
use iced_baseview::runtime::Command;
99+
use iced_baseview::style::application::StyleSheet;
100+
use iced_baseview::widget::renderer::Settings as RendererSettings;
101+
use iced_baseview::window::WindowSubs;
95102
use nih_plug::params::persist::PersistentField;
96103
use nih_plug::prelude::{Editor, GuiContext};
97104
use serde::{Deserialize, Serialize};
105+
use std::borrow::Cow;
98106
// This doesn't need to be re-export but otherwise the compiler complains about
99107
// `hidden_glob_reexports`
100108
pub use std::fmt::Debug;
@@ -126,6 +134,7 @@ mod wrapper;
126134
pub fn create_iced_editor<E: IcedEditor>(
127135
iced_state: Arc<IcedState>,
128136
initialization_flags: E::InitializationFlags,
137+
fonts: Vec<Cow<'static, [u8]>>,
129138
) -> Option<Box<dyn Editor>> {
130139
// We need some way to communicate parameter changes to the `IcedEditor` since parameter updates
131140
// come from outside of the editor's reactive model. This contains only capacity to store only
@@ -147,6 +156,7 @@ pub fn create_iced_editor<E: IcedEditor>(
147156

148157
parameter_updates_sender,
149158
parameter_updates_receiver: Arc::new(parameter_updates_receiver),
159+
fonts,
150160
}))
151161
}
152162

@@ -162,6 +172,8 @@ pub trait IcedEditor: 'static + Send + Sync + Sized {
162172
type Message: 'static + Clone + Debug + Send;
163173
/// See [`Application::Flags`].
164174
type InitializationFlags: 'static + Clone + Send + Sync;
175+
/// See [`Application::Theme`]
176+
type Theme: Default + StyleSheet;
165177

166178
/// See [`Application::new`]. This also receivs the GUI context in addition to the flags.
167179
fn new(
@@ -179,7 +191,6 @@ pub trait IcedEditor: 'static + Send + Sync + Sized {
179191
/// [`handle_param_message()`][Self::handle_param_message()] to handle the parameter update.
180192
fn update(
181193
&mut self,
182-
window: &mut WindowQueue,
183194
message: Self::Message,
184195
) -> Command<Self::Message>;
185196

@@ -192,13 +203,21 @@ pub trait IcedEditor: 'static + Send + Sync + Sized {
192203
}
193204

194205
/// See [`Application::view`].
195-
fn view(&mut self) -> Element<'_, Self::Message>;
206+
fn view(&self) -> Element<'_, Self::Message, Renderer<Self::Theme>>;
196207

197208
/// See [`Application::background_color`].
198209
fn background_color(&self) -> Color {
199210
Color::WHITE
200211
}
201212

213+
fn theme(&self) -> Self::Theme {
214+
Self::Theme::default()
215+
}
216+
217+
fn title(&self) -> String {
218+
"nih_plug plugin".to_owned()
219+
}
220+
202221
/// See [`Application::scale_policy`].
203222
///
204223
/// TODO: Is this needed? Editors shouldn't change the scale policy.
@@ -207,16 +226,13 @@ pub trait IcedEditor: 'static + Send + Sync + Sized {
207226
}
208227

209228
/// See [`Application::renderer_settings`].
210-
fn renderer_settings() -> iced_baseview::backend::settings::Settings {
211-
iced_baseview::backend::settings::Settings {
229+
fn renderer_settings() -> RendererSettings {
230+
RendererSettings {
212231
// Enable some anti-aliasing by default. Since GUIs are likely very simple and most of
213232
// the work will be on the CPU anyways this should not affect performance much.
214-
antialiasing: Some(iced_baseview::backend::settings::Antialiasing::MSAAx4),
215-
// Use Noto Sans as the default font as that renders a bit more cleanly than the default
216-
// Lato font. This crate also contains other weights and versions of this font you can
217-
// use for individual widgets.
218-
default_font: Some(crate::assets::fonts::NOTO_SANS_REGULAR),
219-
..iced_baseview::backend::settings::Settings::default()
233+
antialiasing: Some(Antialiasing::MSAAx4),
234+
default_font: Font::DEFAULT,
235+
..RendererSettings::default()
220236
}
221237
}
222238

nih_plug_iced/src/widgets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
88
use nih_plug::prelude::ParamPtr;
99

10-
pub mod generic_ui;
11-
pub mod param_slider;
10+
// pub mod generic_ui;
11+
// pub mod param_slider;
1212
pub mod peak_meter;
1313
pub mod util;
1414

15-
pub use param_slider::ParamSlider;
15+
// pub use param_slider::ParamSlider;
1616
pub use peak_meter::PeakMeter;
1717

1818
/// A message to update a parameter value. Since NIH-plug manages the parameters, interacting with

0 commit comments

Comments
 (0)