mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-17 06:00:03 +02:00
Inherit Vst3PluginBridge init from PluginBridge
This commit is contained in:
@@ -25,8 +25,9 @@
|
|||||||
#include "../host-process.h"
|
#include "../host-process.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles all common operations for hosting plugins such as setting up the
|
* Handles all common operations for hosting plugins such as initializing up the
|
||||||
* plugin host process, the logger, and logging debug information on startup.
|
* plugin host process, setting up the logger, and logging debug information on
|
||||||
|
* startup.
|
||||||
*
|
*
|
||||||
* @tparam Sockets the `Sockets` implementation to use. We have to initialize it
|
* @tparam Sockets the `Sockets` implementation to use. We have to initialize it
|
||||||
* here because we need to pass it to our `HostProcess`.
|
* here because we need to pass it to our `HostProcess`.
|
||||||
@@ -46,6 +47,12 @@ class PluginBridge {
|
|||||||
* @param create_socket_instance A function to create a socket instance.
|
* @param create_socket_instance A function to create a socket instance.
|
||||||
* Using a lambda here feels wrong, but I can't think of a better
|
* Using a lambda here feels wrong, but I can't think of a better
|
||||||
* solution right now.
|
* solution right now.
|
||||||
|
*
|
||||||
|
* @tparam F A `TSockets(boost::asio::io_context&)` function to create the
|
||||||
|
* `TSockets` instance.
|
||||||
|
*
|
||||||
|
* @throw std::runtime_error Thrown when the Wine plugin host could not be
|
||||||
|
* found, or if it could not locate and load a VST3 module.
|
||||||
*/
|
*/
|
||||||
template <typename F>
|
template <typename F>
|
||||||
PluginBridge(PluginType plugin_type,
|
PluginBridge(PluginType plugin_type,
|
||||||
@@ -55,6 +62,8 @@ class PluginBridge {
|
|||||||
plugin_path(plugin_path),
|
plugin_path(plugin_path),
|
||||||
io_context(),
|
io_context(),
|
||||||
sockets(create_socket_instance(io_context)),
|
sockets(create_socket_instance(io_context)),
|
||||||
|
// This is still correct for VST3 plugins because we can configure an
|
||||||
|
// entire directory (the module's bundle) at once
|
||||||
config(load_config_for(get_this_file_location())),
|
config(load_config_for(get_this_file_location())),
|
||||||
generic_logger(Logger::create_from_environment(
|
generic_logger(Logger::create_from_environment(
|
||||||
create_logger_prefix(sockets.base_dir))),
|
create_logger_prefix(sockets.base_dir))),
|
||||||
@@ -197,6 +206,16 @@ class PluginBridge {
|
|||||||
/**
|
/**
|
||||||
* The path to the plugin (`.dll` or module) being loaded in the Wine plugin
|
* The path to the plugin (`.dll` or module) being loaded in the Wine plugin
|
||||||
* host.
|
* host.
|
||||||
|
*
|
||||||
|
* Forst VST2 plugins this will be a `.dll` file. For VST3 plugins this is
|
||||||
|
* normally a directory called `MyPlugin.vst3` that contains
|
||||||
|
* `MyPlugin.vst3/Contents/x86-win/MyPlugin.vst3`, but there's also an older
|
||||||
|
* deprecated (but still ubiquitous) format where the top level
|
||||||
|
* `MyPlugin.vst3` is not a directory but a .dll file. This points to either
|
||||||
|
* of those things, and then `VST3::Hosting::Win32Module::create()` will be
|
||||||
|
* able to load it.
|
||||||
|
*
|
||||||
|
* https://developer.steinberg.help/pages/viewpage.action?pageId=9798275
|
||||||
*/
|
*/
|
||||||
const boost::filesystem::path plugin_path;
|
const boost::filesystem::path plugin_path;
|
||||||
|
|
||||||
|
|||||||
+15
-41
@@ -16,49 +16,23 @@
|
|||||||
|
|
||||||
#include "vst3.h"
|
#include "vst3.h"
|
||||||
|
|
||||||
#include "../../common/utils.h"
|
|
||||||
|
|
||||||
// TODO: Do all of the initialization stuff from `Vst2PluginBridge`
|
|
||||||
Vst3PluginBridge::Vst3PluginBridge()
|
Vst3PluginBridge::Vst3PluginBridge()
|
||||||
: // TODO: This is technically correct because we can configure the entire
|
: PluginBridge(PluginType::vst3,
|
||||||
// directory at once
|
// TODO: This is incorrect for VST3 modules
|
||||||
config(load_config_for(get_this_file_location())),
|
find_vst_plugin(),
|
||||||
// TODO: This is incorrect for VST3 modules
|
[](boost::asio::io_context& io_context) {
|
||||||
plugin_module_path(find_vst_plugin()),
|
return Vst3Sockets<std::jthread>(
|
||||||
io_context(),
|
io_context,
|
||||||
sockets(io_context,
|
generate_endpoint_base(find_vst_plugin()
|
||||||
// TODO: This is incorrect
|
.filename()
|
||||||
generate_endpoint_base(
|
.replace_extension("")
|
||||||
plugin_module_path.filename().replace_extension("").string()),
|
.string()),
|
||||||
true),
|
true);
|
||||||
// This weird cast is not needed, but without it clang/ccls won't shut up
|
}),
|
||||||
// TODO: Apparently this is UB even though it works fine, so we should
|
// TODO: This is UB, use composition with `generic_logger` instead
|
||||||
// probably just use composition here instead
|
|
||||||
logger(static_cast<Vst3Logger&&>(Logger::create_from_environment(
|
logger(static_cast<Vst3Logger&&>(Logger::create_from_environment(
|
||||||
create_logger_prefix(sockets.base_dir)))),
|
create_logger_prefix(sockets.base_dir)))) {
|
||||||
wine_version(get_wine_version()),
|
|
||||||
vst_host(
|
|
||||||
config.group
|
|
||||||
? std::unique_ptr<HostProcess>(std::make_unique<GroupHost>(
|
|
||||||
io_context,
|
|
||||||
logger,
|
|
||||||
HostRequest{.plugin_type = PluginType::vst2,
|
|
||||||
.plugin_path = plugin_module_path.string(),
|
|
||||||
.endpoint_base_dir = sockets.base_dir.string()},
|
|
||||||
sockets,
|
|
||||||
*config.group))
|
|
||||||
: std::unique_ptr<HostProcess>(std::make_unique<IndividualHost>(
|
|
||||||
io_context,
|
|
||||||
logger,
|
|
||||||
HostRequest{
|
|
||||||
.plugin_type = PluginType::vst2,
|
|
||||||
.plugin_path = plugin_module_path.string(),
|
|
||||||
.endpoint_base_dir = sockets.base_dir.string()}))),
|
|
||||||
has_realtime_priority(set_realtime_priority()),
|
|
||||||
wine_io_handler([&]() { io_context.run(); }) {
|
|
||||||
log_init_message();
|
log_init_message();
|
||||||
}
|
|
||||||
|
|
||||||
void Vst3PluginBridge::log_init_message() {
|
// TODO: Call the host guard handler
|
||||||
// TODO: Move `Vst2PluginBridge::log_init_message()` to utils and call that
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/asio/io_context.hpp>
|
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "../../common/communication/vst3.h"
|
#include "../../common/communication/vst3.h"
|
||||||
#include "../../common/configuration.h"
|
|
||||||
#include "../../common/logging/vst3.h"
|
#include "../../common/logging/vst3.h"
|
||||||
#include "../host-process.h"
|
#include "common.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This handles the communication between the native host and a VST3 plugin
|
* This handles the communication between the native host and a VST3 plugin
|
||||||
@@ -42,10 +39,8 @@
|
|||||||
* The naming scheme of all of these 'bridge' classes is `<type>{,Plugin}Bridge`
|
* The naming scheme of all of these 'bridge' classes is `<type>{,Plugin}Bridge`
|
||||||
* for greppability reasons. The `Plugin` infix is added on the native plugin
|
* for greppability reasons. The `Plugin` infix is added on the native plugin
|
||||||
* side.
|
* side.
|
||||||
*
|
|
||||||
* TODO: Also inherit this from PluginBridge
|
|
||||||
*/
|
*/
|
||||||
class Vst3PluginBridge {
|
class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initializes the VST3 module by starting and setting up communicating with
|
* Initializes the VST3 module by starting and setting up communicating with
|
||||||
@@ -56,74 +51,10 @@ class Vst3PluginBridge {
|
|||||||
*/
|
*/
|
||||||
Vst3PluginBridge();
|
Vst3PluginBridge();
|
||||||
|
|
||||||
/**
|
|
||||||
* The configuration for this instance of yabridge. Set based on the values
|
|
||||||
* from a `yabridge.toml`, if it exists.
|
|
||||||
*
|
|
||||||
* @see ../utils.h:load_config_for
|
|
||||||
*/
|
|
||||||
Configuration config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The path to the VST3 module being loaded in the Wine VST host. This is
|
|
||||||
* normally a directory called `MyPlugin.vst3` that contains
|
|
||||||
* `MyPlugin.vst3/Contents/x86-win/MyPlugin.vst3`, but there's also an older
|
|
||||||
* deprecated (but still ubiquitous) format where the top level
|
|
||||||
* `MyPlugin.vst3` is not a directory but a .dll file. This points to either
|
|
||||||
* of those things, and then `VST3::Hosting::Win32Module::create()` will be
|
|
||||||
* able to load it.
|
|
||||||
*
|
|
||||||
* https://developer.steinberg.help/pages/viewpage.action?pageId=9798275
|
|
||||||
*/
|
|
||||||
const boost::filesystem::path plugin_module_path;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Format and log all relevant debug information during initialization.
|
|
||||||
*/
|
|
||||||
void log_init_message();
|
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
|
||||||
Vst3Sockets<std::jthread> sockets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logging facility used for this instance of yabridge. Wraps around
|
* The logging facility used for this instance of yabridge. Wraps around
|
||||||
* `PluginBridge::generic_logger`.
|
* `PluginBridge::generic_logger`.
|
||||||
*/
|
*/
|
||||||
Vst3Logger logger;
|
Vst3Logger logger;
|
||||||
|
|
||||||
/**
|
|
||||||
* The version of Wine currently in use. Used in the debug output on plugin
|
|
||||||
* startup.
|
|
||||||
*/
|
|
||||||
const std::string wine_version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Wine process hosting the Windows VST3 plugin.
|
|
||||||
*
|
|
||||||
* @see launch_vst_host
|
|
||||||
*/
|
|
||||||
std::unique_ptr<HostProcess> vst_host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A thread used during the initialisation process to terminate listening on
|
|
||||||
* the sockets if the Wine process cannot start for whatever reason. This
|
|
||||||
* has to be defined here instead of in the constructor we can't simply
|
|
||||||
* detach the thread as it has to check whether the Wine plugin host is
|
|
||||||
* still running.
|
|
||||||
*/
|
|
||||||
std::jthread host_guard_handler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this process runs with realtime priority. We'll set this _after_
|
|
||||||
* spawning the Wine process because from my testing running wineserver with
|
|
||||||
* realtime priority can actually increase latency.
|
|
||||||
*/
|
|
||||||
bool has_realtime_priority;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the Boost.Asio `io_context` thread for logging the Wine process
|
|
||||||
* STDOUT and STDERR messages.
|
|
||||||
*/
|
|
||||||
std::jthread wine_io_handler;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user