mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Add a general entry point to HostBridge
Since for all plugin types we would need to start listening for incoming events this way.
This commit is contained in:
@@ -25,6 +25,21 @@
|
|||||||
*/
|
*/
|
||||||
class HostBridge {
|
class HostBridge {
|
||||||
public:
|
public:
|
||||||
|
virtual ~HostBridge(){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle events until the plugin exits. The actual events are posted to
|
||||||
|
* `main_context` to ensure that all operations to could potentially
|
||||||
|
* interact with Win32 code are run from a single thread, even when hosting
|
||||||
|
* multiple plugins. The message loop should be run on a timer within the
|
||||||
|
* same IO context.
|
||||||
|
*
|
||||||
|
* @note Because of the reasons mentioned above, for this to work the plugin
|
||||||
|
* should be initialized within the same thread that calls
|
||||||
|
* `main_context.run()`.
|
||||||
|
*/
|
||||||
|
virtual void run() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle X11 events for the editor window if it is open. This can safely be
|
* Handle X11 events for the editor window if it is open. This can safely be
|
||||||
* run from any thread.
|
* run from any thread.
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ void GroupBridge::handle_plugin_dispatch(size_t plugin_id) {
|
|||||||
|
|
||||||
// Blocks this thread until the plugin shuts down, handling all events on
|
// Blocks this thread until the plugin shuts down, handling all events on
|
||||||
// the main IO context
|
// the main IO context
|
||||||
bridge->handle_dispatch();
|
bridge->run();
|
||||||
logger.log("'" + bridge->vst_plugin_path.string() + "' has exited");
|
logger.log("'" + bridge->vst_plugin_path.string() + "' has exited");
|
||||||
|
|
||||||
// After the plugin has exited we'll remove this thread's plugin from the
|
// After the plugin has exited we'll remove this thread's plugin from the
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ Vst2Bridge::Vst2Bridge(MainContext& main_context,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_dispatch() {
|
void Vst2Bridge::run() {
|
||||||
sockets.host_vst_dispatch.receive_events(
|
sockets.host_vst_dispatch.receive_events(
|
||||||
std::nullopt, [&](Event& event, bool /*on_main_thread*/) {
|
std::nullopt, [&](Event& event, bool /*on_main_thread*/) {
|
||||||
if (event.opcode == effProcessEvents) {
|
if (event.opcode == effProcessEvents) {
|
||||||
|
|||||||
@@ -62,18 +62,7 @@ class Vst2Bridge : public HostBridge {
|
|||||||
std::string plugin_dll_path,
|
std::string plugin_dll_path,
|
||||||
std::string endpoint_base_dir);
|
std::string endpoint_base_dir);
|
||||||
|
|
||||||
/**
|
void run() override;
|
||||||
* Handle events until the plugin exits. The actual events are posted to
|
|
||||||
* `main_context` to ensure that all operations to could potentially
|
|
||||||
* interact with Win32 code are run from a single thread, even when hosting
|
|
||||||
* multiple plugins. The message loop should be run on a timer within the
|
|
||||||
* same IO context.
|
|
||||||
*
|
|
||||||
* @note Because of the reasons mentioned above, for this to work the plugin
|
|
||||||
* should be initialized within the same thread that calls
|
|
||||||
* `main_context.run()`.
|
|
||||||
*/
|
|
||||||
void handle_dispatch();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward the host callback made by the plugin to the host and return the
|
* Forward the host callback made by the plugin to the host and return the
|
||||||
|
|||||||
@@ -76,25 +76,12 @@ main(int argc, char* argv[]) {
|
|||||||
// don't need to differentiate between individually hosted plugins and
|
// don't need to differentiate between individually hosted plugins and
|
||||||
// plugin groups when it comes to event handling.
|
// plugin groups when it comes to event handling.
|
||||||
MainContext main_context{};
|
MainContext main_context{};
|
||||||
Win32Thread worker_thread;
|
std::unique_ptr<HostBridge> bridge;
|
||||||
std::shared_ptr<HostBridge> bridge;
|
|
||||||
try {
|
try {
|
||||||
switch (plugin_type) {
|
switch (plugin_type) {
|
||||||
case PluginType::vst2:
|
case PluginType::vst2:
|
||||||
bridge = std::make_shared<Vst2Bridge>(
|
bridge = std::make_unique<Vst2Bridge>(
|
||||||
main_context, plugin_location, socket_endpoint_path);
|
main_context, plugin_location, socket_endpoint_path);
|
||||||
|
|
||||||
// We'll listen for `dispatcher()` calls on a different thread,
|
|
||||||
// but the actual events will still be executed within the IO
|
|
||||||
// context
|
|
||||||
worker_thread = Win32Thread([&]() {
|
|
||||||
std::static_pointer_cast<Vst2Bridge>(bridge)
|
|
||||||
->handle_dispatch();
|
|
||||||
|
|
||||||
// When the sockets get closed, this application should
|
|
||||||
// terminate gracefully
|
|
||||||
main_context.stop();
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case PluginType::vst3:
|
case PluginType::vst3:
|
||||||
std::cerr << "TODO: Not yet implemented" << std::endl;
|
std::cerr << "TODO: Not yet implemented" << std::endl;
|
||||||
@@ -114,6 +101,17 @@ main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let the plugin receive and handle its events on its own thread. Some
|
||||||
|
// potentially unsafe events that should always be run from the UI thread
|
||||||
|
// will be posted to `main_context`.
|
||||||
|
Win32Thread worker_thread([&]() {
|
||||||
|
bridge->run();
|
||||||
|
|
||||||
|
// When the sockets get closed, this application should
|
||||||
|
// terminate gracefully
|
||||||
|
main_context.stop();
|
||||||
|
});
|
||||||
|
|
||||||
std::cout << "Finished initializing '" << plugin_location << "'"
|
std::cout << "Finished initializing '" << plugin_location << "'"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user