mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Add audio thread callbacks
This commit is contained in:
@@ -328,6 +328,28 @@ class ClapSockets final : public Sockets {
|
|||||||
request_ref, response_ref, request_ref.get().instance_id, logging);
|
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>
|
||||||
|
typename T::Response send_audio_thread_callback_message(
|
||||||
|
const T& object,
|
||||||
|
std::optional<std::pair<ClapLogger&, bool>> 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
|
* 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
|
* idea of what our communication model looks like we'll probably want to
|
||||||
|
|||||||
@@ -246,6 +246,17 @@ class ClapBridge : public HostBridge {
|
|||||||
object, std::nullopt);
|
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>
|
||||||
|
typename T::Response send_audio_thread_message(const T& object) {
|
||||||
|
return sockets_.send_audio_thread_callback_message(
|
||||||
|
object, std::pair<ClapLogger&, bool>(logger_, true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When called from the GUI thread, spawn a new thread and call
|
* When called from the GUI thread, spawn a new thread and call
|
||||||
* `send_message()` from there, and then handle functions passed by calls to
|
* `send_message()` from there, and then handle functions passed by calls to
|
||||||
|
|||||||
Reference in New Issue
Block a user