+
+ XMLNode* root = t->root ();
+
+ for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) {
+ XMLProperty* label = (*i)->property (X_("label"));
+
+ assert (label);
+
+ if (label->value() != r.label) {
+ continue;
+ }
+
+ if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
+
+ /* Load a user preset chunk from our XML file and send it via a circuitous route to the plugin */
+
+ if (_state->wanted_chunk) {
+ g_free (_state->wanted_chunk);
+ }
+
+ for (XMLNodeList::const_iterator j = (*i)->children().begin(); j != (*i)->children().end(); ++j) {
+ if ((*j)->is_content ()) {
+ /* we can't dispatch directly here; too many plugins expect only one GUI thread */
+ gsize size = 0;
+ guchar* raw_data = g_base64_decode ((*j)->content().c_str(), &size);
+ _state->wanted_chunk = raw_data;
+ _state->wanted_chunk_size = size;
+ _state->want_chunk = 1;
+ return true;
+ }
+ }
+
+ return false;
+
+ } else {
+
+ for (XMLNodeList::const_iterator j = (*i)->children().begin(); j != (*i)->children().end(); ++j) {
+ if ((*j)->name() == X_("Parameter")) {
+ XMLProperty* index = (*j)->property (X_("index"));
+ XMLProperty* value = (*j)->property (X_("value"));
+
+ assert (index);
+ assert (value);
+
+ set_parameter (atoi (index->value().c_str()), atof (value->value().c_str ()));
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+string
+VSTPlugin::do_save_preset (string name)
+{
+ boost::shared_ptr<XMLTree> t (presets_tree ());
+ if (t == 0) {
+ return "";
+ }
+
+ XMLNode* p = 0;
+ /* XXX: use of _presets.size() + 1 for the unique ID here is dubious at best */
+ string const uri = string_compose (X_("VST:%1:%2"), unique_id (), _presets.size() + 1);
+
+ if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
+
+ p = new XMLNode (X_("ChunkPreset"));
+ p->add_property (X_("uri"), uri);
+ p->add_property (X_("label"), name);
+ gchar* data = get_chunk (true);
+ p->add_content (string (data));
+ g_free (data);
+
+ } else {
+
+ p = new XMLNode (X_("Preset"));
+ p->add_property (X_("uri"), uri);
+ p->add_property (X_("label"), name);
+
+ for (uint32_t i = 0; i < parameter_count(); ++i) {
+ if (parameter_is_input (i)) {
+ XMLNode* c = new XMLNode (X_("Parameter"));
+ c->add_property (X_("index"), string_compose ("%1", i));
+ c->add_property (X_("value"), string_compose ("%1", get_parameter (i)));
+ p->add_child_nocopy (*c);
+ }
+ }
+ }
+
+ t->root()->add_child_nocopy (*p);
+
+ std::string f = Glib::build_filename (ARDOUR::user_config_directory (), "presets");
+ f = Glib::build_filename (f, presets_file ());
+
+ t->write (f);
+ return uri;
+}
+
+void
+VSTPlugin::do_remove_preset (string name)
+{
+ boost::shared_ptr<XMLTree> t (presets_tree ());
+ if (t == 0) {
+ return;
+ }
+
+ t->root()->remove_nodes_and_delete (X_("label"), name);
+
+ std::string f = Glib::build_filename (ARDOUR::user_config_directory (), "presets");
+ f = Glib::build_filename (f, presets_file ());
+
+ t->write (f);