diff --git a/src/plugin/utils.cpp b/src/plugin/utils.cpp index 59a1c393..af28b3ff 100644 --- a/src/plugin/utils.cpp +++ b/src/plugin/utils.cpp @@ -164,7 +164,27 @@ fs::path find_vst_plugin() { "VST plugin .dll file."); } -fs::path generate_endpoint_name() { +boost::filesystem::path generate_group_endpoint( + std::string group_name, + boost::filesystem::path wine_prefix, + PluginArchitecture architecture) { + std::ostringstream socket_name; + socket_name << "yabridge-group-" << group_name << "-" + << std::hash{}(wine_prefix.string()) << "-"; + switch (architecture) { + case PluginArchitecture::vst_32: + socket_name << "x32"; + break; + case PluginArchitecture::vst_64: + socket_name << "x64"; + break; + } + socket_name << ".sock"; + + return fs::temp_directory_path() / socket_name.str(); +} + +fs::path generate_plugin_endpoint() { const auto plugin_name = find_vst_plugin().filename().replace_extension("").string(); diff --git a/src/plugin/utils.h b/src/plugin/utils.h index 3946d008..2cbad0a0 100644 --- a/src/plugin/utils.h +++ b/src/plugin/utils.h @@ -112,6 +112,32 @@ boost::filesystem::path find_vst_plugin(); */ std::optional find_wineprefix(); +/** + * Generate the group socket endpoint name used based on the name of the group, + * the Wine prefix in use and the plugin architecture. The resulting format is + * `/tmp/yabridge-group---.sock`. In + * this socket name the `wine_prefix_id` is a numerical hash based on the Wine + * prefix in use. This way the same group name can be used for multiple Wine + * prefixes and for both 32 and 64 bit plugins without clashes. + * + * @param group_name The name of the plugin group. + * @param wine_prefix The name of the Wine prefix in use. This should be + * obtained by first calling `set_wineprefix()` to allow the user to override + * this, and then falling back to `$HOME/.wine` if the environment variable is + * unset. Otherwise plugins run from outwide of a Wine prefix will not be + * groupable with those run from within `~/.wine` even though they both run + * under the same prefix. + * @param architecture The architecture the plugin is using, since 64-bit + * processes can't host 32-bit plugins and the other way around. + * + * @return A socket endpoint path that corresponds to the format described + * above. + */ +boost::filesystem::path generate_group_endpoint( + std::string group_name, + boost::filesystem::path wine_prefix, + PluginArchitecture architecture); + /** * Generate a unique name for the Unix domain socket endpoint based on the VST * plugin's name. This will also generate the parent directory if it does not @@ -120,7 +146,7 @@ std::optional find_wineprefix(); * @return A path to a not yet existing Unix domain socket endpoint. * @throw std::runtime_error If no matching .dll file could be found. */ -boost::filesystem::path generate_endpoint_name(); +boost::filesystem::path generate_plugin_endpoint(); /** * Return a path to this `.so` file. This can be used to find out from where