From 4bb7e43008f8453f93559f35c64e937d38de1ebf Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 29 Dec 2022 18:22:48 +0100 Subject: [PATCH] x-platform LADSPA user preset files This fixes saving/loading custom user presests on Windows --- libs/ardour/ardour/ladspa_plugin.h | 5 +-- libs/ardour/ladspa_plugin.cc | 72 +++++++++++++----------------- libs/ardour/plugin_manager.cc | 16 +++++-- 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/libs/ardour/ardour/ladspa_plugin.h b/libs/ardour/ardour/ladspa_plugin.h index 7d10524092..049eaa99e4 100644 --- a/libs/ardour/ardour/ladspa_plugin.h +++ b/libs/ardour/ardour/ladspa_plugin.h @@ -142,9 +142,8 @@ class LIBARDOUR_API LadspaPlugin : public ARDOUR::Plugin int set_state_2X (const XMLNode&, int version); std::string do_save_preset (std::string name); void do_remove_preset (std::string name); - std::string preset_envvar () const; - std::string preset_source (std::string) const; - bool write_preset_file (std::string); + std::string preset_source () const; + bool write_preset_file (); void add_state (XMLNode *) const; }; diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index a4f33a7141..0e3077bda2 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -45,6 +45,10 @@ #include #endif +#include +#include +#include + #include "pbd/compose.h" #include "pbd/error.h" #include "pbd/locale_guard.h" @@ -834,60 +838,50 @@ void LadspaPlugin::do_remove_preset (string name) { #ifdef HAVE_LRDF - string const envvar = preset_envvar (); - if (envvar.empty()) { - warning << _("Could not locate HOME. Preset not removed.") << endmsg; - return; - } - Plugin::PresetRecord const * p = preset_by_label (name); if (!p) { return; } - string const source = preset_source (envvar); + string const source = preset_source (); lrdf_remove_preset (source.c_str(), p->uri.c_str ()); - write_preset_file (envvar); + write_preset_file (); #endif } string -LadspaPlugin::preset_envvar () const +LadspaPlugin::preset_source () const { - char* envvar; - if ((envvar = getenv ("HOME")) == 0) { - return ""; - } - - return envvar; -} - -string -LadspaPlugin::preset_source (string envvar) const -{ - return string_compose ("file:%1/.ladspa/rdf/ardour-presets.n3", envvar); + string const domain = "ladspa"; +#ifdef PLATFORM_WINDOWS + string path = Glib::build_filename (ARDOUR::user_cache_directory (), domain, "rdf", "ardour-presets.n3"); +#else + string path = Glib::build_filename (Glib::get_home_dir (), "." + domain, "rdf", "ardour-presets.n3"); +#endif + return Glib::filename_to_uri (path); } bool -LadspaPlugin::write_preset_file (string envvar) +LadspaPlugin::write_preset_file () { #ifdef HAVE_LRDF - string path = string_compose("%1/.ladspa", envvar); - if (g_mkdir_with_parents (path.c_str(), 0775)) { - warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg; + +#ifndef PLATFORM_WINDOWS + if (Glib::get_home_dir ().empty ()) { + warning << _("Could not locate HOME. Preset file not written.") << endmsg; + return false; + } +#endif + + string const source = preset_source (); + + if (g_mkdir_with_parents (Glib::path_get_dirname (source).c_str(), 0775)) { + warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), source, strerror(errno)) << endmsg; return false; } - path += "/rdf"; - if (g_mkdir_with_parents (path.c_str(), 0775)) { - warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg; - return false; - } - - string const source = preset_source (envvar); - - if (lrdf_export_by_source (source.c_str(), source.substr(5).c_str())) { + if (lrdf_export_by_source (source.c_str(), Glib::filename_from_uri (source).c_str())) { warning << string_compose(_("Error saving presets file %1."), source) << endmsg; return false; } @@ -930,19 +924,13 @@ LadspaPlugin::do_save_preset (string name) portvalues[i].value = get_parameter (input_parameter_pids[i]); } - string const envvar = preset_envvar (); - if (envvar.empty()) { - warning << _("Could not locate HOME. Preset not saved.") << endmsg; - return ""; - } - - string const source = preset_source (envvar); + string const source = preset_source (); char* uri_char = lrdf_add_preset (source.c_str(), name.c_str(), id, &defaults); string uri (uri_char); free (uri_char); - if (!write_preset_file (envvar)) { + if (!write_preset_file ()) { return ""; } diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 2e25228ec3..0169597292 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -279,6 +279,13 @@ PluginManager::PluginManager () add_lrdf_presets ("ladspa"); +#if 0 // dump RDF + lrdf_statement* r = lrdf_all_statements(); + for (lrdf_statement* it = r; it != NULL; it = it->next) { + printf("LRDF: (%s, %s, %s)\n", it->subject, it->predicate, it->object); + } +#endif + if ((s = getenv ("VST_PATH"))) { windows_vst_path = s; } else if ((s = getenv ("VST_PLUGINS"))) { @@ -828,12 +835,15 @@ PluginManager::add_lrdf_presets(string domain) vector presets; vector::iterator x; - char* envvar; - if ((envvar = getenv ("HOME")) == 0) { +#ifdef PLATFORM_WINDOWS + string path = Glib::build_filename (ARDOUR::user_cache_directory (), domain, "rdf"); +#else + if (Glib::get_home_dir ().empty ()) { return; } + string path = Glib::build_filename (Glib::get_home_dir (), "." + domain, "rdf"); +#endif - string path = string_compose("%1/.%2/rdf", envvar, domain); find_files_matching_filter (presets, path, rdf_filter, 0, false, true); for (x = presets.begin(); x != presets.end (); ++x) {