From 8bc61837c9bb7d4e39f8db7ec54140de6520058d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 26 Sep 2022 16:46:00 +0200 Subject: [PATCH] Move the flush request to the audio thread --- src/common/serialization/clap.h | 10 ++++----- src/common/serialization/clap/ext/params.h | 2 -- src/plugin/bridges/clap.cpp | 21 +++++++++---------- src/plugin/bridges/clap.h | 4 ++-- .../bridges/clap-impls/host-proxy.cpp | 2 +- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/common/serialization/clap.h b/src/common/serialization/clap.h index c5d0c194..be4a1611 100644 --- a/src/common/serialization/clap.h +++ b/src/common/serialization/clap.h @@ -151,11 +151,7 @@ using ClapMainThreadCallbackRequest = clap::ext::note_ports::host::SupportedDialects, clap::ext::note_ports::host::Rescan, clap::ext::params::host::Rescan, - clap::ext::params::host::Clear, - // This doesn't need to be done on the main thread, but we - // don't have an alternative per-plugin instance socket - // available so this is probably fine - clap::ext::params::host::RequestFlush>; + clap::ext::params::host::Clear>; template void serialize(S& s, ClapMainThreadCallbackRequest& payload) { @@ -177,7 +173,9 @@ void serialize(S& s, ClapMainThreadCallbackRequest& payload) { * used. */ using ClapAudioThreadCallbackRequest = - std::variant; + std::variant; template void serialize(S& s, ClapAudioThreadCallbackRequest& payload) { diff --git a/src/common/serialization/clap/ext/params.h b/src/common/serialization/clap/ext/params.h index 6a397c3b..ba3fbaa6 100644 --- a/src/common/serialization/clap/ext/params.h +++ b/src/common/serialization/clap/ext/params.h @@ -223,8 +223,6 @@ struct FlushResponse { } }; -// TODO: This can be either a main thread or an audio thread function call -// depending on whether or not the plugin is active /** * Message struct for `clap_plugin_params::flush()`. */ diff --git a/src/plugin/bridges/clap.cpp b/src/plugin/bridges/clap.cpp index f07fc814..824f20c1 100644 --- a/src/plugin/bridges/clap.cpp +++ b/src/plugin/bridges/clap.cpp @@ -179,17 +179,6 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path) return Ack{}; }, - [&](const clap::ext::params::host::RequestFlush& request) - -> clap::ext::params::host::RequestFlush::Response { - const auto& [plugin_proxy, _] = - get_proxy(request.owner_instance_id); - - // This doesn't need to be called from the main thread - plugin_proxy.host_extensions_.params->request_flush( - plugin_proxy.host_); - - return Ack{}; - }, }); }); } @@ -277,6 +266,16 @@ void ClapPluginBridge::register_plugin_proxy( // hell. I haven't been able to figure out why. return {}; }, + [&](const clap::ext::params::host::RequestFlush& request) + -> clap::ext::params::host::RequestFlush::Response { + const auto& [plugin_proxy, _] = + get_proxy(request.owner_instance_id); + + plugin_proxy.host_extensions_.params->request_flush( + plugin_proxy.host_); + + return Ack{}; + }, [&](const clap::ext::tail::host::Changed& request) -> clap::ext::tail::host::Changed::Response { // FIXME: diff --git a/src/plugin/bridges/clap.h b/src/plugin/bridges/clap.h index 27f5867b..b1186f1c 100644 --- a/src/plugin/bridges/clap.h +++ b/src/plugin/bridges/clap.h @@ -116,8 +116,8 @@ class ClapPluginBridge : PluginBridge> { } /** - * Send an a message to a plugin instance's audio thread. This is separate - * from `send_message()`, which shares one socket for all plugin instances. + * Send a message to a plugin instance's audio thread. This is separate from + * `send_message()`, which shares one socket for all plugin instances. */ template typename T::Response send_audio_thread_message(const T& object) { diff --git a/src/wine-host/bridges/clap-impls/host-proxy.cpp b/src/wine-host/bridges/clap-impls/host-proxy.cpp index bf878215..3dbf63a2 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.cpp +++ b/src/wine-host/bridges/clap-impls/host-proxy.cpp @@ -197,7 +197,7 @@ clap_host_proxy::ext_params_request_flush(const clap_host_t* host) { assert(host && host->host_data); auto self = static_cast(host->host_data); - self->bridge_.send_main_thread_message( + self->bridge_.send_audio_thread_message( clap::ext::params::host::RequestFlush{.owner_instance_id = self->owner_instance_id()}); }