mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-06 19:40:10 +02:00
Rename EventHandler::{send,receive} to *_event(s?)
Since it does something way more involved than
`SocketHandler::{send,receive_multi}`, and that makes it a bit confusing
if you don't already know about that (and even if you do).
This commit is contained in:
@@ -110,13 +110,13 @@ as the _Windows VST plugin_. The whole process works as follows:
|
||||
TODO: Rewrite this after the socket changes are done
|
||||
|
||||
Actually sending and receiving the events happens in the
|
||||
`EventHandler::send()` and `EventHandler::receive()` functions. When calling
|
||||
either `dispatch()` or `audioMaster()`, the caller will oftentimes either
|
||||
pass along some kind of data structure through the void pointer function
|
||||
argument, or they expect the function's return value to be a pointer to some
|
||||
kind of struct provided by the plugin or host. The behaviour for reading from
|
||||
and writing into these void pointers and returning pointers to objects when
|
||||
needed is encapsulated in the `DispatchDataConverter` and
|
||||
`EventHandler::send_event()` and `EventHandler::receive_events()` functions.
|
||||
When calling either `dispatch()` or `audioMaster()`, the caller will
|
||||
oftentimes either pass along some kind of data structure through the void
|
||||
pointer function argument, or they expect the function's return value to be a
|
||||
pointer to some kind of struct provided by the plugin or host. The behaviour
|
||||
for reading from and writing into these void pointers and returning pointers
|
||||
to objects when needed is encapsulated in the `DispatchDataConverter` and
|
||||
`HostCallbackDataCovnerter` classes for the `dispatcher()` and
|
||||
`audioMaster()` functions respectively. For operations involving the plugin
|
||||
editor there is also some extra glue in `Vst2Bridge::dispatch_wrapper`. On
|
||||
|
||||
+29
-27
@@ -385,11 +385,11 @@ class DefaultDataConverter {
|
||||
* - Aside from that the listening side will have a second thread asynchronously
|
||||
* listening for new connections on the socket endpoint.
|
||||
*
|
||||
* The `EventHandler::send()` is used to send events. If the socket is currently
|
||||
* being written to, we'll first create a new socket connection as described
|
||||
* above. Similarly, the `EventHandler::receive()` method first sets up
|
||||
* asynchronous listeners for the socket endpoint, and then block and handle
|
||||
* events until the main socket is closed.
|
||||
* The `EventHandler::send_event()` method is used to send events. If the socket
|
||||
* is currently being written to, we'll first create a new socket connection as
|
||||
* described above. Similarly, the `EventHandler::receive_events()` method first
|
||||
* sets up asynchronous listeners for the socket endpoint, and then block and
|
||||
* handle events until the main socket is closed.
|
||||
*
|
||||
* @tparam Thread The thread implementation to use. On the Linux side this
|
||||
* should be `std::jthread` and on the Wine side this should be `Win32Thread`.
|
||||
@@ -435,8 +435,8 @@ class EventHandler {
|
||||
acceptor->accept(socket);
|
||||
|
||||
// As mentioned in `acceptor's` docstring, this acceptor will be
|
||||
// recreated in `receive()` on another context, and potentially on
|
||||
// the other side of the connection in the case of
|
||||
// recreated in `receive_events()` on another context, and
|
||||
// potentially on the other side of the connection in the case of
|
||||
// `vst_host_callback`
|
||||
acceptor.reset();
|
||||
boost::filesystem::remove(endpoint.path());
|
||||
@@ -477,17 +477,17 @@ class EventHandler {
|
||||
* this is for sending `dispatch()` events or host callbacks. Optional
|
||||
* since it doesn't have to be done on both sides.
|
||||
*
|
||||
* @relates EventHandler::receive
|
||||
* @relates EventHandler::receive_events
|
||||
* @relates passthrough_event
|
||||
*/
|
||||
template <typename D>
|
||||
intptr_t send(D& data_converter,
|
||||
std::optional<std::pair<Logger&, bool>> logging,
|
||||
int opcode,
|
||||
int index,
|
||||
intptr_t value,
|
||||
void* data,
|
||||
float option) {
|
||||
intptr_t send_event(D& data_converter,
|
||||
std::optional<std::pair<Logger&, bool>> logging,
|
||||
int opcode,
|
||||
int index,
|
||||
intptr_t value,
|
||||
void* data,
|
||||
float option) {
|
||||
// Encode the right payload types for this event. Check the
|
||||
// documentation for `EventPayload` for more information. These types
|
||||
// are converted to C-style data structures in `passthrough_event()` so
|
||||
@@ -584,11 +584,12 @@ class EventHandler {
|
||||
* The boolean flag is `true` when this event was received on the main
|
||||
* socket, and `false` otherwise.
|
||||
*
|
||||
* @relates EventHandler::send
|
||||
* @relates EventHandler::send_event
|
||||
* @relates passthrough_event
|
||||
*/
|
||||
template <typename F>
|
||||
void receive(std::optional<std::pair<Logger&, bool>> logging, F callback) {
|
||||
void receive_events(std::optional<std::pair<Logger&, bool>> logging,
|
||||
F callback) {
|
||||
// As described above we'll handle incoming requests for `socket` on
|
||||
// this thread. We'll also listen for incoming connections on `endpoint`
|
||||
// on another thread. For any incoming connection we'll spawn a new
|
||||
@@ -691,7 +692,7 @@ class EventHandler {
|
||||
|
||||
private:
|
||||
/**
|
||||
* Used in `receive()` to asynchronously listen for secondary socket
|
||||
* Used in `receive_events()` to asynchronously listen for secondary socket
|
||||
* connections. After `callback()` returns this function will continue to be
|
||||
* called until the IO context gets stopped.
|
||||
*
|
||||
@@ -735,9 +736,9 @@ class EventHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* The main IO context. New sockets created during `send()` will be bound to
|
||||
* this context. In `receive()` we'll create a new IO context since we want
|
||||
* to do all listening there on a dedicated thread.
|
||||
* The main IO context. New sockets created during `send_event()` will be
|
||||
* bound to this context. In `receive_events()` we'll create a new IO
|
||||
* context since we want to do all listening there on a dedicated thread.
|
||||
*/
|
||||
boost::asio::io_context& io_context;
|
||||
|
||||
@@ -746,8 +747,8 @@ class EventHandler {
|
||||
|
||||
/**
|
||||
* This acceptor will be used once synchronously on the listening side
|
||||
* during `Sockets::connect()`. When `EventHandler::receive()` is then
|
||||
* called, we'll recreate the acceptor to asynchronously listen for new
|
||||
* during `Sockets::connect()`. When `EventHandler::receive_events()` is
|
||||
* then called, we'll recreate the acceptor to asynchronously listen for new
|
||||
* incoming socket connections on `endpoint` using. This is important,
|
||||
* because on the case of `vst_host_callback` the acceptor is first accepts
|
||||
* an initial socket on the plugin side (like all sockets), but all
|
||||
@@ -928,8 +929,9 @@ boost::filesystem::path generate_endpoint_base(const std::string& plugin_name);
|
||||
*
|
||||
* This is the receiving analogue of the `*DataCovnerter` objects.
|
||||
*
|
||||
* TODO: Now that `EventHandler::receive` replaced `receive_event()`, refactor
|
||||
* this to just handle the event directly rather than returning a lambda
|
||||
* TODO: Now that `EventHandler::receive_events` replaced `receive_event()`,
|
||||
* refactor this to just handle the event directly rather than returning a
|
||||
* lambda
|
||||
*
|
||||
* @param plugin The `AEffect` instance that should be passed to the callback
|
||||
* function.
|
||||
@@ -940,9 +942,9 @@ boost::filesystem::path generate_endpoint_base(const std::string& plugin_name);
|
||||
* `audioMasterCallback`.
|
||||
*
|
||||
* @return A `EventResult(Event)` callback function that can be passed to
|
||||
* `EditorHandler::receive()`.
|
||||
* `EditorHandler::receive_events()`.
|
||||
*
|
||||
* @relates EditorHandler::receive
|
||||
* @relates EventHandler::receive_events
|
||||
*/
|
||||
template <typename F>
|
||||
auto passthrough_event(AEffect* plugin, F callback) {
|
||||
|
||||
@@ -121,7 +121,7 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
||||
// instead of asynchronous IO since communication has to be handled in
|
||||
// lockstep anyway
|
||||
host_callback_handler = std::jthread([&]() {
|
||||
sockets.vst_host_callback.receive(
|
||||
sockets.vst_host_callback.receive_events(
|
||||
std::pair<Logger&, bool>(logger, false),
|
||||
[&](Event& event, bool /*on_main_thread*/) {
|
||||
// MIDI events sent from the plugin back to the host are a
|
||||
@@ -424,7 +424,7 @@ intptr_t PluginBridge::dispatch(AEffect* /*plugin*/,
|
||||
intptr_t return_value = 0;
|
||||
try {
|
||||
// TODO: Add some kind of timeout?
|
||||
return_value = sockets.host_vst_dispatch.send(
|
||||
return_value = sockets.host_vst_dispatch.send_event(
|
||||
converter, std::pair<Logger&, bool>(logger, true), opcode,
|
||||
index, value, data, option);
|
||||
} catch (const boost::system::system_error& a) {
|
||||
@@ -449,7 +449,7 @@ intptr_t PluginBridge::dispatch(AEffect* /*plugin*/,
|
||||
// thread and socket to pass MIDI events. Otherwise plugins will
|
||||
// stop receiving MIDI data when they have an open dropdowns or
|
||||
// message box.
|
||||
return sockets.host_vst_dispatch_midi_events.send(
|
||||
return sockets.host_vst_dispatch_midi_events.send_event(
|
||||
converter, std::pair<Logger&, bool>(logger, true), opcode,
|
||||
index, value, data, option);
|
||||
break;
|
||||
@@ -485,7 +485,7 @@ intptr_t PluginBridge::dispatch(AEffect* /*plugin*/,
|
||||
// and loading plugin state it's much better to have bitsery or our
|
||||
// receiving function temporarily allocate a large enough buffer rather than
|
||||
// to have a bunch of allocated memory sitting around doing nothing.
|
||||
return sockets.host_vst_dispatch.send(
|
||||
return sockets.host_vst_dispatch.send_event(
|
||||
converter, std::pair<Logger&, bool>(logger, true), opcode, index, value,
|
||||
data, option);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ Vst2Bridge::Vst2Bridge(MainContext& main_context,
|
||||
// but this socket will only handle MIDI events and it will handle them
|
||||
// eagerly. This is needed because of Win32 API limitations.
|
||||
dispatch_midi_events_handler = Win32Thread([&]() {
|
||||
sockets.host_vst_dispatch_midi_events.receive(
|
||||
sockets.host_vst_dispatch_midi_events.receive_events(
|
||||
std::nullopt, [&](Event& event, bool /*on_main_thread*/) {
|
||||
if (BOOST_LIKELY(event.opcode == effProcessEvents)) {
|
||||
// For 99% of the plugins we can just call
|
||||
@@ -318,7 +318,7 @@ bool Vst2Bridge::should_skip_message_loop() const {
|
||||
}
|
||||
|
||||
void Vst2Bridge::handle_dispatch() {
|
||||
sockets.host_vst_dispatch.receive(
|
||||
sockets.host_vst_dispatch.receive_events(
|
||||
std::nullopt, [&](Event& event, bool /*on_main_thread*/) {
|
||||
// TODO: As per the TODO in `passthrough_event`, this can use a
|
||||
// round of refactoring now that we never use its returned
|
||||
@@ -534,8 +534,8 @@ intptr_t Vst2Bridge::host_callback(AEffect* effect,
|
||||
void* data,
|
||||
float option) {
|
||||
HostCallbackDataConverter converter(effect, time_info);
|
||||
return sockets.vst_host_callback.send(converter, std::nullopt, opcode,
|
||||
index, value, data, option);
|
||||
return sockets.vst_host_callback.send_event(converter, std::nullopt, opcode,
|
||||
index, value, data, option);
|
||||
}
|
||||
|
||||
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,
|
||||
|
||||
Reference in New Issue
Block a user