Skip to content

Commit 20f68b8

Browse files
committed
WIP
1 parent 7a01b57 commit 20f68b8

File tree

17 files changed

+1767
-1088
lines changed

17 files changed

+1767
-1088
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 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",
@@ -142,3 +144,6 @@ strip = "symbols"
142144
inherits = "release"
143145
debug = true
144146
strip = "none"
147+
148+
[patch."https://github.com/ilya-epifanov/iced_baseview.git"]
149+
iced_baseview = { path = "../iced_baseview" }

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: 20 additions & 13 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,11 +20,16 @@ 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+
wgpu = ["iced_baseview/wgpu"]
29+
image = ["iced_baseview/image"]
30+
svg = ["iced_baseview/svg"]
31+
canvas = ["iced_baseview/canvas"]
32+
2833
# # Enables the `Image` widget, only supported by the wgpu backend
2934
# wgpu_image = ["iced_baseview/wgpu_image"]
3035
# # Enables the `Svg` widget, only supported by the wgpu backend
@@ -33,40 +38,42 @@ debug = ["iced_baseview/debug"]
3338
# # Enables the `Canvas` widget for the wgpu backend
3439
# wgpu_canvas = ["iced_baseview/wgpu_canvas"]
3540
# Enables the `Canvas` widget for the OpenGL backend
36-
opengl_canvas = ["iced_baseview/glow_canvas"]
41+
# opengl_canvas = ["iced_baseview/glow_canvas"]
3742

3843
# # Enables the `QRCode` widget for the wgpu backend
3944
# wgpu_qr_code = ["iced_baseview/wgpu_qr_code"]
4045
# Enables the `QRCode` widget for the OpenGL backend
41-
opengl_qr_code = ["iced_baseview/glow_qr_code"]
46+
# opengl_qr_code = ["iced_baseview/glow_qr_code"]
4247

4348
# # Enables using system fonts for the wgpu backend
4449
# wgpu_default_system_font = ["iced_baseview/wgpu_default_system_font"]
4550
# Enables using system fonts for the OpenGL backend
46-
opengl_default_system_font = ["iced_baseview/glow_default_system_font"]
51+
# opengl_default_system_font = ["iced_baseview/glow_default_system_font"]
4752

4853
# Enables advanced color conversion via `palette`
49-
palette = ["iced_baseview/palette"]
54+
# palette = ["iced_baseview/palette"]
5055

5156
# Enables `tokio` as the `executor::Default` on native platforms
52-
tokio = ["iced_baseview/tokio"]
57+
# tokio = ["iced_baseview/tokio"]
5358
# Enables `async-std` as the `executor::Default` on native platforms
54-
async-std = ["iced_baseview/async-std"]
59+
# async-std = ["iced_baseview/async-std"]
5560
# Enables `smol` as the `executor::Default` on native platforms
56-
smol = ["iced_baseview/smol"]
61+
# smol = ["iced_baseview/smol"]
5762

5863
[dependencies]
59-
nih_plug = { path = ".." }
64+
nih_plug = { path = "..", default-features = false }
6065
nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }
6166

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

6671
atomic_refcell = "0.1"
67-
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
72+
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "fdb43ea" }
6873
crossbeam = "0.8"
6974
# This targets iced 0.4
70-
iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default_features = false }
75+
iced_baseview = { git = "https://github.com/ilya-epifanov/iced_baseview.git", branch = "fonts_and_optional_window_messages", default_features = false }
76+
futures-util = "0.3"
77+
7178
# To make the state persistable
7279
serde = { version = "1.0", features = ["derive"] }

nih_plug_iced/src/assets.rs

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

55
// This module provides a re-export and simple font wrappers around the re-exported fonts.
66
pub use nih_plug_assets::*;
77

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-
};
8+
pub const NOTO_SANS_REGULAR: Font = Font::with_name("Noto Sans Regular");
9+
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::with_name("Noto Sans Regular Italic");
10+
pub const NOTO_SANS_THIN: Font = Font::with_name("Noto Sans Thin");
11+
pub const NOTO_SANS_THIN_ITALIC: Font = Font::with_name("Noto Sans Thin Italic");
12+
pub const NOTO_SANS_LIGHT: Font = Font::with_name("Noto Sans Light");
13+
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::with_name("Noto Sans Light Italic");
14+
pub const NOTO_SANS_BOLD: Font = Font::with_name("Noto Sans Bold");
15+
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::with_name("Noto Sans Bold Italic");

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

0 commit comments

Comments
 (0)