+struct PluginMenuCompareByCreator {
+ bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+ int cmp;
+
+ cmp = strcasecmp (a->creator.c_str(), b->creator.c_str());
+
+ if (cmp < 0) {
+ return true;
+ } else if (cmp == 0) {
+ /* same creator ... compare names */
+ if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+struct PluginMenuCompareByName {
+ bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+ int cmp;
+
+ cmp = strcasecmp (a->name.c_str(), b->name.c_str());
+
+ if (cmp < 0) {
+ return true;
+ } else if (cmp == 0) {
+ /* same name ... compare type */
+ if (a->type < b->type) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+struct PluginMenuCompareByCategory {
+ bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+ int cmp;
+
+ cmp = strcasecmp (a->category.c_str(), b->category.c_str());
+
+ if (cmp < 0) {
+ return true;
+ } else if (cmp == 0) {
+ /* same category ... compare names */
+ if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+/** @return Plugin menu. The caller should not delete it */
+Gtk::Menu*
+PluginSelector::plugin_menu()
+{
+ return _plugin_menu;
+}
+
+void
+PluginSelector::build_plugin_menu ()
+{
+ PluginInfoList all_plugs;
+
+ all_plugs.insert (all_plugs.end(), manager->ladspa_plugin_info().begin(), manager->ladspa_plugin_info().end());
+#ifdef VST_SUPPORT
+ all_plugs.insert (all_plugs.end(), manager->vst_plugin_info().begin(), manager->vst_plugin_info().end());
+#endif
+#ifdef HAVE_AUDIOUNITS
+ all_plugs.insert (all_plugs.end(), manager->au_plugin_info().begin(), manager->au_plugin_info().end());
+#endif
+#ifdef HAVE_SLV2
+ all_plugs.insert (all_plugs.end(), manager->lv2_plugin_info().begin(), manager->lv2_plugin_info().end());
+#endif
+
+ using namespace Menu_Helpers;
+
+ delete _plugin_menu;
+
+ _plugin_menu = manage (new Menu);
+ _plugin_menu->set_name("ArdourContextMenu");
+
+ MenuList& items = _plugin_menu->items();
+ items.clear ();
+
+ Gtk::Menu* favs = create_favs_menu(all_plugs);
+ items.push_back (MenuElem (_("Favorites"), *manage (favs)));
+
+ items.push_back (MenuElem (_("Plugin Manager"), sigc::mem_fun (*this, &PluginSelector::show_manager)));
+ items.push_back (SeparatorElem ());
+
+ Menu* by_creator = create_by_creator_menu(all_plugs);
+ items.push_back (MenuElem (_("By Creator"), *manage (by_creator)));
+
+ Menu* by_category = create_by_category_menu(all_plugs);
+ items.push_back (MenuElem (_("By Category"), *manage (by_category)));
+}
+
+Gtk::Menu*
+PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
+{
+ using namespace Menu_Helpers;
+
+ Menu* favs = new Menu();
+ favs->set_name("ArdourContextMenu");
+
+ PluginMenuCompareByName cmp_by_name;
+ all_plugs.sort (cmp_by_name);
+
+ for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
+ if (manager->get_status (*i) == PluginManager::Favorite) {
+ favs->items().push_back (MenuElem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));