#include <cstdio>
#include <lrdf.h>
+#include <map>
+
+#include <algorithm>
#include <gtkmm/table.h>
#include <gtkmm/stock.h>
#include <gtkmm/button.h>
#include <gtkmm/notebook.h>
+#include <gtkmm2ext/utils.h>
+
+#include <pbd/convert.h>
+
#include <ardour/plugin_manager.h>
#include <ardour/plugin.h>
#include <ardour/configuration.h>
using namespace ARDOUR;
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"),
+ N_("Favorites only"),
+ 0
+};
PluginSelector::PluginSelector (PluginManager *mgr)
- : ArdourDialog (_("ardour: plugins"), true, false)
+ : ArdourDialog (_("ardour: plugins"), true, false),
+ filter_button (Stock::CLEAR)
{
set_position (Gtk::WIN_POS_MOUSE);
set_name ("PluginSelectorWindow");
manager = mgr;
session = 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_reorderable (false);
- lscroller.set_border_width(10);
- lscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
- lscroller.add(ladspa_display);
+ _menu = 0;
+ in_row_change = false;
+
+ plugin_model = Gtk::ListStore::create (plugin_columns);
+ plugin_display.set_model (plugin_model);
+ /* XXX translators: try to convert "Fav" into a short term
+ related to "favorite"
+ */
+ plugin_display.append_column (_("Fav"), plugin_columns.favorite);
+ plugin_display.append_column (_("Available Plugins"), plugin_columns.name);
+ plugin_display.append_column (_("Type"), plugin_columns.type_name);
+ plugin_display.append_column (_("Category"), plugin_columns.category);
+ plugin_display.append_column (_("Creator"), plugin_columns.creator);
+ plugin_display.append_column (_("# Audio In"),plugin_columns.audio_ins);
+ plugin_display.append_column (_("# Audio Out"), plugin_columns.audio_outs);
+ plugin_display.append_column (_("# MIDI In"),plugin_columns.midi_ins);
+ plugin_display.append_column (_("# MIDI Out"), plugin_columns.midi_outs);
+ plugin_display.set_headers_visible (true);
+ plugin_display.set_headers_clickable (true);
+ plugin_display.set_reorderable (false);
+ plugin_display.set_rules_hint (true);
+
+ CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
+ fav_cell->property_activatable() = true;
+ fav_cell->property_radio() = false;
+ fav_cell->signal_toggled().connect (mem_fun (*this, &PluginSelector::favorite_changed));
+
+ scroller.set_border_width(10);
+ scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ scroller.add(plugin_display);
amodel = Gtk::ListStore::create(acols);
added_list.set_model (amodel);
- added_list.append_column (_("Plugins to be Connected to Insert"), acols.text);
+ 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_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_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);
+ for (int i = 0; i <=7; i++) {
+ Gtk::TreeView::Column* column = plugin_display.get_column(i);
column->set_sort_column(i);
}
-#endif
ascroller.set_border_width(10);
ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
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(scroller, 0, 7, 0, 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));
- 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);
+ filter_box->show ();
+ filter_mode.show ();
+ filter_entry.show ();
+ filter_button.show ();
- table->attach(ascroller, 0, 7, 7, 9);
+ 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(ascroller, 0, 7, 8, 10);
add_button (Stock::CANCEL, RESPONSE_CANCEL);
- add_button (Stock::CONNECT, RESPONSE_APPLY);
+ add_button (_("Insert Plugin(s)"), 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 Gtk::Notebook_Helpers;
- notebook.pages().push_back (TabElem (lscroller, _("LADSPA")));
-
-#ifdef VST_SUPPORT
- if (Config->get_use_vst()) {
- notebook.pages().push_back (TabElem (vscroller, _("VST")));
- }
-#endif
-
-#ifdef HAVE_AUDIOUNIT
- notebook.pages().push_back (TabElem (auscroller, _("AudioUnit")));
-#endif
-
table->set_name("PluginSelectorTable");
- ladspa_display.set_name("PluginSelectorDisplay");
- //ladspa_display.set_name("PluginSelectorList");
+ plugin_display.set_name("PluginSelectorDisplay");
+ //plugin_display.set_name("PluginSelectorList");
added_list.set_name("PluginSelectorList");
- 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();
+ plugin_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
+ plugin_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::display_selection_changed));
+ plugin_display.grab_focus();
-#ifdef VST_SUPPORT
- if (Config->get_use_vst()) {
- 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
-
-#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->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
- input_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_correct_focus()
-{
- int cp = notebook.get_current_page();
-
- if (cp == 0) {
- ladspa_display.grab_focus();
- return;
- }
-
-#ifdef VST_SUPPORT
- if (Config->get_use_vst()) {
- cp--;
-
- if (cp == 0) {
- vst_display.grab_focus();
- return;
- }
- }
-#endif
-
-#ifdef HAVE_AUDIOUNIT
- cp--;
-
- if (cp == 0) {
- au_display.grab_focus();
- return;
- }
-#endif
+ refill ();
}
void
}
}
-void
-PluginSelector::_input_refiller (void *arg)
+bool
+PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& filterstr)
{
- ((PluginSelector *) arg)->input_refiller ();
-}
+ std::string compstr;
+ std::string mode = filter_mode.get_active_text ();
-int compare(const void *left, const void *right)
-{
- return strcmp(*((char**)left), *((char**)right));
-}
+ if (mode == _("Favorites only")) {
+ return manager->is_a_favorite_plugin (info);
+ }
-void
-PluginSelector::input_refiller ()
-{
- guint row;
- PluginInfoList &plugs = manager->ladspa_plugin_info ();
- PluginInfoList::iterator i;
- char ibuf[16], obuf[16];
- lmodel->clear();
-
- // Insert into GTK list
- for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
- snprintf (ibuf, sizeof(ibuf)-1, "%zu", (*i)->n_inputs.n_total());
- snprintf (obuf, sizeof(obuf)-1, "%zu", (*i)->n_outputs.n_total());
+ if (!filterstr.empty()) {
- Gtk::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;
+ 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;
+ }
}
- lmodel->set_sort_column (0, Gtk::SORT_ASCENDING);
+ return true;
}
-#ifdef VST_SUPPORT
-
void
-PluginSelector::_vst_refiller (void *arg)
+PluginSelector::setup_filter_string (string& filterstr)
{
- ((PluginSelector *) arg)->vst_refiller ();
-}
+ filterstr = filter_entry.get_text ();
+ transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
+}
void
-PluginSelector::vst_refiller ()
+PluginSelector::refill ()
{
- guint row;
- PluginInfoList &plugs = manager->vst_plugin_info ();
- PluginInfoList::iterator i;
- char ibuf[16], obuf[16];
- vmodel->clear();
-
- // Insert into GTK list
- for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
+ std::string filterstr;
- snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
- snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
-
- Gtk::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, Gtk::SORT_ASCENDING);
-}
+ in_row_change = true;
-void
-PluginSelector::vst_display_selection_changed()
-{
- if (vst_display.get_selection()->count_selected_rows() != 0) {
- btn_add->set_sensitive (true);
- } else {
- btn_add->set_sensitive (false);
- }
+ plugin_model->clear ();
- current_selection = ARDOUR::VST;
-}
+ setup_filter_string (filterstr);
-#endif //VST_SUPPORT
+ ladspa_refiller (filterstr);
+ lv2_refiller (filterstr);
+ vst_refiller (filterstr);
+ au_refiller (filterstr);
-#ifdef HAVE_AUDIOUNIT
+ in_row_change = false;
+}
void
-PluginSelector::_au_refiller (void *arg)
+PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filterstr, const char* type)
{
- ((PluginSelector *) arg)->au_refiller ();
+ char buf[16];
+
+ for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
+
+ if (show_this_plugin (*i, filterstr)) {
+
+ TreeModel::Row newrow = *(plugin_model->append());
+ newrow[plugin_columns.favorite] = manager->is_a_favorite_plugin (*i);
+ newrow[plugin_columns.name] = (*i)->name;
+ newrow[plugin_columns.type_name] = type;
+ newrow[plugin_columns.category] = (*i)->category;
+
+ string creator = (*i)->creator;
+ string::size_type pos = 0;
+
+ /* stupid LADSPA creator strings */
+
+ while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+ creator = creator.substr (0, pos);
+
+ newrow[plugin_columns.creator] = creator;
+
+ if ((*i)->n_inputs.n_total() < 0) {
+ newrow[plugin_columns.audio_ins] = "various";
+ newrow[plugin_columns.midi_ins] = "various";
+ } else {
+ snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_audio());
+ newrow[plugin_columns.audio_ins] = buf;
+ snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_midi());
+ newrow[plugin_columns.midi_ins] = buf;
+ }
+ if ((*i)->n_outputs.n_total() < 0) {
+ newrow[plugin_columns.audio_outs] = "various";
+ newrow[plugin_columns.midi_outs] = "various";
+ } else {
+ snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_audio());
+ newrow[plugin_columns.audio_outs] = buf;
+ snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_midi());
+ newrow[plugin_columns.midi_outs] = buf;
+ }
+
+ newrow[plugin_columns.plugin] = *i;
+ }
+ }
}
void
-PluginSelector::au_refiller ()
+PluginSelector::ladspa_refiller (const std::string& filterstr)
{
- guint row;
- PluginInfoList plugs (AUPluginInfo::discover ());
- PluginInfoList::iterator i;
- char ibuf[16], obuf[16];
- aumodel->clear();
-
- // Insert into GTK list
- for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
-
- snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
- snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
-
- Gtk::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, Gtk::SORT_ASCENDING);
+ refiller (manager->ladspa_plugin_info(), filterstr, "LADSPA");
}
void
-PluginSelector::au_display_selection_changed()
+PluginSelector::lv2_refiller (const std::string& filterstr)
{
- if (au_display.get_selection()->count_selected_rows() != 0) {
- btn_add->set_sensitive (true);
- } else {
- btn_add->set_sensitive (false);
- }
-
- current_selection = ARDOUR::AudioUnit;
+#ifdef HAVE_LV2
+ refiller (manager->lv2_plugin_info(), filterstr, "LV2");
+#endif
}
-#endif //HAVE_AUDIOUNIT
+void
+PluginSelector::vst_refiller (const std::string& filterstr)
+{
+#ifdef VST_SUPPORT
+ refiller (manager->vst_plugin_info(), filterstr, "VST");
+#endif
+}
void
-PluginSelector::use_plugin (PluginInfoPtr pi)
+PluginSelector::au_refiller (const std::string& filterstr)
+{
+#ifdef HAVE_AUDIOUNITS
+ refiller (manager->au_plugin_info(), filterstr, "AU");
+#endif
+}
+
+PluginPtr
+PluginSelector::load_plugin (PluginInfoPtr pi)
{
if (session == 0) {
- return;
+ return PluginPtr();
}
- PluginPtr plugin = pi->load (*session);
-
- if (plugin) {
- PluginCreated (plugin);
- }
+ return pi->load (*session);
}
void
{
std::string name;
PluginInfoPtr pi;
- Gtk::TreeModel::Row newrow = *(amodel->append());
-
- Gtk::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;
- }
+ TreeModel::Row newrow = *(amodel->append());
+ TreeModel::Row row;
+
+ row = *(plugin_display.get_selection()->get_selected());
+ name = row[plugin_columns.name];
+ pi = row[plugin_columns.plugin];
newrow[acols.text] = name;
newrow[acols.plugin] = pi;
void
PluginSelector::btn_remove_clicked()
{
- Gtk::TreeModel::iterator iter = added_list.get_selection()->get_selected();
+ TreeModel::iterator iter = added_list.get_selection()->get_selected();
amodel->erase(iter);
if (amodel->children().empty()) {
PluginSelector::btn_update_clicked()
{
manager->refresh ();
- input_refiller ();
-#ifdef VST_SUPPORT
- vst_refiller ();
-#endif
-#ifdef HAVE_AUDIOUNIT
- au_refiller ();
-#endif
+ refill();
}
void
-PluginSelector::ladspa_display_selection_changed()
+PluginSelector::display_selection_changed()
{
- if (ladspa_display.get_selection()->count_selected_rows() != 0) {
+ if (plugin_display.get_selection()->count_selected_rows() != 0) {
btn_add->set_sensitive (true);
} else {
btn_add->set_sensitive (false);
}
-
- current_selection = ARDOUR::LADSPA;
}
void
{
ResponseType r;
TreeModel::Children::iterator i;
+ SelectedPlugins plugins;
r = (ResponseType) Dialog::run ();
switch (r) {
case RESPONSE_APPLY:
for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
- use_plugin ((*i)[acols.plugin]);
+ PluginInfoPtr pp = (*i)[acols.plugin];
+ PluginPtr p = load_plugin (pp);
+ if (p) {
+ plugins.push_back (p);
+ }
+ }
+ if (interested_object && !plugins.empty()) {
+ interested_object->use_plugins (plugins);
}
+
break;
default:
break;
}
- cleanup ();
+ hide();
+ amodel->clear();
+ interested_object = 0;
return (int) r;
}
void
-PluginSelector::cleanup ()
+PluginSelector::filter_button_clicked ()
{
- hide();
- amodel->clear();
+ filter_entry.set_text ("");
+}
+
+void
+PluginSelector::filter_entry_changed ()
+{
+ refill ();
+}
+
+void
+PluginSelector::filter_mode_changed ()
+{
+ std::string mode = filter_mode.get_active_text ();
+
+ if (mode == _("Favorites only")) {
+ filter_entry.set_sensitive (false);
+ } else {
+ filter_entry.set_sensitive (true);
+ }
+
+ refill ();
+}
+
+void
+PluginSelector::on_show ()
+{
+ ArdourDialog::on_show ();
+ filter_entry.grab_focus ();
+}
+
+struct PluginMenuCompare {
+ 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;
+ }
+};
+
+Gtk::Menu&
+PluginSelector::plugin_menu()
+{
+ using namespace Menu_Helpers;
+
+ typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
+ SubmenuMap submenu_map;
+
+ if (!_menu) {
+ _menu = new Menu();
+ _menu->set_name("ArdourContextMenu");
+ }
+
+ MenuList& items = _menu->items();
+ Menu* favs = new Menu();
+ favs->set_name("ArdourContextMenu");
+
+ items.clear ();
+ items.push_back (MenuElem (_("Favorites"), *favs));
+ items.push_back (MenuElem (_("Plugin Manager"), mem_fun (*this, &PluginSelector::show_manager)));
+ items.push_back (SeparatorElem ());
+
+ 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_LV2
+ all_plugs.insert (all_plugs.end(), manager->lv2_plugin_info().begin(), manager->lv2_plugin_info().end());
+#endif
+
+ PluginMenuCompare cmp;
+ all_plugs.sort (cmp);
+
+ for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
+ SubmenuMap::iterator x;
+ Gtk::Menu* submenu;
+
+ string creator = (*i)->creator;
+ string::size_type pos = 0;
+
+ if (manager->is_a_favorite_plugin (*i)) {
+ favs->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
+ }
+
+ /* stupid LADSPA creator strings */
+
+ while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+ creator = creator.substr (0, pos);
+
+ if ((x = submenu_map.find (creator)) != submenu_map.end()) {
+ submenu = x->second;
+ } else {
+ submenu = new Gtk::Menu;
+ items.push_back (MenuElem (creator, *submenu));
+ submenu_map.insert (pair<Glib::ustring,Menu*> (creator, submenu));
+ submenu->set_name("ArdourContextMenu");
+ }
+
+ submenu->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
+ }
+
+ return *_menu;
+}
+
+void
+PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
+{
+ PluginPtr p = load_plugin (pi);
+
+ if (p && interested_object) {
+ SelectedPlugins plugins;
+ plugins.push_back (p);
+ interested_object->use_plugins (plugins);
+ }
+
+ interested_object = 0;
+}
+
+void
+PluginSelector::favorite_changed (const Glib::ustring& path)
+{
+ PluginInfoPtr pi;
+
+ if (in_row_change) {
+ return;
+ }
+
+ in_row_change = true;
+
+ TreeModel::iterator iter = plugin_model->get_iter (path);
+
+ if (iter) {
+
+ bool favorite = !(*iter)[plugin_columns.favorite];
+
+ /* change state */
+
+ (*iter)[plugin_columns.favorite] = favorite;
+
+ /* save new favorites list */
+
+ pi = (*iter)[plugin_columns.plugin];
+
+ if (favorite) {
+ manager->add_favorite (pi->type, pi->unique_id);
+ } else {
+ manager->remove_favorite (pi->type, pi->unique_id);
+ }
+
+ manager->save_favorites ();
+ }
+ in_row_change = false;
+}
+
+void
+PluginSelector::show_manager ()
+{
+ show_all();
+ run ();
+}
+
+void
+PluginSelector::set_interested_object (PluginInterestedObject& obj)
+{
+ interested_object = &obj;
}