From ec8028f78c32bebdb7a360564c3d58958e0cd7b0 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 31 Aug 2022 16:28:36 +0200 Subject: [PATCH] Allow serializing CLAP plugin factory list message --- src/common/logging/clap.cpp | 25 ++++++++++++++----- src/common/logging/clap.h | 10 +++----- src/common/serialization/clap.h | 19 +++++++------- .../serialization/clap/plugin-factory.h | 18 ++++++++----- src/wine-host/bridges/clap.cpp | 25 +++++++++++-------- 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/common/logging/clap.cpp b/src/common/logging/clap.cpp index e9166646..07df7f6f 100644 --- a/src/common/logging/clap.cpp +++ b/src/common/logging/clap.cpp @@ -22,12 +22,12 @@ ClapLogger::ClapLogger(Logger& generic_logger) : logger_(generic_logger) {} -// bool ClapLogger::log_request(bool is_host_plugin, -// const ClapPluginFactoryProxy::Construct&) { -// return log_request_base(is_host_plugin, [&](auto& message) { -// message << "GetPluginFactory()"; -// }); -// } +bool ClapLogger::log_request(bool is_host_plugin, + const clap::plugin_factory::List&) { + return log_request_base(is_host_plugin, [&](auto& message) { + message << "clap_plugin_factory::list()"; + }); +} bool ClapLogger::log_request(bool is_host_plugin, const WantsConfiguration&) { return log_request_base(is_host_plugin, [&](auto& message) { @@ -40,6 +40,19 @@ bool ClapLogger::log_request(bool is_host_plugin, const WantsConfiguration&) { // }); // } +bool ClapLogger::log_response( + bool is_host_plugin, + const clap::plugin_factory::ListResponse& response) { + return log_request_base(is_host_plugin, [&](auto& message) { + if (response.descriptors) { + message << "size() << " plugin descriptors>"; + } else { + message << ""; + } + }); +} + void ClapLogger::log_response(bool is_host_plugin, const Configuration&) { log_response_base(is_host_plugin, [&](auto& message) { message << ""; }); diff --git a/src/common/logging/clap.h b/src/common/logging/clap.h index 9c654ff5..bd1903e2 100644 --- a/src/common/logging/clap.h +++ b/src/common/logging/clap.h @@ -45,9 +45,7 @@ class ClapLogger { // `log_request()` call returned `true`. This way we can filter out the // log message for the response together with the request. - // TODO: Main thread rquests - // bool log_request(bool is_host_plugin, - // const ClapPluginFactoryProxy::Construct&); + bool log_request(bool is_host_plugin, const clap::plugin_factory::List&); // TODO: Audio thread requests // bool log_request(bool is_host_plugin, @@ -55,11 +53,9 @@ class ClapLogger { bool log_request(bool is_host_plugin, const WantsConfiguration&); - // TOOD: Main thread responses // void log_response(bool is_host_plugin, const Ack&); - // void log_response(bool is_host_plugin, - // const UniversalTResult&, - // bool from_cache = false); + bool log_response(bool is_host_plugin, + const clap::plugin_factory::ListResponse&); // TODO: Audio thread responses // void log_response(bool is_host_plugin, diff --git a/src/common/serialization/clap.h b/src/common/serialization/clap.h index 6a2a9dbf..8cf67596 100644 --- a/src/common/serialization/clap.h +++ b/src/common/serialization/clap.h @@ -36,8 +36,10 @@ * request of type `ClapControlRequest(T)` should send back a `T::Response`. * These messages are for main thread functions. */ -// TODO: Remove placeholder, add actual types -using ClapMainThreadControlRequest = std::variant; +// FIXME: Remove the `WantsConfiguration`. For some reason bitsery just won't +// serialize this without it. +using ClapMainThreadControlRequest = + std::variant; template void serialize(S& s, ClapMainThreadControlRequest& payload) { @@ -117,13 +119,12 @@ struct ClapAudioThreadControlRequest { // TODO: Placeholder using ClapMainThreadCallbackRequest = std::variant; -// TODO: Uncomment after changing `ClapMainThreadCallbackRequest` -// template -// void serialize(S& s, ClapMainThreadCallbackRequest& payload) { -// // All of the objects in `ClapMainThreadCallbackRequest` should have their own -// // serialization function. -// s.ext(payload, bitsery::ext::InPlaceVariant{}); -// } +template +void serialize(S& s, ClapMainThreadCallbackRequest& payload) { + // All of the objects in `ClapMainThreadCallbackRequest` should have their + // own serialization function. + s.ext(payload, bitsery::ext::InPlaceVariant{}); +} /** * Fetch the `std::variant<>` from an audio thread request object. This will diff --git a/src/common/serialization/clap/plugin-factory.h b/src/common/serialization/clap/plugin-factory.h index 5bde4ec1..b5dcd7f9 100644 --- a/src/common/serialization/clap/plugin-factory.h +++ b/src/common/serialization/clap/plugin-factory.h @@ -26,21 +26,27 @@ namespace plugin_factory { /** * The response to the `clap::plugin_factory::list` message defined below. */ -struct list_response { - std::vector descriptors; +struct ListResponse { + /** + * The descriptors for the plugins in the factory. This will be a nullopt if + * the plugin does not support the plugin factory. + */ + std::optional> descriptors; template void serialize(S& s) { - s.container(descriptors, 8192); + s.ext(descriptors, bitsery::ext::InPlaceOptional{}, + [](S& s, auto& v) { s.container(v, 8192); }); } }; /** * Message combining `clap_plugin_factory::count()` with - * `clap_plugin_factory::get()` to get all plugin descriptors in one go. + * `clap_plugin_factory::get()` to get all plugin descriptors in one go. Will + * return a nullopt if the plugin does not support the plugin factory. */ -struct list { - using Response = list_response; +struct List { + using Response = ListResponse; // Since we send this to a specific CLAP plugin library, there are no // parameters here diff --git a/src/wine-host/bridges/clap.cpp b/src/wine-host/bridges/clap.cpp index 8e7183a2..9c6cf0e7 100644 --- a/src/wine-host/bridges/clap.cpp +++ b/src/wine-host/bridges/clap.cpp @@ -70,16 +70,21 @@ bool ClapBridge::inhibits_event_loop() noexcept { void ClapBridge::run() { set_realtime_priority(true); - // TODO: Listen on the socket - // sockets_.host_plugin_control_.receive_messages( - // std::nullopt, - // overload{ - // [&](const ClapPluginFactoryProxy::Construct&) - // -> ClapPluginFactoryProxy::Construct::Response { - // return ClapPluginFactoryProxy::ConstructArgs( - // module_->getFactory().get()); - // }, - // }); + sockets_.host_plugin_main_thread_control_.receive_messages( + std::nullopt, + overload{ + [&](const WantsConfiguration&) -> WantsConfiguration::Response { + // FIXME: This overload shouldn't be here, but + // bitsery simply won't allow us to serialize the + // variant without it. + return {}; + }, + [&](const clap::plugin_factory::List&) + -> clap::plugin_factory::List::Response { + // FIXME: Actually load this + return clap::plugin_factory::ListResponse{}; + }, + }); } // TODO: Implement this