Rename PluginParameters to GroupReuqest

This commit is contained in:
Robbert van der Helm
2020-05-22 14:08:13 +02:00
parent 27af0f8c11
commit dd843519ce
5 changed files with 34 additions and 27 deletions
+1 -1
View File
@@ -109,6 +109,6 @@ AEffect& update_aeffect(AEffect& plugin, const AEffect& updated_plugin) {
return 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; return plugin_path == rhs.plugin_path && socket_path == rhs.socket_path;
} }
+4 -4
View File
@@ -577,11 +577,11 @@ struct AudioBuffers {
* group process. These are the exact same options that would have been passed * group process. These are the exact same options that would have been passed
* to `yabridge-host.exe` were the plugin to be hosted individually. * to `yabridge-host.exe` were the plugin to be hosted individually.
*/ */
struct PluginParameters { struct GroupRequest {
std::string plugin_path; std::string plugin_path;
std::string socket_path; std::string socket_path;
bool operator==(const PluginParameters& rhs) const; bool operator==(const GroupRequest& rhs) const;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
@@ -591,8 +591,8 @@ struct PluginParameters {
}; };
template <> template <>
struct std::hash<PluginParameters> { struct std::hash<GroupRequest> {
std::size_t operator()(PluginParameters const& params) const noexcept { std::size_t operator()(GroupRequest const& params) const noexcept {
std::hash<string> hasher{}; std::hash<string> hasher{};
return hasher(params.plugin_path) ^ (hasher(params.socket_path) << 1); return hasher(params.plugin_path) ^ (hasher(params.socket_path) << 1);
+4
View File
@@ -49,6 +49,10 @@ PluginBridge& get_bridge_instance(const AEffect& plugin) {
return *static_cast<PluginBridge*>(plugin.ptr3); 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) PluginBridge::PluginBridge(audioMasterCallback host_callback)
: config(Configuration::load_for(get_this_file_location())), : config(Configuration::load_for(get_this_file_location())),
vst_plugin_path(find_vst_plugin()), vst_plugin_path(find_vst_plugin()),
+20 -17
View File
@@ -31,13 +31,17 @@ namespace fs = boost::filesystem;
*/ */
std::string create_logger_prefix(const fs::path& socket_path); 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); 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, StdIoCapture::StdIoCapture(boost::asio::io_context& io_context,
int file_descriptor) int file_descriptor)
: pipe(io_context), : 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] "); 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 // At this point the `active_plugins` map will already contain a copy of
// `parameters` along with this thread's handle // `parameters` along with this thread's handle
// The initialization process for a plugin is identical to that in // The initialization process for a plugin is identical to that in
// `../individual-host.cpp` // `../individual-host.cpp`
logger.log("Received request to host '" + parameters.plugin_path + logger.log("Received request to host '" + request.plugin_path +
"' using socket '" + parameters.socket_path + "'"); "' using socket '" + request.socket_path + "'");
try { try {
Vst2Bridge bridge(parameters.plugin_path, parameters.socket_path); Vst2Bridge bridge(request.plugin_path, request.socket_path);
logger.log("Finished initializing '" + parameters.plugin_path + "'"); logger.log("Finished initializing '" + request.plugin_path + "'");
// Blocks the main thread until the plugin shuts down // Blocks the main thread until the plugin shuts down
bridge.handle_dispatch(); bridge.handle_dispatch();
logger.log("" + parameters.plugin_path + "' has exited"); logger.log("" + request.plugin_path + "' has exited");
} catch (const std::runtime_error& error) { } 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()); 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 // plugins. If no active plugins remain, then we'll terminate
std::lock_guard lock(active_plugins_mutex); std::lock_guard lock(active_plugins_mutex);
active_plugins.erase(parameters); active_plugins.erase(request);
if (active_plugins.size() == 0) { if (active_plugins.size() == 0) {
logger.log("All plugins have exited, shutting down the group process"); logger.log("All plugins have exited, shutting down the group process");
io_context.stop(); 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 // 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 // case the yabridge instance has to determine that this process is
// still running. // 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 // Collisions in the generated socket names should be very rare, but
// it could in theory happen // it could in theory happen
@@ -149,7 +152,7 @@ void GroupBridge::accept_requests() {
// CreateThread() doesn't support multiple arguments and requires // CreateThread() doesn't support multiple arguments and requires
// manualy memory management. // manualy memory management.
handle_host_plugin_parameters* thread_params = handle_host_plugin_parameters* thread_params =
new std::pair<GroupBridge*, PluginParameters>(this, parameters); new std::pair<GroupBridge*, GroupRequest>(this, parameters);
active_plugins[parameters] = active_plugins[parameters] =
Win32Thread(handle_host_plugin_proxy, &thread_params); 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. // need to use manual memory management.
auto thread_params = static_cast<handle_host_plugin_parameters*>(param); auto thread_params = static_cast<handle_host_plugin_parameters*>(param);
GroupBridge* instance = thread_params->first; GroupBridge* instance = thread_params->first;
PluginParameters parameters = thread_params->second; GroupRequest parameters = thread_params->second;
delete thread_params; delete thread_params;
instance->handle_host_plugin(parameters); instance->handle_host_plugin(parameters);
+5 -5
View File
@@ -128,15 +128,15 @@ class GroupBridge {
* `active_plugins` map. If this causes the vector to become empty, we will * `active_plugins` map. If this causes the vector to become empty, we will
* terminate this process. * terminate this process.
* *
* @param parameters Information about the plugin to launch, i.e. the path * @param request Information about the plugin to launch, i.e. the path to
* to the plugin and the path of the socket endpoint that will be used for * the plugin and the path of the socket endpoint that will be used for
* communication. * communication.
* *
* @note In the case that the process starts but no plugin gets initiated, * @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 * then the process will never exit on its own. This should not happen
* though. * 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 * 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 * Listen on the group socket for incoming requests to host a new plugin
* within this group process. This will asynchronously listen on the socket, * 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 * containing information about the plugin to host and then spawn a new
* thread to start hosting that plugin. * thread to start hosting that plugin.
* *
@@ -208,7 +208,7 @@ class GroupBridge {
* the amount of plugins currently running with their associated thread * the amount of plugins currently running with their associated thread
* handles. * 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 * A mutex to prevent two threads from simultaneously accessing the plugins
* map, and also to prevent `handle_host_plugin()` from terminating the * map, and also to prevent `handle_host_plugin()` from terminating the