+
+void
+VSTPlugin::find_presets ()
+{
+ /* Built-in presets */
+
+ int const vst_version = _plugin->dispatcher (_plugin, effGetVstVersion, 0, 0, NULL, 0);
+ for (int i = 0; i < _plugin->numPrograms; ++i) {
+ PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id (), i), "", false);
+
+ if (vst_version >= 2) {
+ char buf[256];
+ if (_plugin->dispatcher (_plugin, 29, i, 0, buf, 0) == 1) {
+ r.label = buf;
+ } else {
+ r.label = string_compose (_("Preset %1"), i);
+ }
+ } else {
+ r.label = string_compose (_("Preset %1"), i);
+ }
+
+ _presets.insert (make_pair (r.uri, r));
+ }
+
+ /* User presets from our XML file */
+
+ boost::shared_ptr<XMLTree> t (presets_tree ());
+
+ if (t) {
+ XMLNode* root = t->root ();
+ for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) {
+
+ XMLProperty* uri = (*i)->property (X_("uri"));
+ XMLProperty* label = (*i)->property (X_("label"));
+
+ assert (uri);
+ assert (label);
+
+ PresetRecord r (uri->value(), label->value(), true);
+ _presets.insert (make_pair (r.uri, r));
+ }
+ }
+
+}
+
+/** @return XMLTree with our user presets; could be a new one if no existing
+ * one was found, or 0 if one was present but badly-formatted.
+ */
+XMLTree *
+VSTPlugin::presets_tree () const
+{
+ XMLTree* t = new XMLTree;
+
+ sys::path p = ARDOUR::user_config_directory ();
+ p /= "presets";
+
+ if (!is_directory (p)) {
+ create_directory (p);
+ }
+
+ p /= presets_file ();
+
+ if (!exists (p)) {
+ t->set_root (new XMLNode (X_("VSTPresets")));
+ return t;
+ }
+
+ t->set_filename (p.to_string ());
+ if (!t->read ()) {
+ delete t;
+ return 0;
+ }
+
+ return t;
+}
+
+/** @return Index of the first user preset in our lists */
+int
+VSTPlugin::first_user_preset_index () const
+{
+ return _plugin->numPrograms;
+}
+
+string
+VSTPlugin::presets_file () const
+{
+ return string_compose ("vst-%1", unique_id ());
+}
+
+VSTPluginInfo::VSTPluginInfo()
+{
+ type = ARDOUR::VST;
+}
+