mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-08 12:30:12 +02:00
Rename PluginParameters to GroupReuqest
This commit is contained in:
@@ -109,6 +109,6 @@ AEffect& update_aeffect(AEffect& plugin, const AEffect& updated_plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
bool PluginParameters::operator==(const PluginParameters& rhs) const {
|
||||
bool GroupRequest::operator==(const GroupRequest& rhs) const {
|
||||
return plugin_path == rhs.plugin_path && socket_path == rhs.socket_path;
|
||||
}
|
||||
|
||||
@@ -577,11 +577,11 @@ struct AudioBuffers {
|
||||
* group process. These are the exact same options that would have been passed
|
||||
* to `yabridge-host.exe` were the plugin to be hosted individually.
|
||||
*/
|
||||
struct PluginParameters {
|
||||
struct GroupRequest {
|
||||
std::string plugin_path;
|
||||
std::string socket_path;
|
||||
|
||||
bool operator==(const PluginParameters& rhs) const;
|
||||
bool operator==(const GroupRequest& rhs) const;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
@@ -591,8 +591,8 @@ struct PluginParameters {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::hash<PluginParameters> {
|
||||
std::size_t operator()(PluginParameters const& params) const noexcept {
|
||||
struct std::hash<GroupRequest> {
|
||||
std::size_t operator()(GroupRequest const& params) const noexcept {
|
||||
std::hash<string> hasher{};
|
||||
|
||||
return hasher(params.plugin_path) ^ (hasher(params.socket_path) << 1);
|
||||
|
||||
@@ -49,6 +49,10 @@ PluginBridge& get_bridge_instance(const AEffect& plugin) {
|
||||
return *static_cast<PluginBridge*>(plugin.ptr3);
|
||||
}
|
||||
|
||||
// TODO: It would be nice to have a better way to encapsulate the small
|
||||
// differences in behavior when using plugin groups, i.e. everywhere where
|
||||
// we check for `config.group.has_value()`
|
||||
|
||||
PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
||||
: config(Configuration::load_for(get_this_file_location())),
|
||||
vst_plugin_path(find_vst_plugin()),
|
||||
|
||||
@@ -31,13 +31,17 @@ namespace fs = boost::filesystem;
|
||||
*/
|
||||
std::string create_logger_prefix(const fs::path& socket_path);
|
||||
|
||||
// CreateThread() is great and allows you to pass a single value to the
|
||||
// function, so we'll use this to pass both `this` and the parameters to the
|
||||
// below thread function so it can do its thing.
|
||||
using handle_host_plugin_parameters = std::pair<GroupBridge*, PluginParameters>;
|
||||
|
||||
uint32_t WINAPI handle_host_plugin_proxy(void* param);
|
||||
|
||||
/**
|
||||
* CreateThread() is great and allows you to pass a single value to the
|
||||
* function, so we'll use this to pass both `this` and the parameters to the
|
||||
* below thread function so it can do its thing.
|
||||
*
|
||||
* @relates handle_host_plugin_proxy
|
||||
*/
|
||||
using handle_host_plugin_parameters = std::pair<GroupBridge*, GroupRequest>;
|
||||
|
||||
StdIoCapture::StdIoCapture(boost::asio::io_context& io_context,
|
||||
int file_descriptor)
|
||||
: pipe(io_context),
|
||||
@@ -76,24 +80,23 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
|
||||
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
|
||||
}
|
||||
|
||||
void GroupBridge::handle_host_plugin(const PluginParameters parameters) {
|
||||
void GroupBridge::handle_host_plugin(const GroupRequest request) {
|
||||
// At this point the `active_plugins` map will already contain a copy of
|
||||
// `parameters` along with this thread's handle
|
||||
// The initialization process for a plugin is identical to that in
|
||||
// `../individual-host.cpp`
|
||||
logger.log("Received request to host '" + parameters.plugin_path +
|
||||
"' using socket '" + parameters.socket_path + "'");
|
||||
logger.log("Received request to host '" + request.plugin_path +
|
||||
"' using socket '" + request.socket_path + "'");
|
||||
try {
|
||||
Vst2Bridge bridge(parameters.plugin_path, parameters.socket_path);
|
||||
logger.log("Finished initializing '" + parameters.plugin_path + "'");
|
||||
Vst2Bridge bridge(request.plugin_path, request.socket_path);
|
||||
logger.log("Finished initializing '" + request.plugin_path + "'");
|
||||
|
||||
// Blocks the main thread until the plugin shuts down
|
||||
bridge.handle_dispatch();
|
||||
|
||||
logger.log("" + parameters.plugin_path + "' has exited");
|
||||
logger.log("" + request.plugin_path + "' has exited");
|
||||
} catch (const std::runtime_error& error) {
|
||||
logger.log("Error while initializing '" + parameters.plugin_path +
|
||||
"':");
|
||||
logger.log("Error while initializing '" + request.plugin_path + "':");
|
||||
logger.log(error.what());
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ void GroupBridge::handle_host_plugin(const PluginParameters parameters) {
|
||||
// plugins. If no active plugins remain, then we'll terminate
|
||||
std::lock_guard lock(active_plugins_mutex);
|
||||
|
||||
active_plugins.erase(parameters);
|
||||
active_plugins.erase(request);
|
||||
if (active_plugins.size() == 0) {
|
||||
logger.log("All plugins have exited, shutting down the group process");
|
||||
io_context.stop();
|
||||
@@ -140,7 +143,7 @@ void GroupBridge::accept_requests() {
|
||||
// still active so we can terminate early if it is not, but in this
|
||||
// case the yabridge instance has to determine that this process is
|
||||
// still running.
|
||||
const auto parameters = read_object<PluginParameters>(socket);
|
||||
const auto parameters = read_object<GroupRequest>(socket);
|
||||
|
||||
// Collisions in the generated socket names should be very rare, but
|
||||
// it could in theory happen
|
||||
@@ -149,7 +152,7 @@ void GroupBridge::accept_requests() {
|
||||
// CreateThread() doesn't support multiple arguments and requires
|
||||
// manualy memory management.
|
||||
handle_host_plugin_parameters* thread_params =
|
||||
new std::pair<GroupBridge*, PluginParameters>(this, parameters);
|
||||
new std::pair<GroupBridge*, GroupRequest>(this, parameters);
|
||||
active_plugins[parameters] =
|
||||
Win32Thread(handle_host_plugin_proxy, &thread_params);
|
||||
|
||||
@@ -209,7 +212,7 @@ uint32_t WINAPI handle_host_plugin_proxy(void* param) {
|
||||
// need to use manual memory management.
|
||||
auto thread_params = static_cast<handle_host_plugin_parameters*>(param);
|
||||
GroupBridge* instance = thread_params->first;
|
||||
PluginParameters parameters = thread_params->second;
|
||||
GroupRequest parameters = thread_params->second;
|
||||
delete thread_params;
|
||||
|
||||
instance->handle_host_plugin(parameters);
|
||||
|
||||
@@ -128,15 +128,15 @@ class GroupBridge {
|
||||
* `active_plugins` map. If this causes the vector to become empty, we will
|
||||
* terminate this process.
|
||||
*
|
||||
* @param parameters Information about the plugin to launch, i.e. the path
|
||||
* to the plugin and the path of the socket endpoint that will be used for
|
||||
* @param request Information about the plugin to launch, i.e. the path to
|
||||
* the plugin and the path of the socket endpoint that will be used for
|
||||
* communication.
|
||||
*
|
||||
* @note In the case that the process starts but no plugin gets initiated,
|
||||
* then the process will never exit on its own. This should not happen
|
||||
* though.
|
||||
*/
|
||||
void handle_host_plugin(const PluginParameters parameters);
|
||||
void handle_host_plugin(const GroupRequest request);
|
||||
|
||||
/**
|
||||
* Listen for new requests to spawn plugins within this process and handle
|
||||
@@ -148,7 +148,7 @@ class GroupBridge {
|
||||
/**
|
||||
* Listen on the group socket for incoming requests to host a new plugin
|
||||
* within this group process. This will asynchronously listen on the socket,
|
||||
* and for any connection made it will retrieve a `PluginParameters` object
|
||||
* and for any connection made it will retrieve a `GroupRequest` object
|
||||
* containing information about the plugin to host and then spawn a new
|
||||
* thread to start hosting that plugin.
|
||||
*
|
||||
@@ -208,7 +208,7 @@ class GroupBridge {
|
||||
* the amount of plugins currently running with their associated thread
|
||||
* handles.
|
||||
*/
|
||||
std::unordered_map<PluginParameters, Win32Thread> active_plugins;
|
||||
std::unordered_map<GroupRequest, Win32Thread> active_plugins;
|
||||
/**
|
||||
* A mutex to prevent two threads from simultaneously accessing the plugins
|
||||
* map, and also to prevent `handle_host_plugin()` from terminating the
|
||||
|
||||
Reference in New Issue
Block a user