GenericUI: subscribe to property changes before querying values
[ardour.git] / gtk2_ardour / plugin_selector.cc
index 3a0fed0d67851e0e1effdb6bde010903ec70d3be..0a609eb9cda85bcf3834d45b7bc49bc508c69d69 100644 (file)
 
 #include <algorithm>
 
-#include <gtkmm/table.h>
-#include <gtkmm/stock.h>
 #include <gtkmm/button.h>
+#include <gtkmm/comboboxtext.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/messagedialog.h>
 #include <gtkmm/notebook.h>
+#include <gtkmm/stock.h>
+#include <gtkmm/table.h>
 
-#include <gtkmm2ext/utils.h>
-
+#include "gtkmm2ext/utils.h"
 #include "pbd/convert.h"
+#include "widgets/tooltips.h"
 
 #include "ardour/plugin_manager.h"
 #include "ardour/plugin.h"
@@ -40,7 +43,6 @@
 
 #include "plugin_selector.h"
 #include "gui_thread.h"
-#include "tooltips.h"
 
 #include "pbd/i18n.h"
 
@@ -48,7 +50,7 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace Gtk;
 using namespace std;
-using namespace ARDOUR_UI_UTILS;
+using namespace ArdourWidgets;
 
 static const char* _filter_mode_strings[] = {
        N_("Name contains"),
@@ -269,6 +271,16 @@ PluginSelector::added_row_clicked(GdkEventButton* event)
                btn_remove_clicked();
 }
 
+static bool is_analyzer (const PluginInfoPtr& info) {
+       // Anaylsis, Analyzer are for backwards compatibility (vst cache)
+       return info->in_category ("Analyser") || info->in_category ("Anaylsis") ||  info->in_category ("Analyzer");
+}
+
+static bool is_util (const PluginInfoPtr& info) {
+       // all MIDI plugins which are not Instruments are Utils.
+       return info->in_category ("Utility") || info->in_category ("MIDI") || info->in_category ("Generator");
+}
+
 bool
 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& filterstr)
 {
@@ -290,10 +302,10 @@ PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string&
        if (_show_instruments == Gtkmm2ext::Off && info->is_instrument()) {
                return false;
        }
-       if (_show_analysers == Gtkmm2ext::Off && info->in_category ("Analyser")) {
+       if (_show_analysers == Gtkmm2ext::Off && is_analyzer (info)) {
                return false;
        }
-       if (_show_utils == Gtkmm2ext::Off && info->in_category ("Utility")) {
+       if (_show_utils == Gtkmm2ext::Off && is_util (info)) {
                return false;
        }
 
@@ -305,10 +317,10 @@ PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string&
        if (_show_instruments == Gtkmm2ext::ExplicitActive && info->is_instrument()) {
                exp_ok = true;
        }
-       if (_show_analysers == Gtkmm2ext::ExplicitActive && info->in_category ("Analyser")) {
+       if (_show_analysers == Gtkmm2ext::ExplicitActive && is_analyzer(info)) {
                exp_ok = true;
        }
-       if (_show_utils == Gtkmm2ext::ExplicitActive && info->in_category ("Utility")) {
+       if (_show_utils == Gtkmm2ext::ExplicitActive && is_util (info)) {
                exp_ok = true;
        }
        if (_show_instruments == Gtkmm2ext::ExplicitActive  || _show_analysers == Gtkmm2ext::ExplicitActive || _show_utils == Gtkmm2ext::ExplicitActive) {
@@ -341,6 +353,9 @@ PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string&
                        case LXVST:
                                compstr = X_("LXVST");
                                break;
+                       case MacVST:
+                               compstr = X_("MacVST");
+                               break;
                        case Lua:
                                compstr = X_("Lua");
                                break;
@@ -390,6 +405,7 @@ PluginSelector::refill ()
        lv2_refiller (filterstr);
        vst_refiller (filterstr);
        lxvst_refiller (filterstr);
+       mac_vst_refiller (filterstr);
        au_refiller (filterstr);
        lua_refiller (filterstr);
 
@@ -501,6 +517,18 @@ PluginSelector::lxvst_refiller (const std::string&)
 #endif
 }
 
+void
+#ifdef MACVST_SUPPORT
+PluginSelector::mac_vst_refiller (const std::string& filterstr)
+#else
+PluginSelector::mac_vst_refiller (const std::string&)
+#endif
+{
+#ifdef MACVST_SUPPORT
+       refiller (manager.mac_vst_plugin_info(), filterstr, "MacVST");
+#endif
+}
+
 void
 #ifdef AUDIOUNIT_SUPPORT
 PluginSelector::au_refiller (const std::string& filterstr)
@@ -594,14 +622,14 @@ PluginSelector::run ()
                                PluginPtr p = load_plugin (pp);
                                if (p) {
                                        plugins.push_back (p);
-                                } else {
-                                        MessageDialog msg (string_compose (_("The plugin \"%1\" could not be loaded\n\nSee the Log window for more details (maybe)"), pp->name));
-                                        msg.run ();
-                                }
+                               } else {
+                                       MessageDialog msg (string_compose (_("The plugin \"%1\" could not be loaded\n\nSee the Log window for more details (maybe)"), pp->name));
+                                       msg.run ();
+                               }
                        }
                        if (interested_object && !plugins.empty()) {
                                finish = !interested_object->use_plugins (plugins);
-                        }
+                       }
 
                        break;
 
@@ -663,57 +691,57 @@ PluginSelector::on_show ()
 }
 
 struct PluginMenuCompareByCreator {
-    bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
-           int cmp;
-
-           cmp = cmp_nocase_utf8 (a->creator, b->creator);
-
-           if (cmp < 0) {
-                   return true;
-           } else if (cmp == 0) {
-                   /* same creator ... compare names */
-                   if (cmp_nocase_utf8 (a->name, b->name) < 0) {
-                           return true;
-                   }
-           }
-           return false;
-    }
+       bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+               int cmp;
+
+               cmp = cmp_nocase_utf8 (a->creator, b->creator);
+
+               if (cmp < 0) {
+                       return true;
+               } else if (cmp == 0) {
+                       /* same creator ... compare names */
+                       if (cmp_nocase_utf8 (a->name, b->name) < 0) {
+                               return true;
+                       }
+               }
+               return false;
+       }
 };
 
 struct PluginMenuCompareByName {
-    bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
-           int cmp;
-
-           cmp = cmp_nocase_utf8 (a->name, b->name);
-
-           if (cmp < 0) {
-                   return true;
-           } else if (cmp == 0) {
-                   /* same name ... compare type */
-                   if (a->type < b->type) {
-                           return true;
-                   }
-           }
-           return false;
-    }
+       bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+               int cmp;
+
+               cmp = cmp_nocase_utf8 (a->name, b->name);
+
+               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 = cmp_nocase_utf8 (a->category, b->category);
-
-           if (cmp < 0) {
-                   return true;
-           } else if (cmp == 0) {
-                   /* same category ... compare names */
-                   if (cmp_nocase_utf8 (a->name, b->name) < 0) {
-                           return true;
-                   }
-           }
-           return false;
-    }
+       bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+               int cmp;
+
+               cmp = cmp_nocase_utf8 (a->category, b->category);
+
+               if (cmp < 0) {
+                       return true;
+               } else if (cmp == 0) {
+                       /* same category ... compare names */
+                       if (cmp_nocase_utf8 (a->name, b->name) < 0) {
+                               return true;
+                       }
+               }
+               return false;
+       }
 };
 
 /** @return Plugin menu. The caller should not delete it */
@@ -736,6 +764,9 @@ PluginSelector::build_plugin_menu ()
 #ifdef LXVST_SUPPORT
        all_plugs.insert (all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
 #endif
+#ifdef MACVST_SUPPORT
+       all_plugs.insert (all_plugs.end(), manager.mac_vst_plugin_info().begin(), manager.mac_vst_plugin_info().end());
+#endif
 #ifdef AUDIOUNIT_SUPPORT
        all_plugs.insert (all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
 #endif
@@ -766,6 +797,34 @@ PluginSelector::build_plugin_menu ()
        items.push_back (MenuElem (_("By Category"), *manage (by_category)));
 }
 
+string
+GetPluginTypeStr(PluginInfoPtr info)
+{
+       string type;
+       
+       switch (info->type) {
+       case LADSPA:
+               type = X_(" (LADSPA)");
+               break;
+       case AudioUnit:
+               type = X_(" (AU)");
+               break;
+       case LV2:
+               type = X_(" (LV2)");
+               break;
+       case Windows_VST:
+       case LXVST:
+       case MacVST:
+               type = X_(" (VST)");
+               break;
+       case Lua:
+               type = X_(" (Lua)");
+               break;
+       }
+       
+       return type;
+}
+
 Gtk::Menu*
 PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
 {
@@ -779,7 +838,8 @@ PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
 
        for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
                if (manager.get_status (*i) == PluginManager::Favorite) {
-                       MenuElem elem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
+                       string typ = GetPluginTypeStr(*i);
+                       MenuElem elem ((*i)->name + typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
                        elem.get_child()->set_use_underline (false);
                        favs->items().push_back (elem);
                }
@@ -838,7 +898,8 @@ PluginSelector::create_by_creator_menu (ARDOUR::PluginInfoList& all_plugs)
                        creator_submenu_map.insert (pair<std::string,Menu*> (creator, submenu));
                        submenu->set_name("ArdourContextMenu");
                }
-               MenuElem elem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
+               string typ = GetPluginTypeStr(*i);
+               MenuElem elem ((*i)->name+typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
                elem.get_child()->set_use_underline (false);
                submenu->items().push_back (elem);
        }
@@ -876,7 +937,8 @@ PluginSelector::create_by_category_menu (ARDOUR::PluginInfoList& all_plugs)
                        category_submenu_map.insert (pair<std::string,Menu*> (category, submenu));
                        submenu->set_name("ArdourContextMenu");
                }
-               MenuElem elem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
+               string typ = GetPluginTypeStr(*i);
+               MenuElem elem ((*i)->name + typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
                elem.get_child()->set_use_underline (false);
                submenu->items().push_back (elem);
        }