1
0
Fork 0

Update for CLAP 0.24

This commit is contained in:
Robbert van der Helm 2022-04-05 16:32:00 +02:00
parent cf05ca10f8
commit a49393f863
4 changed files with 136 additions and 91 deletions

113
Cargo.lock generated
View file

@ -157,9 +157,9 @@ dependencies = [
[[package]]
name = "async-global-executor"
version = "2.0.3"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c026b7e44f1316b567ee750fea85103f87fcb80792b860e979f221259796ca0a"
checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43"
dependencies = [
"async-channel",
"async-executor",
@ -385,18 +385,18 @@ checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
[[package]]
name = "bytemuck"
version = "1.8.0"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e851ca7c24871e7336801608a4797d7376545b6928a10d32d75685687141ead"
checksum = "cdead85bdec19c194affaeeb670c0e41fe23de31459efd1c174d049269cf02cc"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.0.1"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
checksum = "562e382481975bc61d11275ac5e62a19abd00b0547d99516a415336f183dcd0e"
dependencies = [
"proc-macro2",
"quote",
@ -454,8 +454,8 @@ checksum = "17cc5e6b5ab06331c33589842070416baa137e8b0eb912b008cfd4a78ada7919"
[[package]]
name = "clap-sys"
version = "0.23.0"
source = "git+https://github.com/glowcoil/clap-sys#7a4cca3c2166db8d61ed3c5552f31a68694da952"
version = "0.24.0"
source = "git+https://github.com/robbert-vdh/clap-sys?branch=update/clap-0.24#a703ec943df1f34c0c664c91071cef4fb0daaeda"
[[package]]
name = "clipboard-win"
@ -897,9 +897,9 @@ dependencies = [
[[package]]
name = "euclid"
version = "0.22.6"
version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da96828553a086d7b18dcebfc579bd9628b016f86590d7453c115e490fa74b80"
checksum = "b52c2ef4a78da0ba68fbe1fd920627411096d2ac478f7f4c9f3a54ba6705bade"
dependencies = [
"num-traits",
]
@ -1631,9 +1631,9 @@ checksum = "41d0c0db6c932f8262e0ed8909f2e7f8c0e9b1cfb4da884267ce09a10be54365"
[[package]]
name = "indexmap"
version = "1.8.0"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [
"autocfg",
"hashbrown",
@ -1808,10 +1808,11 @@ dependencies = [
[[package]]
name = "lock_api"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
dependencies = [
"autocfg",
"scopeguard",
]
@ -1827,9 +1828,9 @@ dependencies = [
[[package]]
name = "lru"
version = "0.7.3"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb87f3080f6d1d69e8c564c0fcfde1d7aa8cc451ce40cae89479111f03bc0eb"
checksum = "32613e41de4c47ab04970c348ca7ae7382cf116625755af070b008a15516a889"
[[package]]
name = "lyon"
@ -2319,7 +2320,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core 0.9.1",
"parking_lot_core 0.9.2",
]
[[package]]
@ -2338,9 +2339,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37"
dependencies = [
"cfg-if 1.0.0",
"libc",
@ -2451,9 +2452,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.24"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "plain"
@ -2682,9 +2683,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
[[package]]
name = "raw-window-handle"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba75eee94a9d5273a68c9e1e105d9cffe1ef700532325788389e5a83e2522b7"
checksum = "b800beb9b6e7d2df1fe337c9e3d04e3af22a124460fb4c30fcc22c9117cefb41"
dependencies = [
"cty",
]
@ -2731,18 +2732,18 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.12"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0"
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7776223e2696f1aa4c6b0170e83212f47296a00424305117d013dfe86fb0fe55"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom 0.2.6",
"redox_syscall",
@ -3060,9 +3061,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "slab"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
[[package]]
name = "slotmap"
@ -3901,24 +3902,24 @@ version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
"windows_aarch64_msvc 0.32.0",
"windows_i686_gnu 0.32.0",
"windows_i686_msvc 0.32.0",
"windows_x86_64_gnu 0.32.0",
"windows_x86_64_msvc 0.32.0",
]
[[package]]
name = "windows-sys"
version = "0.32.0"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
"windows_aarch64_msvc 0.34.0",
"windows_i686_gnu 0.34.0",
"windows_i686_msvc 0.34.0",
"windows_x86_64_gnu 0.34.0",
"windows_x86_64_msvc 0.34.0",
]
[[package]]
@ -3927,30 +3928,60 @@ version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
[[package]]
name = "windows_aarch64_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
[[package]]
name = "windows_i686_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
[[package]]
name = "windows_i686_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
[[package]]
name = "windows_x86_64_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
[[package]]
name = "windows_x86_64_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
[[package]]
name = "wio"
version = "0.2.2"

View file

@ -48,8 +48,8 @@ atomic_float = "0.1"
atomic_refcell = "0.1"
bitflags = "1.3"
cfg-if = "1.0"
# For CLAP 0.23
clap-sys = { git = "https://github.com/glowcoil/clap-sys" }
# For CLAP 0.24
clap-sys = { git = "https://github.com/robbert-vdh/clap-sys", branch = "update/clap-0.24" }
crossbeam = "0.8"
lazy_static = "1.4"
parking_lot = "0.12"

View file

@ -1,5 +1,4 @@
use atomic_refcell::AtomicRefMut;
use crossbeam::channel;
use std::collections::VecDeque;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@ -28,22 +27,7 @@ pub(crate) struct WrapperProcessContext<'a, P: ClapPlugin> {
impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
fn request_resize(&self) -> bool {
// Bitwig and the CLAP test host require this resize to be done from the main thread, so
// we'll use a channel as a substitute for a promise here.
let (result_sender, result_receiver) = channel::bounded(1);
if !self
.wrapper
.do_maybe_async(Task::RequestResize(result_sender))
{
nih_debug_assert_failure!("The task queue is full, dropping task...");
return false;
}
// FIXME: Waiting for this can be very slow when this function gets called many times in
// rapid succession because the X11 GUI thread is not the same as the host's GUI
// thread and both Bitwig and CLAP will reject (or outright SIGABRT) if this gets
// called from any other thread
result_receiver.recv().expect("Main thread died?")
self.wrapper.request_resize()
}
// All of these functions are supposed to be called from the main thread, so we'll put some

View file

@ -22,8 +22,8 @@ use clap_sys::ext::audio_ports_config::{
};
use clap_sys::ext::event_filter::{clap_plugin_event_filter, CLAP_EXT_EVENT_FILTER};
use clap_sys::ext::gui::{
clap_host_gui, clap_plugin_gui, clap_window, CLAP_EXT_GUI, CLAP_WINDOW_API_COCOA,
CLAP_WINDOW_API_WIN32, CLAP_WINDOW_API_X11,
clap_gui_resize_hints, clap_host_gui, clap_plugin_gui, clap_window, CLAP_EXT_GUI,
CLAP_WINDOW_API_COCOA, CLAP_WINDOW_API_WIN32, CLAP_WINDOW_API_X11,
};
use clap_sys::ext::latency::{clap_host_latency, clap_plugin_latency, CLAP_EXT_LATENCY};
use clap_sys::ext::note_ports::{
@ -47,7 +47,6 @@ use clap_sys::process::{
};
use clap_sys::stream::{clap_istream, clap_ostream};
use crossbeam::atomic::AtomicCell;
use crossbeam::channel;
use crossbeam::queue::ArrayQueue;
use parking_lot::RwLock;
use raw_window_handle::RawWindowHandle;
@ -217,9 +216,6 @@ pub struct Wrapper<P: ClapPlugin> {
pub enum Task {
/// Inform the host that the latency has changed.
LatencyChanged,
/// Request a resize from the main thread. The result is written back to the one element channel
/// for a lock of a proper promise type within the current set of libraries.
RequestResize(channel::Sender<bool>),
}
/// The types of CLAP parameter updates for events.
@ -306,27 +302,6 @@ impl<P: ClapPlugin> MainThreadExecutor<Task> for Wrapper<P> {
}
None => nih_debug_assert_failure!("Host does not support the latency extension"),
},
Task::RequestResize(result_sender) => {
// Both Bitwig and the CLAP test host won't accept resizes coming from a thread that
// isn't the main thread
let result = match (&*self.host_gui.borrow(), &self.editor) {
(Some(host_gui), Some(editor)) => {
let (unscaled_width, unscaled_height) = editor.size();
let scaling_factor = self.editor_scaling_factor.load(Ordering::Relaxed);
(host_gui.request_resize)(
&*self.host_callback,
(unscaled_width as f32 * scaling_factor).round() as u32,
(unscaled_height as f32 * scaling_factor).round() as u32,
)
}
_ => false,
};
// This channel acts as a promise, there will never be more than a single value
// writen to it, and if the other end got dropped then that's okay
let _ = result_sender.send(result);
}
};
}
}
@ -507,11 +482,13 @@ impl<P: ClapPlugin> Wrapper<P> {
clap_plugin_gui: clap_plugin_gui {
is_api_supported: Self::ext_gui_is_api_supported,
get_preferred_api: Self::ext_gui_get_preferred_api,
create: Self::ext_gui_create,
destroy: Self::ext_gui_destroy,
set_scale: Self::ext_gui_set_scale,
get_size: Self::ext_gui_get_size,
can_resize: Self::ext_gui_can_resize,
get_resize_hints: Self::ext_gui_get_resize_hints,
adjust_size: Self::ext_gui_adjust_size,
set_size: Self::ext_gui_set_size,
set_parent: Self::ext_gui_set_parent,
@ -612,6 +589,27 @@ impl<P: ClapPlugin> Wrapper<P> {
}
}
/// Request a resize based on the editor's current reported size. As of CLAP 0.24 this can
/// safely be called from any thread. If this returns `false`, then the plugin should reset its
/// size back to the previous value.
pub fn request_resize(&self) -> bool {
match (&*self.host_gui.borrow(), &self.editor) {
(Some(host_gui), Some(editor)) => {
let (unscaled_width, unscaled_height) = editor.size();
let scaling_factor = self.editor_scaling_factor.load(Ordering::Relaxed);
unsafe {
(host_gui.request_resize)(
&*self.host_callback,
(unscaled_width as f32 * scaling_factor).round() as u32,
(unscaled_height as f32 * scaling_factor).round() as u32,
)
}
}
_ => false,
}
}
/// Convenience function for setting a value for a parameter as triggered by a VST3 parameter
/// update. The same rate is for updating parameter smoothing.
///
@ -1352,10 +1350,23 @@ impl<P: ClapPlugin> Wrapper<P> {
let config = &mut *config;
config.id = index;
strlcpy(&mut config.name, &name);
config.input_channel_count = bus_config.num_input_channels;
config.input_port_type = input_port_type;
config.output_channel_count = bus_config.num_output_channels;
config.output_port_type = output_port_type;
// TODO: Currently we don't support sidechain inputs or multiple outputs
config.input_port_count = if bus_config.num_input_channels > 0 {
1
} else {
0
};
config.output_port_count = if bus_config.num_output_channels > 0 {
1
} else {
0
};
config.has_main_input_channel = bus_config.num_output_channels > 0;
config.main_input_channel_count = bus_config.num_output_channels;
config.main_input_port_type = input_port_type;
config.has_main_output_channel = bus_config.num_output_channels > 0;
config.main_output_channel_count = bus_config.num_output_channels;
config.main_output_port_type = output_port_type;
true
}
@ -1527,6 +1538,15 @@ impl<P: ClapPlugin> Wrapper<P> {
false
}
unsafe extern "C" fn ext_gui_get_preferred_api(
plugin: *const clap_plugin,
api: *const c_char,
is_floating: bool,
) -> bool {
// We don't do floating windows yet, so for us this is the same as the other function
Self::ext_gui_is_api_supported(plugin, api, is_floating)
}
unsafe extern "C" fn ext_gui_create(
plugin: *const clap_plugin,
api: *const c_char,
@ -1613,6 +1633,14 @@ impl<P: ClapPlugin> Wrapper<P> {
false
}
unsafe extern "C" fn ext_gui_get_resize_hints(
_plugin: *const clap_plugin,
_hints: *mut clap_gui_resize_hints,
) -> bool {
// TODO: Implement Host->Plugin GUI resizing
false
}
unsafe extern "C" fn ext_gui_adjust_size(
_plugin: *const clap_plugin,
_width: *mut u32,
@ -1628,6 +1656,7 @@ impl<P: ClapPlugin> Wrapper<P> {
height: u32,
) -> bool {
// TODO: Implement Host->Plugin GUI resizing
// TODO: The host will also call this if an asynchronous (on Linux) resize request fails
check_null_ptr!(false, plugin);
let wrapper = &*(plugin as *const Self);
@ -1808,6 +1837,7 @@ impl<P: ClapPlugin> Wrapper<P> {
let automatable = !flags.contains(ParamFlags::NON_AUTOMATABLE);
let is_bypass = flags.contains(ParamFlags::BYPASS);
// TODO: Somehow expose modulation and per note/channel/port variations
param_info.id = *param_hash;
param_info.flags = if automatable {
CLAP_PARAM_IS_AUTOMATABLE