mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Add restart and process request callbacks
This commit is contained in:
@@ -118,6 +118,22 @@ bool ClapLogger::log_request(bool is_host_plugin, const WantsConfiguration&) {
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin,
|
||||
const clap::host::RequestRestart& request) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << request.owner_instance_id
|
||||
<< ": clap_host::request_restart()";
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin,
|
||||
const clap::host::RequestProcess& request) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << request.owner_instance_id
|
||||
<< ": clap_host::request_process()";
|
||||
});
|
||||
}
|
||||
|
||||
void ClapLogger::log_response(bool is_host_plugin, const Ack&) {
|
||||
log_response_base(is_host_plugin, [&](auto& message) { message << "ACK"; });
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ class ClapLogger {
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::Reset&);
|
||||
|
||||
bool log_request(bool is_host_plugin, const WantsConfiguration&);
|
||||
bool log_request(bool is_host_plugin, const clap::host::RequestRestart&);
|
||||
bool log_request(bool is_host_plugin, const clap::host::RequestProcess&);
|
||||
|
||||
void log_response(bool is_host_plugin, const Ack&);
|
||||
void log_response(bool is_host_plugin,
|
||||
|
||||
@@ -124,7 +124,9 @@ struct ClapAudioThreadControlRequest {
|
||||
* type `ClapMainThreadCallbackRequest(T)` should send back a `T::Response`.
|
||||
*/
|
||||
// TODO: Placeholder
|
||||
using ClapMainThreadCallbackRequest = std::variant<WantsConfiguration>;
|
||||
using ClapMainThreadCallbackRequest = std::variant<WantsConfiguration,
|
||||
clap::host::RequestRestart,
|
||||
clap::host::RequestProcess>;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, ClapMainThreadCallbackRequest& payload) {
|
||||
|
||||
@@ -22,7 +22,8 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
size_t instance_id,
|
||||
clap::plugin::Descriptor descriptor,
|
||||
const clap_host_t* host)
|
||||
: bridge_(bridge),
|
||||
: host_(host),
|
||||
bridge_(bridge),
|
||||
instance_id_(instance_id),
|
||||
descriptor_(std::move(descriptor)),
|
||||
plugin_vtable_(clap_plugin_t{
|
||||
@@ -39,7 +40,6 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
.get_extension = plugin_get_extension,
|
||||
.on_main_thread = plugin_on_main_thread,
|
||||
}),
|
||||
host_(host),
|
||||
// These function objects are relatively large, and we probably won't be
|
||||
// getting that many of them
|
||||
pending_callbacks_(128) {}
|
||||
|
||||
@@ -121,6 +121,12 @@ class clap_plugin_proxy {
|
||||
return response_future;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `clap_host_t*` passed when creating the instance. Any callbacks made
|
||||
* by the proxied plugin instance must go through ere.
|
||||
*/
|
||||
const clap_host_t* host_;
|
||||
|
||||
private:
|
||||
ClapPluginBridge& bridge_;
|
||||
size_t instance_id_;
|
||||
@@ -140,12 +146,6 @@ class clap_plugin_proxy {
|
||||
*/
|
||||
clap::plugin::SupportedPluginExtensions supported_extensions_;
|
||||
|
||||
/**
|
||||
* The `clap_host_t*` passed when creating the instance. Any callbacks made
|
||||
* by the proxied plugin instance must go through ere.
|
||||
*/
|
||||
const clap_host_t* host_;
|
||||
|
||||
/**
|
||||
* Pending callbacks that must be sent to the host on the main thread. If a
|
||||
* socket needs to make a main thread function call, it will
|
||||
|
||||
@@ -46,7 +46,6 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
set_realtime_priority(true);
|
||||
pthread_setname_np(pthread_self(), "host-callbacks");
|
||||
|
||||
// TODO: Add the rest of the callbacks
|
||||
sockets_.plugin_host_main_thread_callback_.receive_messages(
|
||||
std::pair<ClapLogger&, bool>(logger_, false),
|
||||
overload{
|
||||
@@ -56,6 +55,32 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return config_;
|
||||
},
|
||||
[&](const clap::host::RequestRestart& request)
|
||||
-> clap::host::RequestRestart::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread([host = plugin_proxy.host_]() {
|
||||
host->request_restart(host);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::host::RequestProcess& request)
|
||||
-> clap::host::RequestProcess::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread([host = plugin_proxy.host_]() {
|
||||
host->request_process(host);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "host-proxy.h"
|
||||
|
||||
#include "../../../common/serialization/clap/version.h"
|
||||
#include "../clap.h"
|
||||
|
||||
clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
size_t owner_instance_id,
|
||||
@@ -46,12 +47,20 @@ clap_host_proxy::host_get_extension(const struct clap_host* host,
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::host_request_restart(const struct clap_host* host) {
|
||||
// TODO: Implement
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::host::RequestRestart{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::host_request_process(const struct clap_host* host) {
|
||||
// TODO: Implement
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::host::RequestProcess{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
|
||||
Reference in New Issue
Block a user