diff --git a/src/plugin/bridges/clap-impls/plugin-proxy.h b/src/plugin/bridges/clap-impls/plugin-proxy.h index cdd99c67..117e7c36 100644 --- a/src/plugin/bridges/clap-impls/plugin-proxy.h +++ b/src/plugin/bridges/clap-impls/plugin-proxy.h @@ -112,6 +112,54 @@ class clap_plugin_proxy { */ inline size_t instance_id() const { return instance_id_; } + /** + * Asynchronously run a function on the host's main thread, returning the + * result as a future. + */ + template + std::future> run_on_main_thread(F&& fn) { + using Result = std::invoke_result_t; + + std::promise response_promise{}; + std::future response_future = response_promise.get_future(); + pending_callbacks_.push(HostCallback( + [fn = std::forward(fn), + response_promise = std::move(response_promise)]() mutable { + if constexpr (std::is_void_v) { + fn(); + response_promise.set_value(); + } else { + response_promise.set_value(fn()); + } + })); + + // In theory the host will now call `clap_plugin::on_main_thread()`, + // where we can pop the function from the queue + host_->request_callback(host_); + + return response_future; + } + + /** + * The `clap_host_t*` passed when creating the instance. Any callbacks made + * by the proxied plugin instance must go through here. + */ + const clap_host_t* host_; + + /** + * The host's supported extensions. These will be populated in the + * `clap_plugin::init()` call. + */ + ClapHostExtensions host_extensions_; + + /** + * A handler for receiving audio thread callbacks. Set when initializing the + * plugin. This is needed to minimize blocking during those callbacks, as + * certain CLAP extensions allow callbacks on the audio thread. + */ + std::jthread audio_thread_handler_; + + protected: static bool CLAP_ABI plugin_init(const struct clap_plugin* plugin); static void CLAP_ABI plugin_destroy(const struct clap_plugin* plugin); static bool CLAP_ABI plugin_activate(const struct clap_plugin* plugin, @@ -170,53 +218,6 @@ class clap_plugin_proxy { static uint32_t CLAP_ABI ext_tail_get(const clap_plugin_t* plugin); - /** - * Asynchronously run a function on the host's main thread, returning the - * result as a future. - */ - template - std::future> run_on_main_thread(F&& fn) { - using Result = std::invoke_result_t; - - std::promise response_promise{}; - std::future response_future = response_promise.get_future(); - pending_callbacks_.push(HostCallback( - [fn = std::forward(fn), - response_promise = std::move(response_promise)]() mutable { - if constexpr (std::is_void_v) { - fn(); - response_promise.set_value(); - } else { - response_promise.set_value(fn()); - } - })); - - // In theory the host will now call `clap_plugin::on_main_thread()`, - // where we can pop the function from the queue - host_->request_callback(host_); - - return response_future; - } - - /** - * The `clap_host_t*` passed when creating the instance. Any callbacks made - * by the proxied plugin instance must go through here. - */ - const clap_host_t* host_; - - /** - * The host's supported extensions. These will be populated in the - * `clap_plugin::init()` call. - */ - ClapHostExtensions host_extensions_; - - /** - * A handler for receiving audio thread callbacks. Set when initializing the - * plugin. This is needed to minimize blocking during those callbacks, as - * certain CLAP extensions allow callbacks on the audio thread. - */ - std::jthread audio_thread_handler_; - private: ClapPluginBridge& bridge_; size_t instance_id_; diff --git a/src/wine-host/bridges/clap-impls/host-proxy.h b/src/wine-host/bridges/clap-impls/host-proxy.h index 9656eb9d..cb60e98d 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.h +++ b/src/wine-host/bridges/clap-impls/host-proxy.h @@ -61,6 +61,14 @@ class clap_host_proxy { */ inline size_t owner_instance_id() const { return owner_instance_id_; } + /** + * The extensions supported by the host, set just before calling + * `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to + * query these extensions through `clap_host::get_extension()`. + */ + clap::host::SupportedHostExtensions supported_extensions_; + + protected: static const void* CLAP_ABI host_get_extension(const struct clap_host* host, const char* extension_id); static void CLAP_ABI host_request_restart(const struct clap_host* host); @@ -89,13 +97,6 @@ class clap_host_proxy { static void CLAP_ABI ext_tail_changed(const clap_host_t* host); - /** - * The extensions supported by the host, set just before calling - * `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to - * query these extensions through `clap_host::get_extension()`. - */ - clap::host::SupportedHostExtensions supported_extensions_; - private: ClapBridge& bridge_; size_t owner_instance_id_;