+
+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);
+ lrdf_remove_preset (source.c_str(), p->uri.c_str ());
+
+ write_preset_file (envvar);
+#endif
+}
+
+string
+LadspaPlugin::preset_envvar () 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);
+}
+
+bool
+LadspaPlugin::write_preset_file (string envvar)
+{
+#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;
+ 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())) {
+ warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
+ return false;
+ }
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+string
+LadspaPlugin::do_save_preset (string name)
+{
+#ifdef HAVE_LRDF
+ /* make a vector of pids that are input parameters */
+ vector<int> input_parameter_pids;
+ for (uint32_t i = 0; i < parameter_count(); ++i) {
+ if (parameter_is_input (i)) {
+ input_parameter_pids.push_back (i);
+ }
+ }
+
+ std::string unique (unique_id());
+
+ if (!isdigit (unique[0])) {
+ return "";
+ }
+
+ uint32_t const id = atol (unique.c_str());
+
+ lrdf_defaults defaults;
+ defaults.count = input_parameter_pids.size ();
+ lrdf_portvalue portvalues[input_parameter_pids.size()];
+ defaults.items = portvalues;
+
+ for (vector<int>::size_type i = 0; i < input_parameter_pids.size(); ++i) {
+ portvalues[i].pid = input_parameter_pids[i];
+ 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);
+
+ 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)) {
+ return "";
+ }
+
+ return uri;
+#else
+ return string();
+#endif
+}
+
+LADSPA_PortDescriptor
+LadspaPlugin::port_descriptor (uint32_t i) const
+{
+ if (i < _descriptor->PortCount) {
+ return _descriptor->PortDescriptors[i];
+ }
+
+ warning << "LADSPA plugin port index " << i << " out of range." << endmsg;
+ return 0;
+}
+
+
+