diff --git a/src/common/communication/clap.h b/src/common/communication/clap.h index eb0679eb..053bde60 100644 --- a/src/common/communication/clap.h +++ b/src/common/communication/clap.h @@ -328,6 +328,28 @@ class ClapSockets final : public Sockets { request_ref, response_ref, request_ref.get().instance_id, logging); } + /** + * Send a message from the Wine plugin host to the native plugin to handle + * an audio thread callback. Since those functions are called from a hot + * loop we want every instance to have a dedicated socket and thread for + * handling those. These calls also always reuse buffers to minimize + * allocations. + * + * @tparam T Some object in the `ClapAudioThreadCallbackRequest` variant. + * All of these objects need to have an `owner_instance_id` field. + */ + template + typename T::Response send_audio_thread_callback_message( + const T& object, + std::optional> logging) { + typename T::Response response_object; + thread_local SerializationBuffer<256> audio_thread_buffer{}; + + return audio_thread_sockets_.at(object.owner_instance_id) + .callback_.receive_into(object, response_object, logging, + audio_thread_buffer); + } + /** * For sending messages from the host to the plugin. After we have a better * idea of what our communication model looks like we'll probably want to diff --git a/src/wine-host/bridges/clap.h b/src/wine-host/bridges/clap.h index ed55db75..66bfaf23 100644 --- a/src/wine-host/bridges/clap.h +++ b/src/wine-host/bridges/clap.h @@ -246,6 +246,17 @@ class ClapBridge : public HostBridge { object, std::nullopt); } + /** + * Send a callback message to the host from 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) { + return sockets_.send_audio_thread_callback_message( + object, std::pair(logger_, true)); + } + /** * When called from the GUI thread, spawn a new thread and call * `send_message()` from there, and then handle functions passed by calls to