From e2ec0e286ffdc19398abd6640188718e78318228 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 21 Oct 2022 17:11:28 +0200 Subject: [PATCH] Implement host side of the note-name extension --- src/common/serialization/clap.h | 1 + src/common/serialization/clap/host.cpp | 4 +++- src/common/serialization/clap/host.h | 4 +++- src/plugin/bridges/clap-impls/plugin-proxy.cpp | 3 +++ src/plugin/bridges/clap-impls/plugin-proxy.h | 2 ++ src/plugin/bridges/clap.cpp | 16 ++++++++++++++++ src/wine-host/bridges/clap-impls/host-proxy.cpp | 15 +++++++++++++++ src/wine-host/bridges/clap-impls/host-proxy.h | 4 ++++ 8 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/common/serialization/clap.h b/src/common/serialization/clap.h index 50a93dfb..3d4e1f55 100644 --- a/src/common/serialization/clap.h +++ b/src/common/serialization/clap.h @@ -183,6 +183,7 @@ using ClapMainThreadCallbackRequest = clap::ext::gui::host::RequestShow, clap::ext::gui::host::RequestHide, clap::ext::gui::host::Closed, + clap::ext::note_name::host::Changed, clap::ext::note_ports::host::SupportedDialects, clap::ext::note_ports::host::Rescan, clap::ext::params::host::Rescan, diff --git a/src/common/serialization/clap/host.cpp b/src/common/serialization/clap/host.cpp index 6ed64b39..a36dbcb6 100644 --- a/src/common/serialization/clap/host.cpp +++ b/src/common/serialization/clap/host.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -37,13 +38,14 @@ Host::Host(const clap_host_t& original) url(original.url ? std::optional(original.url) : std::nullopt), version((assert(original.version), original.version)) {} -std::array, 10> SupportedHostExtensions::list() +std::array, 11> SupportedHostExtensions::list() const noexcept { return {std::pair(supports_audio_ports, CLAP_EXT_AUDIO_PORTS), std::pair(supports_audio_ports_config, CLAP_EXT_AUDIO_PORTS_CONFIG), std::pair(supports_gui, CLAP_EXT_GUI), std::pair(supports_latency, CLAP_EXT_LATENCY), std::pair(supports_log, CLAP_EXT_LOG), + std::pair(supports_note_name, CLAP_EXT_NOTE_NAME), std::pair(supports_note_ports, CLAP_EXT_NOTE_PORTS), std::pair(supports_params, CLAP_EXT_PARAMS), std::pair(supports_state, CLAP_EXT_STATE), diff --git a/src/common/serialization/clap/host.h b/src/common/serialization/clap/host.h index 8b42419d..a613e37f 100644 --- a/src/common/serialization/clap/host.h +++ b/src/common/serialization/clap/host.h @@ -86,6 +86,7 @@ struct SupportedHostExtensions { bool supports_gui = false; bool supports_latency = false; bool supports_log = false; + bool supports_note_name = false; bool supports_note_ports = false; bool supports_params = false; bool supports_state = false; @@ -96,7 +97,7 @@ struct SupportedHostExtensions { * Get a list of `` tuples for the supported * extensions. Used during logging. */ - std::array, 10> list() const noexcept; + std::array, 11> list() const noexcept; template void serialize(S& s) { @@ -105,6 +106,7 @@ struct SupportedHostExtensions { s.value1b(supports_gui); s.value1b(supports_latency); s.value1b(supports_log); + s.value1b(supports_note_name); s.value1b(supports_note_ports); s.value1b(supports_params); s.value1b(supports_state); diff --git a/src/plugin/bridges/clap-impls/plugin-proxy.cpp b/src/plugin/bridges/clap-impls/plugin-proxy.cpp index 47d972c1..90228034 100644 --- a/src/plugin/bridges/clap-impls/plugin-proxy.cpp +++ b/src/plugin/bridges/clap-impls/plugin-proxy.cpp @@ -29,6 +29,8 @@ ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept host.get_extension(&host, CLAP_EXT_LATENCY))), log(static_cast( host.get_extension(&host, CLAP_EXT_LOG))), + note_name(static_cast( + host.get_extension(&host, CLAP_EXT_NOTE_NAME))), note_ports(static_cast( host.get_extension(&host, CLAP_EXT_NOTE_PORTS))), params(static_cast( @@ -50,6 +52,7 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported() .supports_gui = gui != nullptr, .supports_latency = latency != nullptr, .supports_log = log != nullptr, + .supports_note_name = note_name != nullptr, .supports_note_ports = note_ports != nullptr, .supports_params = params != nullptr, .supports_state = state != nullptr, diff --git a/src/plugin/bridges/clap-impls/plugin-proxy.h b/src/plugin/bridges/clap-impls/plugin-proxy.h index ac696d22..e7819120 100644 --- a/src/plugin/bridges/clap-impls/plugin-proxy.h +++ b/src/plugin/bridges/clap-impls/plugin-proxy.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ struct ClapHostExtensions { const clap_host_gui_t* gui = nullptr; const clap_host_latency_t* latency = nullptr; const clap_host_log_t* log = nullptr; + const clap_host_note_name_t* note_name = nullptr; const clap_host_note_ports_t* note_ports = nullptr; const clap_host_params_t* params = nullptr; const clap_host_state_t* state = nullptr; diff --git a/src/plugin/bridges/clap.cpp b/src/plugin/bridges/clap.cpp index 7bf0bfe1..b49fa1d2 100644 --- a/src/plugin/bridges/clap.cpp +++ b/src/plugin/bridges/clap.cpp @@ -196,6 +196,22 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path) return Ack{}; }, + [&](const clap::ext::note_name::host::Changed& request) + -> clap::ext::note_name::host::Changed::Response { + const auto& [plugin_proxy, _] = + get_proxy(request.owner_instance_id); + + plugin_proxy + .run_on_main_thread( + [&, host = plugin_proxy.host_, + note_name = + plugin_proxy.host_extensions_.note_name]() { + note_name->changed(host); + }) + .wait(); + + return Ack{}; + }, [&](const clap::ext::note_ports::host::SupportedDialects& request) -> clap::ext::note_ports::host::SupportedDialects:: diff --git a/src/wine-host/bridges/clap-impls/host-proxy.cpp b/src/wine-host/bridges/clap-impls/host-proxy.cpp index 56cf85c0..fbdec048 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.cpp +++ b/src/wine-host/bridges/clap-impls/host-proxy.cpp @@ -69,6 +69,9 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge, ext_log_vtable(clap_host_log_t{ .log = ext_log_log, }), + ext_note_name_vtable(clap_host_note_name_t{ + .changed = ext_note_name_changed, + }), ext_note_ports_vtable(clap_host_note_ports_t{ .supported_dialects = ext_note_ports_supported_dialects, .rescan = ext_note_ports_rescan, @@ -116,6 +119,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host, // supports it, or we'll print the message if it doesn't. That allows us // to filter misbehavior messages. extension_ptr = &self->ext_log_vtable; + } else if (self->supported_extensions_.supports_note_name && + strcmp(extension_id, CLAP_EXT_NOTE_NAME) == 0) { + extension_ptr = &self->ext_note_name_vtable; } else if (self->supported_extensions_.supports_note_ports && strcmp(extension_id, CLAP_EXT_NOTE_PORTS) == 0) { extension_ptr = &self->ext_note_ports_vtable; @@ -363,6 +369,15 @@ void CLAP_ABI clap_host_proxy::ext_log_log(const clap_host_t* host, } } +void CLAP_ABI clap_host_proxy::ext_note_name_changed(const clap_host_t* host) { + assert(host && host->host_data); + auto self = static_cast(host->host_data); + + self->bridge_.send_mutually_recursive_main_thread_message( + clap::ext::note_name::host::Changed{.owner_instance_id = + self->owner_instance_id()}); +} + uint32_t CLAP_ABI clap_host_proxy::ext_note_ports_supported_dialects(const clap_host_t* host) { assert(host && host->host_data); diff --git a/src/wine-host/bridges/clap-impls/host-proxy.h b/src/wine-host/bridges/clap-impls/host-proxy.h index 78937ff0..58290929 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.h +++ b/src/wine-host/bridges/clap-impls/host-proxy.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,8 @@ class clap_host_proxy { clap_log_severity severity, const char* msg); + static void CLAP_ABI ext_note_name_changed(const clap_host_t* host); + static uint32_t CLAP_ABI ext_note_ports_supported_dialects(const clap_host_t* host); static void CLAP_ABI ext_note_ports_rescan(const clap_host_t* host, @@ -150,6 +153,7 @@ class clap_host_proxy { // can filter out plugin/host misbehavior messages on lower yabridge // verbosity levels. const clap_host_log_t ext_log_vtable; + const clap_host_note_name_t ext_note_name_vtable; const clap_host_note_ports_t ext_note_ports_vtable; const clap_host_params_t ext_params_vtable; const clap_host_state_t ext_state_vtable;