Towards fixing AU preset invalidation
[ardour.git] / libs / ardour / plugin_manager.cc
index 9713a241e2a09e6f54f52843626d7d162e4423c6..06a7e0ee774fed5f0773b7037f5782f179141e6e 100644 (file)
@@ -993,7 +993,6 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("VST plugin %1 does not support processReplacing, and cannot be used in %2 at this time"),
@@ -1002,29 +1001,14 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info (new WindowsVSTPluginInfo);
+               PluginInfoPtr info (new WindowsVSTPluginInfo (finfo));
+               info->path = path;
 
                /* what a joke freeware VST is */
-
                if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
                        info->name = PBD::basename_nosuffix (path);
-               } else {
-                       info->name = finfo->name;
                }
 
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               info->category = finfo->Category;
-               info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::Windows_VST;
-
                /* if we don't have any tags for this plugin, make some up. */
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
 
@@ -1140,7 +1124,6 @@ PluginManager::mac_vst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("Mac VST plugin %1 does not support processReplacing, and so cannot be used in %2 at this time"),
@@ -1149,21 +1132,8 @@ PluginManager::mac_vst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info (new MacVSTPluginInfo);
-
-               info->name = finfo->name;
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               info->category = finfo->Category;
+               PluginInfoPtr info (new MacVSTPluginInfo (finfo));
                info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::MacVST;
 
                /* if we don't have any tags for this plugin, make some up. */
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
@@ -1257,7 +1227,6 @@ PluginManager::lxvst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("linuxVST plugin %1 does not support processReplacing, and so cannot be used in %2 at this time"),
@@ -1266,27 +1235,13 @@ PluginManager::lxvst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info(new LXVSTPluginInfo);
+               PluginInfoPtr info(new LXVSTPluginInfo (finfo));
+               info->path = path;
 
                if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
                        info->name = PBD::basename_nosuffix (path);
-               } else {
-                       info->name = finfo->name;
                }
 
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               info->category = finfo->Category;
-               info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::LXVST;
-
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
 
                /* Make sure we don't find the same plugin in more than one place along
@@ -1537,6 +1492,43 @@ PluginManager::user_plugin_metadata_dir () const
        return dir;
 }
 
+bool
+PluginManager::load_plugin_order_file (XMLNode &n) const
+{
+       std::string path = Glib::build_filename (user_plugin_metadata_dir(), "plugin_order");
+
+       info << string_compose (_("Loading plugin order file %1"), path) << endmsg;
+       if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+               return false;
+       }
+
+       XMLTree tree;
+       if (tree.read (path)) {
+               n = *(tree.root());
+               return true;
+       } else {
+               error << string_compose (_("Cannot parse Plugin Order info from %1"), path) << endmsg;
+               return false;
+       }
+}
+
+
+void
+PluginManager::save_plugin_order_file (XMLNode &elem) const
+{
+       std::string path = Glib::build_filename (user_plugin_metadata_dir(), "plugin_order");
+
+       info << string_compose (_("Saving plugin order file %1"), path) << endmsg;
+
+       XMLTree tree;
+       tree.set_root (&elem);
+       if (!tree.write (path)) {
+               error << string_compose (_("Could not save Plugin Order info to %1"), path) << endmsg;
+       }
+       tree.set_root (0);  //note: must disconnect the elem from XMLTree, or it will try to delete memory it didn't allocate
+}
+
+
 void
 PluginManager::save_tags ()
 {
@@ -1553,7 +1545,9 @@ PluginManager::save_tags ()
                node->set_property (X_("id"), (*i).unique_id);
                node->set_property (X_("tags"), (*i).tags);
                node->set_property (X_("name"), (*i).name);
-               node->set_property (X_("user-set"), "1");
+               if ( (*i).tagtype >= FromUserFile ) {
+                       node->set_property (X_("user-set"), "1");
+               }
                root->add_child_nocopy (*node);
        }
 
@@ -1570,7 +1564,8 @@ PluginManager::load_tags ()
        vector<std::string> tmp;
        find_files_matching_pattern (tmp, plugin_metadata_search_path (), "plugin_tags");
 
-       for (vector<std::string>::const_reverse_iterator p = tmp.rbegin (); p != tmp.rend(); ++p) {
+       for (vector<std::string>::const_reverse_iterator p = tmp.rbegin ();
+                       p != (vector<std::string>::const_reverse_iterator)tmp.rend(); ++p) {
                std::string path = *p;
                info << string_compose (_("Loading plugin meta data file %1"), path) << endmsg;
                if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
@@ -1612,7 +1607,7 @@ PluginManager::set_tags (PluginType t, string id, string tag, std::string name,
        PluginTagList::const_iterator i = find (ptags.begin(), ptags.end(), ps);
        if (i == ptags.end()) {
                ptags.insert (ps);
-       } else if ( (uint32_t) ttype >  (uint32_t) (*i).tagtype ) {  // only overwrite if we are more important than the existing. Gui > UserFile > FactoryFile > Plugin
+       } else if ( (uint32_t) ttype >=  (uint32_t) (*i).tagtype ) {  // only overwrite if we are more important than the existing. Gui > UserFile > FactoryFile > Plugin
                ptags.erase (ps);
                ptags.insert (ps);
        }