13
0

x-platform LADSPA user preset files

This fixes saving/loading custom user presests on Windows
This commit is contained in:
Robin Gareus 2022-12-29 18:22:48 +01:00
parent 3ba999b9d7
commit 4bb7e43008
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 45 additions and 48 deletions

View File

@ -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;
};

View File

@ -45,6 +45,10 @@
#include <lrdf.h>
#endif
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>
#include <glibmm/convert.h>
#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 "";
}

View File

@ -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<string> presets;
vector<string>::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) {