+ if (status != Normal) {
+ statuses.insert (ps);
+ }
+
+ PluginStatusesChanged (t, id, status); /* EMIT SIGNAL */
+}
+
+PluginType
+PluginManager::to_generic_vst (const PluginType t)
+{
+ switch (t) {
+ case Windows_VST:
+ case LXVST:
+ case MacVST:
+ return LXVST;
+ default:
+ break;
+ }
+ return t;
+}
+
+struct SortByTag {
+ bool operator() (std::string a, std::string b) {
+ return a.compare (b) < 0;
+ }
+};
+
+vector<std::string>
+PluginManager::get_tags (const PluginInfoPtr& pi) const
+{
+ vector<std::string> tags;
+
+ PluginTag ps (to_generic_vst(pi->type), pi->unique_id, "", false);
+ PluginTagList::const_iterator i = find (ptags.begin(), ptags.end(), ps);
+ if (i != ptags.end ()) {
+ PBD::tokenize (i->tags, string(" "), std::back_inserter (tags), true);
+ SortByTag sorter;
+ sort (tags.begin(), tags.end(), sorter);
+ }
+ return tags;
+}
+
+std::string
+PluginManager::get_tags_as_string (PluginInfoPtr const& pi) const
+{
+ std::string ret;
+
+ vector<std::string> tags = get_tags(pi);
+ for (vector<string>::iterator t = tags.begin(); t != tags.end(); ++t) {
+ if (t != tags.begin ()) {
+ ret.append(" ");
+ }
+ ret.append(*t);
+ }
+
+ return ret;
+}
+
+std::string
+PluginManager::user_plugin_metadata_dir () const
+{
+ std::string dir = Glib::build_filename (user_config_directory(), plugin_metadata_dir_name);
+ g_mkdir_with_parents (dir.c_str(), 0744);
+ return dir;
+}
+
+void
+PluginManager::save_tags ()
+{
+ std::string path = Glib::build_filename (user_plugin_metadata_dir(), "plugin_tags");
+ XMLNode* root = new XMLNode (X_("PluginTags"));
+
+ for (PluginTagList::iterator i = ptags.begin(); i != ptags.end(); ++i) {
+ if (!(*i).user_set) {
+ continue;
+ }
+ XMLNode* node = new XMLNode (X_("Plugin"));
+ node->set_property (X_("type"), to_generic_vst ((*i).type));
+ node->set_property (X_("id"), (*i).unique_id);
+ node->set_property (X_("tags"), (*i).tags);
+ node->set_property (X_("user-set"), (*i).user_set);
+ root->add_child_nocopy (*node);
+ }
+
+ XMLTree tree;
+ tree.set_root (root);
+ if (!tree.write (path)) {
+ error << string_compose (_("Could not save Plugin Tags info to %1"), path) << endmsg;
+ }
+}
+
+void
+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) {
+ std::string path = *p;
+ info << string_compose (_("Loading plugin meta data file %1"), path) << endmsg;
+ if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+ return;
+ }
+
+ XMLTree tree;
+ if (!tree.read (path)) {
+ error << string_compose (_("Cannot parse plugin tag info from %1"), path) << endmsg;
+ return;
+ }
+
+ for (XMLNodeConstIterator i = tree.root()->children().begin(); i != tree.root()->children().end(); ++i) {
+ PluginType type;
+ string id;
+ string tags;
+ bool user_set;
+ if (!(*i)->get_property (X_("type"), type) ||
+ !(*i)->get_property (X_("id"), id) ||
+ !(*i)->get_property (X_("tags"), tags)) {
+ }
+ if (!(*i)->get_property (X_("user-set"), user_set)) {
+ user_set = false;
+ }
+ strip_whitespace_edges (tags);
+ set_tags (type, id, tags, !user_set);
+ }
+ }
+}
+
+void
+PluginManager::set_tags (PluginType t, string id, string tag, bool factory, bool force)
+{
+ string sanitized = sanitize_tag (tag);
+
+ PluginTag ps (to_generic_vst (t), id, sanitized, !factory);
+ PluginTagList::const_iterator i = find (ptags.begin(), ptags.end(), ps);
+ if (i == ptags.end()) {
+ ptags.insert (ps);
+ } else if (!factory || force || !(*i).user_set) {
+ ptags.erase (ps);
+ ptags.insert (ps);
+ }
+ if (!factory || force) {
+ PluginTagsChanged (t, id, sanitized); /* EMIT SIGNAL */
+ }
+}
+
+void
+PluginManager::reset_tags (PluginInfoPtr const& pi)
+{
+ set_tags (pi->type, pi->unique_id, pi->category, true, true);
+}
+
+std::string
+PluginManager::sanitize_tag (const std::string to_sanitize) const
+{
+ if (to_sanitize.empty ()) {
+ return "";
+ }
+ string sanitized = to_sanitize;
+ vector<string> tags;
+ if (!PBD::tokenize (sanitized, string(" ,\n"), std::back_inserter (tags), true)) {
+#ifndef NDEBUG
+ cerr << _("PluginManager::sanitize_tag could not tokenize string: ") << sanitized << endmsg;
+#endif
+ return "";
+ }
+
+ /* convert tokens to lower-case, space-separated list */
+ sanitized = "";
+ for (vector<string>::iterator t = tags.begin(); t != tags.end(); ++t) {
+ if (t != tags.begin ()) {
+ sanitized.append(" ");
+ }
+ sanitized.append (downcase (*t));
+ }
+
+ return sanitized;
+}
+
+std::vector<std::string>
+PluginManager::get_all_tags (bool favorites_only) const
+{
+ std::vector<std::string> ret;
+
+ PluginTagList::const_iterator pt;
+ for (pt = ptags.begin(); pt != ptags.end(); ++pt) {
+ if ((*pt).tags.empty ()) {
+ continue;
+ }
+
+ /* if favorites_only then we need to check the info ptr and maybe skip */
+ if (favorites_only) {
+ PluginStatus stat ((*pt).type, (*pt).unique_id);
+ PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), stat);
+ if ((i != statuses.end()) && (i->status == Favorite)) {
+ /* it's a favorite! */
+ } else {
+ continue;
+ }
+ }
+
+ /* parse each plugin's tag string into separate tags */
+ vector<string> tags;
+ if (!PBD::tokenize ((*pt).tags, string(" "), std::back_inserter (tags), true)) {
+#ifndef NDEBUG
+ cerr << _("PluginManager: Could not tokenize string: ") << (*pt).tags << endmsg;
+#endif
+ continue;
+ }
+
+ /* maybe add the tags we've found */
+ for (vector<string>::iterator t = tags.begin(); t != tags.end(); ++t) {
+ /* if this tag isn't already in the list, add it */
+ vector<string>::iterator i = find (ret.begin(), ret.end(), *t);
+ if (i == ret.end()) {
+ ret.push_back (*t);
+ }
+ }