Patch from jdavisp3 to fix bug #1841.
[ardour.git] / gtk2_ardour / plugin_selector.cc
index c6b41a66038376925d0272232e1f585e6c8155fc..0b96adf6822272f15b3eded606c00951c32a44a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2000-2006 Paul Davis 
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include <cstdio>
 #include <lrdf.h>
 
+#include <algorithm>
+
 #include <gtkmm/table.h>
+#include <gtkmm/stock.h>
 #include <gtkmm/button.h>
 #include <gtkmm/notebook.h>
-#include <gtkmm/ctree.h>
+
+#include <gtkmm2ext/utils.h>
+
+#include <pbd/convert.h>
 
 #include <ardour/plugin_manager.h>
 #include <ardour/plugin.h>
 #include "i18n.h"
 
 using namespace ARDOUR;
-
-static const gchar *i_titles[] = {
-       N_("Available LADSPA plugins"), 
-       N_("Type"),
-       N_("# Inputs"), 
-       N_("# Outputs"),
-       0
-};
-
-#ifdef VST_SUPPORT
-static const gchar *vst_titles[] = {
-       N_("Available VST plugins"), 
-       N_("# Inputs"), 
-       N_("# Outputs"),
-       0
-};
-#endif
-
-static const gchar *o_titles[] = {
-       N_("To be added"),
+using namespace PBD;
+using namespace Gtk;
+using namespace std;
+
+static const char* _filter_mode_strings[] = {
+       N_("Name contains"),
+       N_("Type contains"),
+       N_("Author contains"),
+       N_("Library contains"),
        0
 };
 
 PluginSelector::PluginSelector (PluginManager *mgr)
-       : ArdourDialog ("plugin selector"),
-         ladspa_display (_input_refiller, this, internationalize (i_titles), false, true),
-#ifdef VST_SUPPORT
-        vst_display (_vst_refiller, this, internationalize (vst_titles), false, true),
-#endif
-         o_selector (_output_refiller, this, internationalize (o_titles), false, true)
+       : ArdourDialog (_("ardour: plugins"), true, false),
+         filter_button (Stock::CLEAR)
 {
        set_position (Gtk::WIN_POS_MOUSE);
        set_name ("PluginSelectorWindow");
-       set_title (_("ardour: plugins"));
-       set_modal(true);
        add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
 
        manager = mgr;
        session = 0;
-       o_selected_plug = -1;
-       i_selected_plug = 0;
+       
+       current_selection = ARDOUR::LADSPA;
+
+       lmodel = Gtk::ListStore::create(lcols);
+       ladspa_display.set_model (lmodel);
+       ladspa_display.append_column (_("Available LADSPA Plugins"), lcols.name);
+       ladspa_display.append_column (_("Type"), lcols.type);
+       ladspa_display.append_column (_("# Inputs"),lcols.ins);
+       ladspa_display.append_column (_("# Outputs"), lcols.outs);
+       ladspa_display.set_headers_visible (true);
+       ladspa_display.set_headers_clickable (true);
+       ladspa_display.set_reorderable (false);
+       lscroller.set_border_width(10);
+       lscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       lscroller.add(ladspa_display);
+
+       amodel = Gtk::ListStore::create(acols);
+       added_list.set_model (amodel);
+       added_list.append_column (_("Plugins to be connected"), acols.text);
+       added_list.set_headers_visible (true);
+       added_list.set_reorderable (false);
+
+       for (int i = 0; i <=3; i++) {
+               Gtk::TreeView::Column* column = ladspa_display.get_column(i);
+               column->set_sort_column(i);
+       }
+
+#ifdef VST_SUPPORT
+       vmodel = ListStore::create(vcols);
+       vst_display.set_model (vmodel);
+       vst_display.append_column (_("Available plugins"), vcols.name);
+       vst_display.append_column (_("# Inputs"), vcols.ins);
+       vst_display.append_column (_("# Outputs"), vcols.outs);
+       vst_display.set_headers_visible (true);
+       vst_display.set_headers_clickable (true);
+       vst_display.set_reorderable (false);
+       vscroller.set_border_width(10);
+       vscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       vscroller.add(vst_display);
+
+       for (int i = 0; i <=2; i++) {
+               Gtk::TreeView::Column* column = vst_display.get_column(i);
+               column->set_sort_column(i);
+       }
+#endif
+
+#ifdef HAVE_AUDIOUNIT
+       aumodel = ListStore::create(aucols);
+       au_display.set_model (aumodel);
+       au_display.append_column (_("Available plugins"), aucols.name);
+       au_display.append_column (_("# Inputs"), aucols.ins);
+       au_display.append_column (_("# Outputs"), aucols.outs);
+       au_display.set_headers_visible (true);
+       au_display.set_headers_clickable (true);
+       au_display.set_reorderable (false);
+       auscroller.set_border_width(10);
+       auscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       auscroller.add(au_display);
+
+       for (int i = 0; i <=2; i++) {
+               Gtk::TreeView::Column* column = au_display.get_column(i);
+               column->set_sort_column(i);
+       }
+#endif
 
-       Gtk::Button *btn_add = manage(new Gtk::Button(_("Add")));
+       ascroller.set_border_width(10);
+       ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       ascroller.add(added_list);
+       btn_add = manage(new Gtk::Button(Stock::ADD));
        ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
-       Gtk::Button *btn_remove = manage(new Gtk::Button(_("Remove")));
+       btn_add->set_sensitive (false);
+       btn_remove = manage(new Gtk::Button(Stock::REMOVE));
+       btn_remove->set_sensitive (false);
        ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
-       Gtk::Button *btn_ok = manage(new Gtk::Button(_("OK")));
-       Gtk::Button *btn_cancel = manage(new Gtk::Button(_("Cancel")));
-
-       Gtk::Button *btn_update = manage(new Gtk::Button(_("Update")));
+       Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
        ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
 
-       btn_ok->set_name("PluginSelectorButton");
-       btn_cancel->set_name("PluginSelectorButton");
        btn_add->set_name("PluginSelectorButton");
        btn_remove->set_name("PluginSelectorButton");
-       
-       Gtk::Table* table = manage(new Gtk::Table(7, 10));
+
+       Gtk::Table* table = manage(new Gtk::Table(7, 11));
        table->set_size_request(750, 500);
        table->attach(notebook, 0, 7, 0, 5);
 
-       table->attach(*btn_add, 1, 2, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
-       table->attach(*btn_remove, 3, 4, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
-       table->attach(*btn_update, 5, 6, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
+       HBox* filter_box = manage (new HBox);
+
+       vector<string> filter_strings = I18N (_filter_mode_strings);
+       Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
+       filter_mode.set_active_text (filter_strings.front());
+
+       filter_box->pack_start (filter_mode, false, false);
+       filter_box->pack_start (filter_entry, true, true);
+       filter_box->pack_start (filter_button, false, false);
+
+       filter_entry.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_entry_changed));
+       filter_button.signal_clicked().connect (mem_fun (*this, &PluginSelector::filter_button_clicked));
+       filter_mode.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_mode_changed));
+
+       filter_box->show ();
+       filter_mode.show ();
+       filter_entry.show ();
+       filter_button.show ();
+
+       table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
+
+       table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5); 
+       table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
+       table->attach(*btn_update, 5, 6, 6, 7, FILL, FILL, 5, 5);
 
-       table->attach(o_selector, 0, 7, 7, 9);
-       table->attach(*btn_ok, 1, 3, 9, 10, Gtk::FILL, Gtk::FILL, 5, 5);
-       table->attach(*btn_cancel, 3, 4, 9, 10, Gtk::FILL, Gtk::FILL, 5, 5);
-       add (*table);
+       table->attach(ascroller, 0, 7, 8, 10);
+
+       add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       add_button (Stock::CONNECT, RESPONSE_APPLY);
+       set_default_response (RESPONSE_APPLY);
+       set_response_sensitive (RESPONSE_APPLY, false);
+       get_vbox()->pack_start (*table);
+
+
+       // Notebook tab order must be the same in here as in set_correct_focus()
+       using namespace Notebook_Helpers;
+       notebook.pages().push_back (TabElem (lscroller, _("LADSPA")));
 
-       using namespace Gtk::Notebook_Helpers;
-       notebook.pages().push_back (TabElem (ladspa_display, _("LADSPA")));
 #ifdef VST_SUPPORT
        if (Config->get_use_vst()) {
-               notebook.pages().push_back (TabElem (vst_display, _("VST")));
+               notebook.pages().push_back (TabElem (vscroller, _("VST")));
        }
 #endif
 
-       table->set_name("PluginSelectorTable");
-       //ladspa_display.set_name("PluginSelectorDisplay");
-       ladspa_display.clist().set_name("PluginSelectorList");
-       o_selector.clist().set_name("PluginSelectorList");
-       
-       ladspa_display.clist().column_titles_active();
-       ladspa_display.clist().column(0).set_auto_resize (false);
-       ladspa_display.clist().column(0).set_width(470);
+#ifdef HAVE_AUDIOUNIT
+       notebook.pages().push_back (TabElem (auscroller, _("AudioUnit")));
+#endif
 
-       ladspa_display.clist().column(1).set_auto_resize (true);
-       o_selector.clist().column(0).set_auto_resize (true);
+       table->set_name("PluginSelectorTable");
+       ladspa_display.set_name("PluginSelectorDisplay");
+       //ladspa_display.set_name("PluginSelectorList");
+       added_list.set_name("PluginSelectorList");
 
-       ladspa_display.selection_made.connect (mem_fun(*this, &PluginSelector::i_plugin_selected));
-       ladspa_display.choice_made.connect(mem_fun(*this, &PluginSelector::i_plugin_chosen));
-       ladspa_display.clist().click_column.connect(bind (mem_fun(*this, &PluginSelector::column_clicked), ladspa_display.clist().gobj()));
+       ladspa_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
+       ladspa_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::ladspa_display_selection_changed));
+       ladspa_display.grab_focus();
+       
 #ifdef VST_SUPPORT
        if (Config->get_use_vst()) {
-               vst_display.selection_made.connect (mem_fun(*this, &PluginSelector::i_plugin_selected));
-               vst_display.choice_made.connect(mem_fun(*this, &PluginSelector::i_plugin_chosen));
-               vst_display.clist().click_column.connect(bind (mem_fun(*this, &PluginSelector::column_clicked), vst_display.clist().gobj()));
+               vst_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
+               vst_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::vst_display_selection_changed));
        }
 #endif
-       o_selector.selection_made.connect(mem_fun(*this, &PluginSelector::o_plugin_selected));
-       o_selector.choice_made.connect(mem_fun(*this,&PluginSelector::o_plugin_chosen));
+
+#ifdef HAVE_AUDIOUNIT
+       au_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
+       au_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::au_display_selection_changed));
+#endif
+
        btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
-       btn_add->clicked.connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
+       btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
        btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
-       btn_ok->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_ok_clicked));
-       btn_cancel->signal_clicked().connect(mem_fun(*this,&PluginSelector::btn_cancel_clicked));
-       signal_delete_event().connect (mem_fun(*this, &PluginSelector::wm_close));
+       added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
+
+       ladspa_refiller ();
+       
+#ifdef VST_SUPPORT
+       vst_refiller ();
+#endif
 
+#ifdef HAVE_AUDIOUNIT
+       au_refiller ();
+#endif
+
+       signal_show().connect (mem_fun (*this, &PluginSelector::set_correct_focus));
 }
 
+/**
+ * Makes sure keyboard focus is always in the plugin list
+ * of the selected notebook tab.
+ **/
 void
-PluginSelector::set_session (Session* s)
+PluginSelector::set_correct_focus()
 {
-       ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
+       int cp = notebook.get_current_page();
+
+       if (cp == 0) {
+               ladspa_display.grab_focus();
+               return;
+       }
+
+#ifdef VST_SUPPORT
+       if (Config->get_use_vst()) {
+               cp--;
        
-       session = s;
+               if (cp == 0) {
+                       vst_display.grab_focus();
+                       return;
+               }
+       }
+#endif
 
-       if (session) {
-               session->going_away.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
+#ifdef HAVE_AUDIOUNIT
+       cp--;
+
+       if (cp == 0) {
+               au_display.grab_focus();
+               return;
        }
+#endif
 }
 
 void
-PluginSelector::_input_refiller (Gtk::CList &list, void *arg)
+PluginSelector::row_clicked(GdkEventButton* event)
 {
-       ((PluginSelector *) arg)->input_refiller (list);
+       if (event->type == GDK_2BUTTON_PRESS)
+               btn_add_clicked();
 }
 
 void
-PluginSelector::_output_refiller (Gtk::CList &list, void *arg)
+PluginSelector::set_session (Session* s)
 {
-       ((PluginSelector *) arg)->output_refiller (list);
-}
+       ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
+       
+       session = s;
 
-int compare(const void *left, const void *right)
-{
-  return strcmp(*((char**)left), *((char**)right));
+       if (session) {
+               session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
+       }
 }
 
-void
-PluginSelector::input_refiller (Gtk::CList &clist)
+bool
+PluginSelector::show_this_plugin (PluginInfoPtr& info, const std::string& filterstr)
 {
-       const gchar *rowdata[4];
-       guint row;
-       list<PluginInfo *> &plugs = manager->ladspa_plugin_info ();
-       list<PluginInfo *>::iterator i;
-       char ibuf[16], obuf[16];
-       
-       // Insert into GTK list
-       for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
-               rowdata[0] = (*i)->name.c_str();
-               rowdata[1] = (*i)->category.c_str();
+       std::string compstr;
+       std::string mode = filter_mode.get_active_text ();
 
-               snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
-               snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);         
-               rowdata[2] = ibuf;
-               rowdata[3] = obuf;
+       if (!filterstr.empty()) {
+               
+               if (mode == _("Name contains")) {
+                       compstr = info->name;
+               } else if (mode == _("Type contains")) {
+                       compstr = info->category;
+               } else if (mode == _("Author contains")) {
+                       compstr = info->creator;
+               } else if (mode == _("Library contains")) {
+                       compstr = info->path;
+               }
+               
+               transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
+
+               if (compstr.find (filterstr) != string::npos) {
+                       return true;
+               } else {
+                       return false;
+               }
                
-               clist.insert_row (row, rowdata);
-               clist.rows().back().set_data (*i);
        }
 
-       clist.set_sort_column (0);
-       clist.sort ();
+       return true;
 }
 
-#ifdef VST_SUPPORT
-
 void
-PluginSelector::_vst_refiller (Gtk::CList &list, void *arg)
+PluginSelector::setup_filter_string (string& filterstr)
 {
-       ((PluginSelector *) arg)->vst_refiller (list);
-}
+       filterstr = filter_entry.get_text ();
+       transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
+}      
 
 void
-PluginSelector::vst_refiller (Gtk::CList &clist)
+PluginSelector::ladspa_refiller ()
 {
-       const gchar *rowdata[3];
        guint row;
-       list<PluginInfo *> &plugs = manager->vst_plugin_info ();
-       list<PluginInfo *>::iterator i;
+       PluginInfoList &plugs = manager->ladspa_plugin_info ();
+       PluginInfoList::iterator i;
        char ibuf[16], obuf[16];
-       
-       if (!Config->get_use_vst()) {
-               return;
-       }
 
-       // Insert into GTK list
+       lmodel->clear();
 
-       for (row = 0, i = plugs.begin(); i != plugs.end(); ++i, ++row) {
-               rowdata[0] = (*i)->name.c_str();
-
-               snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
-               snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);         
-               rowdata[1] = ibuf;
-               rowdata[2] = obuf;
-               
-               clist.insert_row (row, rowdata);
-               clist.rows().back().set_data (*i);
+       std::string filterstr;
+       setup_filter_string (filterstr);
+       
+       for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
+               if (show_this_plugin (*i, filterstr)) {
+                       snprintf (ibuf, sizeof(ibuf)-1, "%u", (*i)->n_inputs.n_total());
+                       snprintf (obuf, sizeof(obuf)-1, "%u", (*i)->n_outputs.n_total());               
+
+                       TreeModel::Row newrow = *(lmodel->append());
+                       newrow[lcols.name] = (*i)->name.c_str();
+                       newrow[lcols.type] = (*i)->category.c_str();
+                       newrow[lcols.ins] = ibuf;
+                       newrow[lcols.outs] = obuf;
+                       newrow[lcols.plugin] = *i;
+               }
        }
 
-       clist.set_sort_column (0);
-       clist.sort ();
+       lmodel->set_sort_column (0, SORT_ASCENDING);
 }
-#endif
+
+#ifdef VST_SUPPORT
 
 void
-PluginSelector::output_refiller (Gtk::CList &clist)
+PluginSelector::vst_refiller ()
 {
-       const gchar *rowdata[2];
        guint row;
-       list<PluginInfo*>::iterator i;
+       PluginInfoList &plugs = manager->vst_plugin_info ();
+       PluginInfoList::iterator i;
+       char ibuf[16], obuf[16];
+       vmodel->clear();
+       
+       std::string filterstr;
+       setup_filter_string (filterstr);
        
-       // Insert into GTK list
+       for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
 
-       for (row = 0, i = added_plugins.begin(); i != added_plugins.end(); ++i, ++row){
-               rowdata[0] = (*i)->name.c_str();
-               clist.insert_row (row, rowdata);
-               clist.rows().back().set_data (*i);
+               if (show_this_plugin (*i, filterstr)) {
+                       snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
+                       snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);         
+                       
+                       TreeModel::Row newrow = *(vmodel->append());
+                       newrow[vcols.name] = (*i)->name.c_str();
+                       newrow[vcols.ins] = ibuf;
+                       newrow[vcols.outs] = obuf;
+                       newrow[vcols.plugin] = *i;
+               }
        }
+       vmodel->set_sort_column (0, SORT_ASCENDING);
 }
 
 void
-PluginSelector::i_plugin_chosen (Gtkmm2ext::Selector *selector,
-                                Gtkmm2ext::SelectionResult *res)
+PluginSelector::vst_display_selection_changed()
 {
-       if (res) {
-               // get text for name column (0)
-               i_selected_plug = static_cast<PluginInfo*> (selector->clist().row(res->row).get_data());
-               //i_selected_plug = *res->text;
+       if (vst_display.get_selection()->count_selected_rows() != 0) {
+               btn_add->set_sensitive (true);
        } else {
-               i_selected_plug = 0;
+               btn_add->set_sensitive (false);
        }
-}
 
-void
-PluginSelector::i_plugin_selected (Gtkmm2ext::Selector *selector,
-                                  Gtkmm2ext::SelectionResult *res)
-{
-       if (res) {
-               added_plugins.push_back (static_cast<PluginInfo*> (selector->clist().row(res->row).get_data()));
-               //added_plugins.push_back(*(res->text));
-               o_selector.rescan();
-       }
+       current_selection = ARDOUR::VST;
 }
 
+#endif //VST_SUPPORT
+
+#ifdef HAVE_AUDIOUNIT
+
 void
-PluginSelector::o_plugin_chosen (Gtkmm2ext::Selector *selector,
-                             Gtkmm2ext::SelectionResult *res)
+PluginSelector::au_refiller ()
 {
-       if (res && res->text) {
-               o_selected_plug = res->row;
-       } else {
-               o_selected_plug = -1;
+       guint row;
+       PluginInfoList plugs (AUPluginInfo::discover ());
+       PluginInfoList::iterator i;
+       char ibuf[16], obuf[16];
+       aumodel->clear();
+       
+       std::string filterstr;
+       setup_filter_string (filterstr);
+       
+       for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
+
+               if (show_this_plugin (*i, filterstr)) {
+
+                       snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
+                       snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);         
+                       
+                       TreeModel::Row newrow = *(aumodel->append());
+                       newrow[aucols.name] = (*i)->name.c_str();
+                       newrow[aucols.ins] = ibuf;
+                       newrow[aucols.outs] = obuf;
+                       newrow[aucols.plugin] = *i;
+               }
        }
 
+       aumodel->set_sort_column (0, SORT_ASCENDING);
 }
 
 void
-PluginSelector::o_plugin_selected (Gtkmm2ext::Selector *selector,
-                               Gtkmm2ext::SelectionResult *res)
+PluginSelector::au_display_selection_changed()
 {
-       if(res && res->text){
-               gint row = 0;
-               list<PluginInfo*>::iterator i = added_plugins.begin();
-               while (row < res->row){
-                       i++;
-                       row++;
-               }
-               added_plugins.erase(i);
-               o_selector.rescan();
-               o_selected_plug = -1;
+       if (au_display.get_selection()->count_selected_rows() != 0) {
+               btn_add->set_sensitive (true);
+       } else {
+               btn_add->set_sensitive (false);
        }
+       
+       current_selection = ARDOUR::AudioUnit;
 }
 
+#endif //HAVE_AUDIOUNIT
+
 void
-PluginSelector::use_plugin (PluginInfo* pi)
+PluginSelector::use_plugin (PluginInfoPtr pi)
 {
-       list<PluginInfo *>::iterator i;
-
-       if (pi == 0 || session == 0) {
+       if (session == 0) {
                return;
        }
 
-       Plugin *plugin = manager->load (*session, pi);
+       PluginPtr plugin = pi->load (*session);
 
        if (plugin) {
                PluginCreated (plugin);
@@ -331,88 +464,143 @@ PluginSelector::use_plugin (PluginInfo* pi)
 void
 PluginSelector::btn_add_clicked()
 {
-       if (i_selected_plug) {
-               added_plugins.push_back (i_selected_plug);
-               o_selector.rescan();
+       std::string name;
+       PluginInfoPtr pi;
+       TreeModel::Row newrow = *(amodel->append());
+       
+       TreeModel::Row row;
+
+       switch (current_selection) {
+               case ARDOUR::LADSPA:
+                       row = *(ladspa_display.get_selection()->get_selected());
+                       name = row[lcols.name];
+                       pi = row[lcols.plugin];
+                       break;
+               case ARDOUR::VST:
+#ifdef VST_SUPPORT
+                       row = *(vst_display.get_selection()->get_selected());
+                       name = row[vcols.name];
+                       pi = row[vcols.plugin];
+#endif
+                       break;
+               case ARDOUR::AudioUnit:
+#ifdef HAVE_AUDIOUNIT
+                       row = *(au_display.get_selection()->get_selected());
+                       name = row[aucols.name];
+                       pi = row[aucols.plugin];
+#endif
+                       break;
+               default:
+                       error << "Programming error.  Unknown plugin selected." << endmsg;
+                       return;
+       }
+
+       newrow[acols.text] = name;
+       newrow[acols.plugin] = pi;
+
+       if (!amodel->children().empty()) {
+               set_response_sensitive (RESPONSE_APPLY, true);
        }
 }
 
 void
 PluginSelector::btn_remove_clicked()
 {
-       if (o_selected_plug > -1){
-               gint row = 0;
-               list<PluginInfo*>::iterator i = added_plugins.begin();
-               while(row < o_selected_plug){
-                       i++;
-                       row++;
-               }
-               added_plugins.erase(i);
-               o_selector.rescan();
-               o_selected_plug = -1;
+       TreeModel::iterator iter = added_list.get_selection()->get_selected();
+       
+       amodel->erase(iter);
+       if (amodel->children().empty()) {
+               set_response_sensitive (RESPONSE_APPLY, false);
        }
 }
 
-// Adds a plugin, and closes the window.
-void 
-PluginSelector::btn_ok_clicked()
+void
+PluginSelector::btn_update_clicked()
 {
-       using namespace Gtk::CList_Helpers;
+       manager->refresh ();
+       refill();
+}
 
-       list<PluginInfo*>::iterator i;
+void
+PluginSelector::refill()
+{
+       ladspa_refiller ();
+#ifdef VST_SUPPORT
+       vst_refiller ();
+#endif 
+#ifdef HAVE_AUDIOUNIT
+       au_refiller ();
+#endif
+}
 
-       for (i = added_plugins.begin(); i != added_plugins.end(); ++i){
-               use_plugin (*i);
+void
+PluginSelector::ladspa_display_selection_changed()
+{
+       if (ladspa_display.get_selection()->count_selected_rows() != 0) {
+               btn_add->set_sensitive (true);
+       } else {
+               btn_add->set_sensitive (false);
        }
+       
+       current_selection = ARDOUR::LADSPA;
+}
 
-       hide();
-       added_plugins.clear();
-       o_selector.rescan();
-       i_selected_plug = 0;
-       o_selected_plug = -1;
-
-       SelectionList s_list = ladspa_display.clist().selection();
-       SelectionList::iterator s = s_list.begin();
-       if (s != s_list.end()) {
-               (*s).unselect();
+void
+PluginSelector::added_list_selection_changed()
+{
+       if (added_list.get_selection()->count_selected_rows() != 0) {
+               btn_remove->set_sensitive (true);
+       } else {
+               btn_remove->set_sensitive (false);
        }
+}
 
-#ifdef VST_SUPPORT
-       SelectionList v_list = vst_display.clist().selection();
-       SelectionList::iterator v = v_list.begin();
-       if (v != v_list.end()) {
-               (*v).unselect();
+int
+PluginSelector::run ()
+{
+       ResponseType r;
+       TreeModel::Children::iterator i;
+
+       r = (ResponseType) Dialog::run ();
+
+       switch (r) {
+       case RESPONSE_APPLY:
+               for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
+                       use_plugin ((*i)[acols.plugin]);
+               }
+               break;
+
+       default:
+               break;
        }
-#endif
+
+       cleanup ();
+
+       return (int) r;
 }
 
 void
-PluginSelector::btn_cancel_clicked()
+PluginSelector::cleanup ()
 {
        hide();
-       added_plugins.clear();
-       o_selector.rescan();
-       i_selected_plug = 0;
-       o_selected_plug = -1;
+       amodel->clear();
 }
 
 void
-PluginSelector::btn_update_clicked()
+PluginSelector::filter_button_clicked ()
 {
-       manager->refresh ();
-       ladspa_display.rescan ();
+       filter_entry.set_text ("");
 }
 
-gint
-PluginSelector::wm_close(GdkEventAny* ev)
+void
+PluginSelector::filter_entry_changed ()
 {
-       btn_cancel_clicked();
-       return TRUE;
+       refill ();
 }
 
-void
-PluginSelector::column_clicked (int column, GtkCList* clist)
+void 
+PluginSelector::filter_mode_changed ()
 {
-       gtk_clist_set_sort_column (clist, column);
-       gtk_clist_sort (clist);
+       refill ();
 }
+