Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Iced to 0.13 #170

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2,084 changes: 1,454 additions & 630 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/robbert-vdh/nih-plug"

[workspace]
resolver = "2"

members = [
"nih_plug_derive",
"nih_plug_egui",
Expand Down Expand Up @@ -54,7 +55,14 @@ assert_process_allocs = ["dep:assert_no_alloc"]
# Enables an export target for standalone binaries through the
# `nih_export_standalone()` function. Disabled by default as this requires
# building additional dependencies for audio and MIDI handling.
standalone = ["dep:baseview", "dep:clap", "dep:cpal", "dep:jack", "dep:midir", "dep:rtrb"]
standalone = [
"dep:baseview",
"dep:clap",
"dep:cpal",
"dep:jack",
"dep:midir",
"dep:rtrb",
]
# Enables the `nih_export_vst3!()` macro. Enabled by default. This feature
# exists mostly for GPL-compliance reasons, since even if you don't use the VST3
# wrapper you might otherwise still include a couple (unused) symbols from the
Expand Down Expand Up @@ -83,7 +91,7 @@ backtrace = "0.3.65"
bitflags = "1.3"
cfg-if = "1.0"
# This supports CLAP 1.1.8
clap-sys = { git = "https://github.com/robbert-vdh/clap-sys.git", branch = "feature/cstr-macro" }
clap-sys = { git = "https://github.com/robbert-vdh/clap-sys.git", branch = "feature/cstr-macro" }
crossbeam = "0.8"
log = { version = "0.4", features = ["std", "release_max_level_info"] }
midi-consts = "0.1"
Expand All @@ -95,14 +103,20 @@ serde_json = "1.0"
widestring = "1.0.0-beta.1"

# Used for the `assert_process_allocs` feature
assert_no_alloc = { git = "https://github.com/robbert-vdh/rust-assert-no-alloc.git", branch = "feature/nested-permit-forbid", features = ["backtrace", "log"], optional = true }
assert_no_alloc = { git = "https://github.com/robbert-vdh/rust-assert-no-alloc.git", branch = "feature/nested-permit-forbid", features = [
"backtrace",
"log",
], optional = true }

# Used for the `standalone` feature
# NOTE: OpenGL support is not needed here, but rust-analyzer gets confused when
# some crates do use it and others don't
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "579130ecb4f9f315ae52190af42f0ea46aeaa4a2", features = ["opengl"], optional = true }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "579130ecb4f9f315ae52190af42f0ea46aeaa4a2", default_features = false, optional = true }
# All the claps!
clap = { version = "4.1.8", features = ["derive", "wrap_help"], optional = true }
clap = { version = "4.1.8", features = [
"derive",
"wrap_help",
], optional = true }
cpal = { version = "0.15", optional = true }
jack = { version = "0.11.4", optional = true }
midir = { version = "0.9.1", optional = true }
Expand Down
52 changes: 16 additions & 36 deletions nih_plug_iced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "ISC"
description = "An adapter to use iced GUIs with NIH-plug"

[features]
default = ["opengl"]
default = []

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

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

# # Enables the `Image` widget, only supported by the wgpu backend
# wgpu_image = ["iced_baseview/wgpu_image"]
# # Enables the `Svg` widget, only supported by the wgpu backend
# wgpu_svg = ["iced_baseview/wgpu_svg"]

# # Enables the `Canvas` widget for the wgpu backend
# wgpu_canvas = ["iced_baseview/wgpu_canvas"]
# Enables the `Canvas` widget for the OpenGL backend
opengl_canvas = ["iced_baseview/glow_canvas"]

# # Enables the `QRCode` widget for the wgpu backend
# wgpu_qr_code = ["iced_baseview/wgpu_qr_code"]
# Enables the `QRCode` widget for the OpenGL backend
opengl_qr_code = ["iced_baseview/glow_qr_code"]

# # Enables using system fonts for the wgpu backend
# wgpu_default_system_font = ["iced_baseview/wgpu_default_system_font"]
# Enables using system fonts for the OpenGL backend
opengl_default_system_font = ["iced_baseview/glow_default_system_font"]

# Enables advanced color conversion via `palette`
palette = ["iced_baseview/palette"]

# Enables `tokio` as the `executor::Default` on native platforms
tokio = ["iced_baseview/tokio"]
# Enables `async-std` as the `executor::Default` on native platforms
async-std = ["iced_baseview/async-std"]
# Enables `smol` as the `executor::Default` on native platforms
smol = ["iced_baseview/smol"]
wgpu = ["iced_baseview/wgpu"]
# Enables the `Image` widget, only supported by the wgpu backend
image = ["iced_baseview/image"]
# Enables the `Svg` widget, only supported by the wgpu backend
svg = ["iced_baseview/svg"]
# Enables the `Canvas` widget for the wgpu backend
canvas = ["iced_baseview/canvas"]

[dependencies]
nih_plug = { path = "..", default-features = false }
nih_plug = { path = "..", default_features = false }
nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }

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

atomic_refcell = "0.1"
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "579130ecb4f9f315ae52190af42f0ea46aeaa4a2" }
crossbeam = "0.8"
# This targets iced 0.4
iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default-features = false }
# This targets iced 0.13
iced_baseview = { git = "https://github.com/BillyDM/iced_baseview.git", rev = "a0842a8205c852127981e27de6342cf2e665562f", default_features = false }
futures-util = "0.3"

# To make the state persistable
serde = { version = "1.0", features = ["derive"] }
2 changes: 1 addition & 1 deletion nih_plug_iced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configurations. To use wgpu instead, include the crate with the following
options:

```toml
nih_plug_iced = { git = "https://github.com/robbert-vdh/nih-plug.git", default-features = false, features = ["wgpu"] }
nih_plug_iced = { git = "https://github.com/robbert-vdh/nih-plug.git", default_features = false, features = ["wgpu"] }
```

Iced has many more optional features. Check the `Cargo.toml` file for more
Expand Down
71 changes: 31 additions & 40 deletions nih_plug_iced/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
//! Binary assets for use with `nih_plug_iced`.

use crate::Font;
use std::borrow::Cow;

use crate::core::Font;

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

pub const NOTO_SANS_REGULAR: Font = Font::External {
name: "Noto Sans Regular",
bytes: fonts::NOTO_SANS_REGULAR,
};

pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::External {
name: "Noto Sans Regular Italic",
bytes: fonts::NOTO_SANS_REGULAR_ITALIC,
};

pub const NOTO_SANS_THIN: Font = Font::External {
name: "Noto Sans Thin",
bytes: fonts::NOTO_SANS_THIN,
};

pub const NOTO_SANS_THIN_ITALIC: Font = Font::External {
name: "Noto Sans Thin Italic",
bytes: fonts::NOTO_SANS_THIN_ITALIC,
};

pub const NOTO_SANS_LIGHT: Font = Font::External {
name: "Noto Sans Light",
bytes: fonts::NOTO_SANS_LIGHT,
};

pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::External {
name: "Noto Sans Light Italic",
bytes: fonts::NOTO_SANS_LIGHT_ITALIC,
};

pub const NOTO_SANS_BOLD: Font = Font::External {
name: "Noto Sans Bold",
bytes: fonts::NOTO_SANS_BOLD,
};

pub const NOTO_SANS_BOLD_ITALIC: Font = Font::External {
name: "Noto Sans Bold Italic",
bytes: fonts::NOTO_SANS_BOLD_ITALIC,
};
pub const NOTO_SANS_REGULAR: Font = Font::with_name("Noto Sans Regular");
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::with_name("Noto Sans Regular Italic");
pub const NOTO_SANS_THIN: Font = Font::with_name("Noto Sans Thin");
pub const NOTO_SANS_THIN_ITALIC: Font = Font::with_name("Noto Sans Thin Italic");
pub const NOTO_SANS_LIGHT: Font = Font::with_name("Noto Sans Light");
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::with_name("Noto Sans Light Italic");
pub const NOTO_SANS_BOLD: Font = Font::with_name("Noto Sans Bold");
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::with_name("Noto Sans Bold Italic");

/// Useful for initializing the Settings, like this:
/// ```rust,ignore
/// Settings {
/// ...
/// fonts: noto_sans_fonts_data().into_iter().collect(),
/// }
/// ```
pub const fn noto_sans_fonts_data() -> [Cow<'static, [u8]>; 8] {
[
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR_ITALIC),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN_ITALIC),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT_ITALIC),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD),
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD_ITALIC),
]
}
80 changes: 17 additions & 63 deletions nih_plug_iced/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//! And [`Editor`] implementation for iced.

use baseview::{WindowOpenOptions, WindowScalePolicy};
use ::baseview::{WindowOpenOptions, WindowScalePolicy};
use crossbeam::atomic::AtomicCell;
use crossbeam::channel;
pub use iced_baseview::*;
use iced_baseview::settings::IcedBaseviewSettings;
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::{borrow::Cow, sync::atomic::Ordering};

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

pub use iced_baseview::*;

/// An [`Editor`] implementation that renders an iced [`Application`].
pub(crate) struct IcedEditorWrapper<E: IcedEditor> {
pub(crate) iced_state: Arc<IcedState>,
pub(crate) initialization_flags: E::InitializationFlags,
pub(crate) fonts: Vec<Cow<'static, [u8]>>,

/// The scaling factor reported by the host, if any. On macOS this will never be set and we
/// should use the system scaling factor instead.
Expand All @@ -25,32 +27,6 @@ pub(crate) struct IcedEditorWrapper<E: IcedEditor> {
pub(crate) parameter_updates_receiver: Arc<channel::Receiver<ParameterUpdate>>,
}

/// This version of `baseview` uses a different version of `raw_window_handle than NIH-plug, so we
/// need to adapt it ourselves.
struct ParentWindowHandleAdapter(nih_plug::editor::ParentWindowHandle);

unsafe impl HasRawWindowHandle for ParentWindowHandleAdapter {
fn raw_window_handle(&self) -> RawWindowHandle {
match self.0 {
ParentWindowHandle::X11Window(window) => {
let mut handle = raw_window_handle::XcbHandle::empty();
handle.window = window;
RawWindowHandle::Xcb(handle)
}
ParentWindowHandle::AppKitNsView(ns_view) => {
let mut handle = raw_window_handle::AppKitHandle::empty();
handle.ns_view = ns_view;
RawWindowHandle::AppKit(handle)
}
ParentWindowHandle::Win32Hwnd(hwnd) => {
let mut handle = raw_window_handle::Win32Handle::empty();
handle.hwnd = hwnd;
RawWindowHandle::Win32(handle)
}
}
}
}

impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
fn spawn(
&self,
Expand All @@ -62,8 +38,14 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {

// TODO: iced_baseview does not have gracefuly error handling for context creation failures.
// This will panic if the context could not be created.
let window = IcedWindow::<wrapper::IcedEditorWrapperApplication<E>>::open_parented(
&ParentWindowHandleAdapter(parent),
let window = iced_baseview::open_parented::<wrapper::IcedEditorWrapperApplication<E>, _>(
&parent,
// We use this wrapper to be able to pass the GUI context to the editor
(
context,
self.parameter_updates_receiver.clone(),
self.initialization_flags.clone(),
),
Settings {
window: WindowOpenOptions {
title: String::from("iced window"),
Expand All @@ -74,41 +56,13 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
scale: scaling_factor
.map(|factor| WindowScalePolicy::ScaleFactor(factor as f64))
.unwrap_or(WindowScalePolicy::SystemScaleFactor),

#[cfg(feature = "opengl")]
gl_config: Some(baseview::gl::GlConfig {
// FIXME: glow_glyph forgot to add an `#extension`, so this won't work under
// OpenGL 3.2 at the moment. With that change applied this should work on
// OpenGL 3.2/macOS.
version: (3, 3),
red_bits: 8,
blue_bits: 8,
green_bits: 8,
alpha_bits: 8,
depth_bits: 24,
stencil_bits: 8,
samples: None,
srgb: true,
double_buffer: true,
vsync: true,
..Default::default()
}),
// FIXME: Rust analyzer always thinks baseview/opengl is enabled even if we
// don't explicitly enable it, so you'd get a compile error if this line
// is missing
#[cfg(not(feature = "opengl"))]
gl_config: None,
},
iced_baseview: IcedBaseviewSettings {
ignore_non_modifier_keys: false,
always_redraw: true,
},
// We use this wrapper to be able to pass the GUI context to the editor
flags: (
context,
self.parameter_updates_receiver.clone(),
self.initialization_flags.clone(),
),
fonts: self.fonts.clone(),
..Default::default()
},
);

Expand Down Expand Up @@ -154,7 +108,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
/// The window handle used for [`IcedEditorWrapper`].
struct IcedEditorHandle<Message: 'static + Send> {
iced_state: Arc<IcedState>,
window: iced_baseview::WindowHandle<Message>,
window: iced_baseview::window::WindowHandle<Message>,
}

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