Manage attempts to save plugin presets with the same name. Helps with #2662.
git-svn-id: svn://localhost/ardour2/branches/3.0@8191 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
433196a83a
commit
5546fa38fc
@ -66,6 +66,7 @@
|
|||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "latency_gui.h"
|
#include "latency_gui.h"
|
||||||
#include "plugin_eq_gui.h"
|
#include "plugin_eq_gui.h"
|
||||||
|
#include "new_plugin_preset_dialog.h"
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
@ -475,7 +476,7 @@ PlugUIBase::set_latency_label ()
|
|||||||
framecnt_t const sr = insert->session().frame_rate ();
|
framecnt_t const sr = insert->session().frame_rate ();
|
||||||
|
|
||||||
if (l < sr / 1000) {
|
if (l < sr / 1000) {
|
||||||
snprintf (buf, sizeof (buf), "latency (%d samples)", l);
|
snprintf (buf, sizeof (buf), "latency (%" PRId64 " samples)", l);
|
||||||
} else {
|
} else {
|
||||||
snprintf (buf, sizeof (buf), "latency (%.2f msecs)", (float) l / ((float) sr / 1000.0f));
|
snprintf (buf, sizeof (buf), "latency (%.2f msecs)", (float) l / ((float) sr / 1000.0f));
|
||||||
}
|
}
|
||||||
@ -527,27 +528,23 @@ PlugUIBase::setting_selected()
|
|||||||
void
|
void
|
||||||
PlugUIBase::save_plugin_setting ()
|
PlugUIBase::save_plugin_setting ()
|
||||||
{
|
{
|
||||||
ArdourPrompter prompter (true);
|
NewPluginPresetDialog d (plugin);
|
||||||
prompter.set_title(_("New Preset"));
|
|
||||||
prompter.set_prompt(_("Name of New Preset:"));
|
|
||||||
prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
|
|
||||||
prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
|
||||||
prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
|
|
||||||
|
|
||||||
prompter.show_all();
|
switch (d.run ()) {
|
||||||
prompter.present ();
|
|
||||||
|
|
||||||
switch (prompter.run ()) {
|
|
||||||
case Gtk::RESPONSE_ACCEPT:
|
case Gtk::RESPONSE_ACCEPT:
|
||||||
string name;
|
if (d.name().empty()) {
|
||||||
prompter.get_result(name);
|
break;
|
||||||
if (name.length()) {
|
}
|
||||||
if (plugin->save_preset(name)) {
|
|
||||||
update_presets();
|
if (d.replace ()) {
|
||||||
no_load_preset = true;
|
plugin->remove_preset (d.name ());
|
||||||
preset_combo.set_active_text (name);
|
}
|
||||||
no_load_preset = false;
|
|
||||||
}
|
if (plugin->save_preset (d.name())) {
|
||||||
|
update_presets ();
|
||||||
|
no_load_preset = true;
|
||||||
|
preset_combo.set_active_text (d.name());
|
||||||
|
no_load_preset = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,7 @@ gtk2_ardour_sources = [
|
|||||||
'monitor_section.cc',
|
'monitor_section.cc',
|
||||||
'mouse_cursors.cc',
|
'mouse_cursors.cc',
|
||||||
'nag.cc',
|
'nag.cc',
|
||||||
|
'new_plugin_preset_dialog.cc',
|
||||||
'normalize_dialog.cc',
|
'normalize_dialog.cc',
|
||||||
'note_player.cc',
|
'note_player.cc',
|
||||||
'option_editor.cc',
|
'option_editor.cc',
|
||||||
|
@ -99,7 +99,8 @@ class LadspaPlugin : public ARDOUR::Plugin
|
|||||||
|
|
||||||
XMLNode& get_state();
|
XMLNode& get_state();
|
||||||
int set_state (const XMLNode&, int version);
|
int set_state (const XMLNode&, int version);
|
||||||
bool save_preset(std::string name);
|
bool save_preset (std::string name);
|
||||||
|
void remove_preset (std::string name);
|
||||||
|
|
||||||
bool has_editor() const { return false; }
|
bool has_editor() const { return false; }
|
||||||
|
|
||||||
|
@ -114,8 +114,9 @@ class LV2Plugin : public ARDOUR::Plugin
|
|||||||
|
|
||||||
XMLNode& get_state();
|
XMLNode& get_state();
|
||||||
int set_state(const XMLNode& node, int version);
|
int set_state(const XMLNode& node, int version);
|
||||||
bool save_preset(std::string uri);
|
bool save_preset (std::string uri);
|
||||||
bool load_preset(const std::string& uri);
|
void remove_preset (std::string uri);
|
||||||
|
bool load_preset (const std::string& uri);
|
||||||
virtual std::vector<Plugin::PresetRecord> get_presets();
|
virtual std::vector<Plugin::PresetRecord> get_presets();
|
||||||
|
|
||||||
bool has_editor() const;
|
bool has_editor() const;
|
||||||
|
@ -129,6 +129,7 @@ class Plugin : public PBD::StatefulDestructible, public Latent
|
|||||||
virtual bool parameter_is_output(uint32_t) const = 0;
|
virtual bool parameter_is_output(uint32_t) const = 0;
|
||||||
|
|
||||||
virtual bool save_preset (std::string) = 0;
|
virtual bool save_preset (std::string) = 0;
|
||||||
|
virtual void remove_preset (std::string) = 0;
|
||||||
virtual bool load_preset (const std::string& uri);
|
virtual bool load_preset (const std::string& uri);
|
||||||
|
|
||||||
struct PresetRecord {
|
struct PresetRecord {
|
||||||
@ -187,6 +188,10 @@ class Plugin : public PBD::StatefulDestructible, public Latent
|
|||||||
virtual void set_parameter (uint32_t which, float val) = 0;
|
virtual void set_parameter (uint32_t which, float val) = 0;
|
||||||
|
|
||||||
bool save_preset (std::string, std::string /* vst, ladspa etc. */);
|
bool save_preset (std::string, std::string /* vst, ladspa etc. */);
|
||||||
|
void remove_preset (std::string, std::string);
|
||||||
|
bool write_preset_file (std::string, std::string);
|
||||||
|
std::string preset_source (std::string, std::string) const;
|
||||||
|
std::string preset_envvar () const;
|
||||||
|
|
||||||
ARDOUR::AudioEngine& _engine;
|
ARDOUR::AudioEngine& _engine;
|
||||||
ARDOUR::Session& _session;
|
ARDOUR::Session& _session;
|
||||||
|
@ -372,6 +372,12 @@ LadspaPlugin::save_preset (string name)
|
|||||||
return Plugin::save_preset (name, "ladspa");
|
return Plugin::save_preset (name, "ladspa");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LadspaPlugin::remove_preset (string name)
|
||||||
|
{
|
||||||
|
return Plugin::remove_preset (name, "ladspa");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
LadspaPlugin::set_state (const XMLNode& node, int version)
|
LadspaPlugin::set_state (const XMLNode& node, int version)
|
||||||
{
|
{
|
||||||
|
@ -386,6 +386,12 @@ LV2Plugin::save_preset (string /*name*/)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LV2Plugin::remove_preset (string /*name*/)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LV2Plugin::has_editor() const
|
LV2Plugin::has_editor() const
|
||||||
{
|
{
|
||||||
|
@ -162,6 +162,109 @@ Plugin::load_preset(const string& preset_uri)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* XXX: should be in liblrdf */
|
||||||
|
static void
|
||||||
|
lrdf_remove_preset (const char *source, const char *setting_uri)
|
||||||
|
{
|
||||||
|
lrdf_statement p;
|
||||||
|
lrdf_statement *q;
|
||||||
|
lrdf_statement *i;
|
||||||
|
char setting_uri_copy[64];
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
strncpy(setting_uri_copy, setting_uri, sizeof(setting_uri_copy));
|
||||||
|
|
||||||
|
p.subject = setting_uri_copy;
|
||||||
|
strncpy(buf, LADSPA_BASE "hasPortValue", sizeof(buf));
|
||||||
|
p.predicate = buf;
|
||||||
|
p.object = NULL;
|
||||||
|
q = lrdf_matches(&p);
|
||||||
|
|
||||||
|
p.predicate = NULL;
|
||||||
|
p.object = NULL;
|
||||||
|
for (i = q; i; i = i->next) {
|
||||||
|
p.subject = i->object;
|
||||||
|
lrdf_remove_matches(&p);
|
||||||
|
}
|
||||||
|
|
||||||
|
lrdf_free_statements(q);
|
||||||
|
|
||||||
|
p.subject = NULL;
|
||||||
|
strncpy(buf, LADSPA_BASE "hasSetting", sizeof(buf));
|
||||||
|
p.predicate = buf;
|
||||||
|
p.object = setting_uri_copy;
|
||||||
|
lrdf_remove_matches(&p);
|
||||||
|
|
||||||
|
p.subject = setting_uri_copy;
|
||||||
|
p.predicate = NULL;
|
||||||
|
p.object = NULL;
|
||||||
|
lrdf_remove_matches (&p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Plugin::remove_preset (string name, string domain)
|
||||||
|
{
|
||||||
|
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, domain);
|
||||||
|
lrdf_remove_preset (source.c_str(), p->uri.c_str ());
|
||||||
|
|
||||||
|
presets.erase (p->uri);
|
||||||
|
|
||||||
|
write_preset_file (envvar, domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
Plugin::preset_envvar () const
|
||||||
|
{
|
||||||
|
char* envvar;
|
||||||
|
if ((envvar = getenv ("HOME")) == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return envvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
Plugin::preset_source (string envvar, string domain) const
|
||||||
|
{
|
||||||
|
return string_compose ("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Plugin::write_preset_file (string envvar, string domain)
|
||||||
|
{
|
||||||
|
string path = string_compose("%1/.%2", envvar, domain);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, domain);
|
||||||
|
|
||||||
|
if (lrdf_export_by_source (source.c_str(), source.substr(5).c_str())) {
|
||||||
|
warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Plugin::save_preset (string name, string domain)
|
Plugin::save_preset (string name, string domain)
|
||||||
{
|
{
|
||||||
@ -191,13 +294,13 @@ Plugin::save_preset (string name, string domain)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* envvar;
|
string const envvar = preset_envvar ();
|
||||||
if ((envvar = getenv ("HOME")) == 0) {
|
if (envvar.empty()) {
|
||||||
warning << _("Could not locate HOME. Preset not saved.") << endmsg;
|
warning << _("Could not locate HOME. Preset not saved.") << endmsg;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
|
string const source = preset_source (envvar, domain);
|
||||||
|
|
||||||
char* uri = lrdf_add_preset (source.c_str(), name.c_str(), id, &defaults);
|
char* uri = lrdf_add_preset (source.c_str(), name.c_str(), id, &defaults);
|
||||||
|
|
||||||
@ -206,24 +309,7 @@ Plugin::save_preset (string name, string domain)
|
|||||||
presets.insert (make_pair (uri, PresetRecord (uri, name)));
|
presets.insert (make_pair (uri, PresetRecord (uri, name)));
|
||||||
free (uri);
|
free (uri);
|
||||||
|
|
||||||
string path = string_compose("%1/.%2", envvar, domain);
|
return write_preset_file (envvar, domain);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
|
|
||||||
warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginPtr
|
PluginPtr
|
||||||
|
Loading…
Reference in New Issue
Block a user