diff --git a/src/common/communication/clap.h b/src/common/communication/clap.h index 589deae3..a3cebced 100644 --- a/src/common/communication/clap.h +++ b/src/common/communication/clap.h @@ -295,8 +295,9 @@ class ClapSockets final : public Sockets { const T& object, std::optional> logging) { typename T::Response response_object; - return receive_audio_thread_control_message_into( - object, response_object, object.instance_id, logging); + return audio_thread_sockets_.at(object.instance_id) + .control_.receive_into(object, response_object, logging, + audio_thread_buffer()); } /** @@ -308,8 +309,9 @@ class ClapSockets final : public Sockets { const MessageReference& object_ref, std::optional> logging) { typename T::Response response_object; - return receive_audio_thread_control_message_into( - object_ref, response_object, object_ref.get().instance_id, logging); + return audio_thread_sockets_.at(object_ref.get().instance_id) + .control_.receive_into(object_ref, response_object, logging, + audio_thread_buffer()); } /** @@ -324,8 +326,9 @@ class ClapSockets final : public Sockets { const MessageReference& request_ref, typename T::Response& response_ref, std::optional> logging) { - return receive_audio_thread_control_message_into( - request_ref, response_ref, request_ref.get().instance_id, logging); + return audio_thread_sockets_.at(request_ref.get().instance_id) + .control_.receive_into(request_ref, response_ref, logging, + audio_thread_buffer()); } /** @@ -343,11 +346,9 @@ class ClapSockets final : public Sockets { const T& object, std::optional> logging) { typename T::Response response_object; - thread_local SerializationBuffer<2048> audio_thread_buffer{}; - return audio_thread_sockets_.at(object.owner_instance_id) .callback_.receive_into(object, response_object, logging, - audio_thread_buffer); + audio_thread_buffer()); } /** @@ -371,21 +372,14 @@ class ClapSockets final : public Sockets { private: /** - * The actual implementation for `send_audio_thread_message` and - * `receive_audio_thread_message_into`. Here we keep a thread local - * static variable for our buffers sending. + * Get the shared thread local serialization buffer for audio threads. This + * is defined here so the buffer can be shared regardless of which `T` is + * being sent. */ - template - typename T::Response& receive_audio_thread_control_message_into( - const T& object, - typename T::Response& response_object, - size_t instance_id, - std::optional> logging) { - thread_local SerializationBuffer<256> audio_thread_buffer{}; + SerializationBufferBase& audio_thread_buffer() { + thread_local SerializationBuffer<2048> audio_thread_buffer{}; - return audio_thread_sockets_.at(instance_id) - .control_.receive_into(object, response_object, logging, - audio_thread_buffer); + return audio_thread_buffer; } asio::io_context& io_context_; diff --git a/src/common/communication/vst3.h b/src/common/communication/vst3.h index abaa09ab..c9010e4d 100644 --- a/src/common/communication/vst3.h +++ b/src/common/communication/vst3.h @@ -197,8 +197,9 @@ class Vst3Sockets final : public Sockets { const T& object, std::optional> logging) { typename T::Response response_object; - return receive_audio_processor_message_into( - object, response_object, object.instance_id, logging); + return audio_processor_sockets_.at(object.instance_id) + .receive_into(object, response_object, logging, + audio_processor_buffer()); } /** @@ -210,8 +211,9 @@ class Vst3Sockets final : public Sockets { const MessageReference& object_ref, std::optional> logging) { typename T::Response response_object; - return receive_audio_processor_message_into( - object_ref, response_object, object_ref.get().instance_id, logging); + return audio_processor_sockets_.at(object_ref.get().instance_id) + .receive_into(object_ref, response_object, logging, + audio_processor_buffer()); } /** @@ -226,8 +228,9 @@ class Vst3Sockets final : public Sockets { const MessageReference& request_ref, typename T::Response& response_ref, std::optional> logging) { - return receive_audio_processor_message_into( - request_ref, response_ref, request_ref.get().instance_id, logging); + return audio_processor_sockets_.at(request_ref.get().instance_id) + .receive_into(request_ref, response_ref, logging, + audio_processor_buffer()); } /** @@ -253,21 +256,14 @@ class Vst3Sockets final : public Sockets { private: /** - * The actual implementation for `send_audio_processor_message` and - * `receive_audio_processor_message_into`. Here we keep a thread local - * static variable for our buffers sending. + * Get the shared thread local serialization buffer for audio processors. + * This is defined here so the buffer can be shared regardless of which `T` + * is being sent. */ - template - typename T::Response& receive_audio_processor_message_into( - const T& object, - typename T::Response& response_object, - size_t instance_id, - std::optional> logging) { + SerializationBufferBase& audio_processor_buffer() { thread_local SerializationBuffer<2048> audio_processor_buffer{}; - return audio_processor_sockets_.at(instance_id) - .receive_into(object, response_object, logging, - audio_processor_buffer); + return audio_processor_buffer; } asio::io_context& io_context_;