GenericUI: subscribe to property changes before querying values
[ardour.git] / gtk2_ardour / plugin_selector.cc
index a38ad7d2e06a3cf210c7c2def9e9260ca3f1d527..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"
 
 #include "plugin_selector.h"
 #include "gui_thread.h"
-#include "tooltips.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 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"),
@@ -83,6 +85,8 @@ PluginSelector::PluginSelector (PluginManager& mgr)
 
        manager.PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
        manager.PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::refill, this), gui_context());
+       manager.PluginStatusesChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
+       manager.PluginStatusesChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::refill, this), gui_context());
        build_plugin_menu ();
 
        plugin_model = Gtk::ListStore::create (plugin_columns);
@@ -105,6 +109,11 @@ PluginSelector::PluginSelector (PluginManager& mgr)
        plugin_display.set_headers_clickable (true);
        plugin_display.set_reorderable (false);
        plugin_display.set_rules_hint (true);
+       plugin_display.add_object_drag (plugin_columns.plugin.index(), "PluginInfoPtr");
+       plugin_display.set_drag_column (plugin_columns.name.index());
+
+       // setting a sort-column prevents re-ordering via Drag/Drop
+       plugin_model->set_sort_column (plugin_columns.name.index(), Gtk::SORT_ASCENDING);
 
        CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
        fav_cell->property_activatable() = true;
@@ -203,18 +212,29 @@ PluginSelector::PluginSelector (PluginManager& mgr)
 
        filter_frame->show_all ();
 
+       HBox* side_by_side = manage (new HBox);
+       VBox* right_side = manage (new VBox);
+
        table->attach (scroller, 0, 7, 0, 5);
        table->attach (*filter_frame, 0, 7, 6, 7, FILL|EXPAND, FILL, 5, 5);
-       table->attach(*btn_add, 1, 2, 7, 8, FILL, FILL, 5, 5);
-       table->attach(*btn_remove, 5, 6, 7, 8, FILL, FILL, 5, 5);
 
-       table->attach(ascroller, 0, 7, 8, 10);
+       right_side->pack_start (ascroller);
+
+       HBox* add_remove = manage (new HBox);
+       add_remove->pack_start (*btn_add, true, true);
+       add_remove->pack_start (*btn_remove, true, true);
+
+       right_side->pack_start (*add_remove, false, false);
+       right_side->set_size_request (200, -1);
+
+       side_by_side->pack_start (*table);
+       side_by_side->pack_start (*right_side);
 
        add_button (Stock::CLOSE, RESPONSE_CLOSE);
        add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
        set_default_response (RESPONSE_APPLY);
        set_response_sensitive (RESPONSE_APPLY, false);
-       get_vbox()->pack_start (*table);
+       get_vbox()->pack_start (*side_by_side);
 
        table->set_name("PluginSelectorTable");
        plugin_display.set_name("PluginSelectorDisplay");
@@ -251,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)
 {
@@ -272,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;
        }
 
@@ -287,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) {
@@ -323,6 +353,12 @@ 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;
                        }
 
                } else if (mode == _("Author contains")) {
@@ -369,7 +405,9 @@ PluginSelector::refill ()
        lv2_refiller (filterstr);
        vst_refiller (filterstr);
        lxvst_refiller (filterstr);
+       mac_vst_refiller (filterstr);
        au_refiller (filterstr);
+       lua_refiller (filterstr);
 
        in_row_change = false;
 }
@@ -393,18 +431,23 @@ PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filte
                        string creator = (*i)->creator;
                        string::size_type pos = 0;
 
-                       /* stupid LADSPA creator strings */
+                       if ((*i)->type == ARDOUR::LADSPA) {
+                               /* stupid LADSPA creator strings */
 #ifdef PLATFORM_WINDOWS
-                       while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+                               while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
 #else
-                       while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+                               while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
 #endif
+                       } else {
+                               pos = creator.length ();
+                       }
                        // If there were too few characters to create a
                        // meaningful name, mark this creator as 'Unknown'
-                       if (creator.length()<2 || pos<3)
+                       if (creator.length() < 2 || pos < 3) {
                                creator = "Unknown";
-                       else
+                       } else{
                                creator = creator.substr (0, pos);
+                       }
 
                        newrow[plugin_columns.creator] = creator;
 
@@ -436,6 +479,12 @@ PluginSelector::ladspa_refiller (const std::string& filterstr)
        refiller (manager.ladspa_plugin_info(), filterstr, "LADSPA");
 }
 
+void
+PluginSelector::lua_refiller (const std::string& filterstr)
+{
+       refiller (manager.lua_plugin_info(), filterstr, "Lua");
+}
+
 void
 PluginSelector::lv2_refiller (const std::string& filterstr)
 {
@@ -468,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)
@@ -561,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;
 
@@ -630,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 */
@@ -696,12 +757,16 @@ PluginSelector::build_plugin_menu ()
        PluginInfoList all_plugs;
 
        all_plugs.insert (all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
+       all_plugs.insert (all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
 #ifdef WINDOWS_VST_SUPPORT
        all_plugs.insert (all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
 #endif
 #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
@@ -732,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)
 {
@@ -745,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);
                }
@@ -773,23 +867,25 @@ PluginSelector::create_by_creator_menu (ARDOUR::PluginInfoList& all_plugs)
                if (manager.get_status (*i) == PluginManager::Hidden) continue;
 
                string creator = (*i)->creator;
-
-               /* stupid LADSPA creator strings */
                string::size_type pos = 0;
+
+               if ((*i)->type == ARDOUR::LADSPA) {
+                       /* stupid LADSPA creator strings */
 #ifdef PLATFORM_WINDOWS
-               while (pos < creator.length() && creator[pos]>(-2) && creator[pos]<256 && (isprint (creator[pos]))) ++pos;
+                       while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
 #else
-               while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+                       while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
 #endif
+               } else {
+                       pos = creator.length ();
+               }
 
-               // Check to see if we found any invalid characters.
-               if (creator.length() != pos) {
-                       // If there were too few characters to create a
-                       // meaningful name, mark this creator as 'Unknown'
-                       if (pos<3)
-                               creator = "Unknown?";
-                       else
-                               creator = creator.substr (0, pos);
+               // If there were too few characters to create a
+               // meaningful name, mark this creator as 'Unknown'
+               if (creator.length() < 2 || pos < 3) {
+                       creator = "Unknown";
+               } else{
+                       creator = creator.substr (0, pos);
                }
 
                SubmenuMap::iterator x;
@@ -802,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);
        }
@@ -840,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);
        }
@@ -955,6 +1053,12 @@ static Gtkmm2ext::ActiveState next_state (Gtkmm2ext::ActiveState s){
                        break;
                default: assert(0); break; // not reached
        }
+       /* impossible, but keep some compiles happy */
+       fatal << string_compose (_("programming error: %1"),
+                       X_("Illegal Active State."))
+               << endmsg;
+       abort(); /*NOTREACHED*/
+       return Gtkmm2ext::Off;
 }
 
 static Gtkmm2ext::ActiveState prev_state (Gtkmm2ext::ActiveState s){
@@ -970,6 +1074,12 @@ static Gtkmm2ext::ActiveState prev_state (Gtkmm2ext::ActiveState s){
                        break;
                default: assert(0); break; // not reached
        }
+       /* impossible, but keep some compiles happy */
+       fatal << string_compose (_("programming error: %1"),
+                       X_("Illegal Active State."))
+               << endmsg;
+       abort(); /*NOTREACHED*/
+       return Gtkmm2ext::Off;
 }
 
 bool