mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Conditionally disiable the message loop from
Based on a function. This is needed because the message loop should be skipped while any of the plugins is opening their GUI, similar to how `EditorOpening` worked for individually hosted plugins.
This commit is contained in:
@@ -19,9 +19,6 @@
|
|||||||
#include <future>
|
#include <future>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "../../common/communication.h"
|
|
||||||
#include "../../common/events.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function pointer to what should be the entry point of a VST plugin.
|
* A function pointer to what should be the entry point of a VST plugin.
|
||||||
*/
|
*/
|
||||||
@@ -163,40 +160,6 @@ void Vst2Bridge::handle_dispatch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_dispatch(boost::asio::io_context& main_context) {
|
|
||||||
using namespace std::placeholders;
|
|
||||||
|
|
||||||
// This works exactly the same as the function above, but execute the actual
|
|
||||||
// event and run the message loop from the main thread that's also
|
|
||||||
// instantiating these plugins. This is required for a few plugins to run
|
|
||||||
// multiple instances in the same process
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
receive_event(
|
|
||||||
host_vst_dispatch, std::nullopt,
|
|
||||||
passthrough_event(
|
|
||||||
plugin,
|
|
||||||
[&](AEffect* plugin, int opcode, int index, intptr_t value,
|
|
||||||
void* data, float option) -> intptr_t {
|
|
||||||
std::promise<intptr_t> dispatch_result;
|
|
||||||
boost::asio::dispatch(main_context, [&]() {
|
|
||||||
const intptr_t result = dispatch_wrapper(
|
|
||||||
plugin, opcode, index, value, data, option);
|
|
||||||
|
|
||||||
dispatch_result.set_value(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
return dispatch_result.get_future().get();
|
|
||||||
}));
|
|
||||||
|
|
||||||
boost::asio::post(main_context, [&]() { pump_message_loop(); });
|
|
||||||
}
|
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// The plugin has cut off communications, so we can shut down this host
|
|
||||||
// application
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vst2Bridge::handle_dispatch_midi_events() {
|
void Vst2Bridge::handle_dispatch_midi_events() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -26,9 +26,13 @@
|
|||||||
#include <vestige/aeffectx.h>
|
#include <vestige/aeffectx.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <boost/asio/dispatch.hpp>
|
||||||
#include <boost/asio/local/stream_protocol.hpp>
|
#include <boost/asio/local/stream_protocol.hpp>
|
||||||
|
#include <future>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "../../common/communication.h"
|
||||||
|
#include "../../common/events.h"
|
||||||
#include "../../common/logging.h"
|
#include "../../common/logging.h"
|
||||||
#include "../editor.h"
|
#include "../editor.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
@@ -93,11 +97,49 @@ class Vst2Bridge {
|
|||||||
*
|
*
|
||||||
* @param main_context The main IO context that's handling the event
|
* @param main_context The main IO context that's handling the event
|
||||||
* handling for all plugins.
|
* handling for all plugins.
|
||||||
|
* @param message_loop_blocked A function that returns true if the message
|
||||||
|
* loop is blocked. This is used to temporarily postpone running the
|
||||||
|
* message loop while a plugin is opening its GUI.
|
||||||
*
|
*
|
||||||
* @note With this approach you'll have to make sure that the object was
|
* @note With this approach you'll have to make sure that the object was
|
||||||
* instantiated from the same thread as the one that runs the IO context.
|
* instantiated from the same thread as the one that runs the IO context.
|
||||||
*/
|
*/
|
||||||
void handle_dispatch(boost::asio::io_context& main_context);
|
template <typename F = bool()>
|
||||||
|
void handle_dispatch(boost::asio::io_context& main_context,
|
||||||
|
const F& message_loop_blocked) {
|
||||||
|
// This works exactly the same as the function above, but execute the
|
||||||
|
// actual event and run the message loop from the main thread that's
|
||||||
|
// also instantiating these plugins. This is required for a few plugins
|
||||||
|
// to run multiple instances in the same process
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
receive_event(
|
||||||
|
host_vst_dispatch, std::nullopt,
|
||||||
|
passthrough_event(
|
||||||
|
plugin,
|
||||||
|
[&](AEffect* plugin, int opcode, int index,
|
||||||
|
intptr_t value, void* data,
|
||||||
|
float option) -> intptr_t {
|
||||||
|
std::promise<intptr_t> dispatch_result;
|
||||||
|
boost::asio::dispatch(main_context, [&]() {
|
||||||
|
const intptr_t result = dispatch_wrapper(
|
||||||
|
plugin, opcode, index, value, data, option);
|
||||||
|
|
||||||
|
dispatch_result.set_value(result);
|
||||||
|
|
||||||
|
if (!message_loop_blocked()) {
|
||||||
|
pump_message_loop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return dispatch_result.get_future().get();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// The plugin has cut off communications, so we can shut down this
|
||||||
|
// host application
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// These functions are the entry points for the `*_handler` threads
|
// These functions are the entry points for the `*_handler` threads
|
||||||
// defined below. They're defined here because we can't use lambdas with
|
// defined below. They're defined here because we can't use lambdas with
|
||||||
|
|||||||
Reference in New Issue
Block a user