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