Don't close the plugin manager when an incompatible plugin is selected. Fixes #1194.
[ardour.git] / gtk2_ardour / plugin_selector.cc
1 /*
2     Copyright (C) 2000-2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19 #ifdef WAF_BUILD
20 #include "gtk2ardour-config.h"
21 #endif
22
23 #include <cstdio>
24 #include <lrdf.h>
25 #include <map>
26
27 #include <algorithm>
28
29 #include <gtkmm/table.h>
30 #include <gtkmm/stock.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/notebook.h>
33
34 #include <gtkmm2ext/utils.h>
35
36 #include "pbd/convert.h"
37
38 #include "ardour/plugin_manager.h"
39 #include "ardour/plugin.h"
40 #include "ardour/configuration.h"
41 #include "ardour/session.h"
42
43 #include "ardour_ui.h"
44 #include "plugin_selector.h"
45 #include "gui_thread.h"
46
47 #include "i18n.h"
48
49 using namespace ARDOUR;
50 using namespace PBD;
51 using namespace Gtk;
52 using namespace std;
53
54 static const char* _filter_mode_strings[] = {
55         N_("Name contains"),
56         N_("Type contains"),
57         N_("Category contains"),
58         N_("Author contains"),
59         N_("Library contains"),
60         N_("Favorites only"),
61         N_("Hidden only"),
62         0
63 };
64
65 PluginSelector::PluginSelector (PluginManager *mgr)
66         : ArdourDialog (_("Plugin Manager"), true, false),
67           filter_button (Stock::CLEAR)
68 {
69         set_position (Gtk::WIN_POS_MOUSE);
70         set_name ("PluginSelectorWindow");
71         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
72
73         _plugin_menu = 0;
74         manager = mgr;
75         in_row_change = false;
76
77         manager->PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
78         build_plugin_menu ();
79
80         plugin_model = Gtk::ListStore::create (plugin_columns);
81         plugin_display.set_model (plugin_model);
82         /* XXX translators: try to convert "Fav" into a short term
83            related to "favorite" and "Hid" into a short term
84            related to "hidden"
85         */
86         plugin_display.append_column (_("Fav"), plugin_columns.favorite);
87         plugin_display.append_column (_("Hid"), plugin_columns.hidden);
88         plugin_display.append_column (_("Available Plugins"), plugin_columns.name);
89         plugin_display.append_column (_("Type"), plugin_columns.type_name);
90         plugin_display.append_column (_("Category"), plugin_columns.category);
91         plugin_display.append_column (_("Creator"), plugin_columns.creator);
92         plugin_display.append_column (_("# Audio In"),plugin_columns.audio_ins);
93         plugin_display.append_column (_("# Audio Out"), plugin_columns.audio_outs);
94         plugin_display.append_column (_("# MIDI In"),plugin_columns.midi_ins);
95         plugin_display.append_column (_("# MIDI Out"), plugin_columns.midi_outs);
96         plugin_display.set_headers_visible (true);
97         plugin_display.set_headers_clickable (true);
98         plugin_display.set_reorderable (false);
99         plugin_display.set_rules_hint (true);
100
101         CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
102         fav_cell->property_activatable() = true;
103         fav_cell->property_radio() = true;
104         fav_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::favorite_changed));
105
106         CellRendererToggle* hidden_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (1));
107         hidden_cell->property_activatable() = true;
108         hidden_cell->property_radio() = true;
109         hidden_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::hidden_changed));
110
111         scroller.set_border_width(10);
112         scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
113         scroller.add(plugin_display);
114
115         amodel = Gtk::ListStore::create(acols);
116         added_list.set_model (amodel);
117         added_list.append_column (_("Plugins to be connected"), acols.text);
118         added_list.set_headers_visible (true);
119         added_list.set_reorderable (false);
120
121         for (int i = 0; i <=8; i++) {
122                 Gtk::TreeView::Column* column = plugin_display.get_column(i);
123                 column->set_sort_column(i);
124         }
125
126         ascroller.set_border_width(10);
127         ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
128         ascroller.add(added_list);
129         btn_add = manage(new Gtk::Button(Stock::ADD));
130         ARDOUR_UI::instance()->set_tip(*btn_add, _("Add a plugin to the effect list"));
131         btn_add->set_sensitive (false);
132         btn_remove = manage(new Gtk::Button(Stock::REMOVE));
133         btn_remove->set_sensitive (false);
134         ARDOUR_UI::instance()->set_tip(*btn_remove, _("Remove a plugin from the effect list"));
135         Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
136         ARDOUR_UI::instance()->set_tip(*btn_update, _("Update available plugins"));
137
138         btn_add->set_name("PluginSelectorButton");
139         btn_remove->set_name("PluginSelectorButton");
140
141         Gtk::Table* table = manage(new Gtk::Table(7, 11));
142         table->set_size_request(750, 500);
143         table->attach(scroller, 0, 7, 0, 5);
144
145         HBox* filter_box = manage (new HBox);
146
147         vector<string> filter_strings = I18N (_filter_mode_strings);
148         Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
149         filter_mode.set_active_text (filter_strings.front());
150
151         filter_box->pack_start (filter_mode, false, false);
152         filter_box->pack_start (filter_entry, true, true);
153         filter_box->pack_start (filter_button, false, false);
154
155         filter_entry.signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::filter_entry_changed));
156         filter_button.signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::filter_button_clicked));
157         filter_mode.signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::filter_mode_changed));
158
159         filter_box->show ();
160         filter_mode.show ();
161         filter_entry.show ();
162         filter_button.show ();
163
164         table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
165
166         table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5);
167         table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
168         table->attach(*btn_update, 5, 6, 6, 7, FILL, FILL, 5, 5);
169
170         table->attach(ascroller, 0, 7, 8, 10);
171
172         add_button (Stock::CLOSE, RESPONSE_CLOSE);
173         add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
174         set_default_response (RESPONSE_APPLY);
175         set_response_sensitive (RESPONSE_APPLY, false);
176         get_vbox()->pack_start (*table);
177
178         table->set_name("PluginSelectorTable");
179         plugin_display.set_name("PluginSelectorDisplay");
180         //plugin_display.set_name("PluginSelectorList");
181         added_list.set_name("PluginSelectorList");
182
183         plugin_display.signal_button_press_event().connect_notify (sigc::mem_fun(*this, &PluginSelector::row_clicked));
184         plugin_display.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::display_selection_changed));
185         plugin_display.grab_focus();
186
187         btn_update->signal_clicked().connect (sigc::mem_fun(*this, &PluginSelector::btn_update_clicked));
188         btn_add->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_add_clicked));
189         btn_remove->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_remove_clicked));
190         added_list.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::added_list_selection_changed));
191
192         refill ();
193 }
194
195 PluginSelector::~PluginSelector ()
196 {
197         delete _plugin_menu;
198 }
199
200 void
201 PluginSelector::row_clicked(GdkEventButton* event)
202 {
203         if (event->type == GDK_2BUTTON_PRESS) {
204                 btn_add_clicked();
205         }
206 }
207
208 bool
209 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& filterstr)
210 {
211         std::string compstr;
212         std::string mode = filter_mode.get_active_text ();
213
214         if (mode == _("Favorites only")) {
215                 return manager->get_status (info) == PluginManager::Favorite;
216         }
217
218         if (mode == _("Hidden only")) {
219                 return manager->get_status (info) == PluginManager::Hidden;
220         }
221
222         if (!filterstr.empty()) {
223
224                 if (mode == _("Name contains")) {
225                         compstr = info->name;
226                 } else if (mode == _("Category contains")) {
227                         compstr = info->category;
228                 } else if (mode == _("Type contains")) {
229
230                         switch (info->type) {
231                         case LADSPA:
232                                 compstr = X_("LADSPA");
233                                 break;
234                         case AudioUnit:
235                                 compstr = X_("AudioUnit");
236                                 break;
237                         case LV2:
238                                 compstr = X_("LV2");
239                                 break;
240                         case VST:
241                                 compstr = X_("VST");
242                                 break;
243                         }
244
245                 } else if (mode == _("Author contains")) {
246                         compstr = info->creator;
247                 } else if (mode == _("Library contains")) {
248                         compstr = info->path;
249                 }
250
251                 if (compstr.empty()) {
252                         return false;
253                 }
254
255                 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
256
257                 if (compstr.find (filterstr) != string::npos) {
258                         return true;
259                 } else {
260                         return false;
261                 }
262         }
263
264         return true;
265 }
266
267 void
268 PluginSelector::setup_filter_string (string& filterstr)
269 {
270         filterstr = filter_entry.get_text ();
271         transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
272 }
273
274 void
275 PluginSelector::refill ()
276 {
277         std::string filterstr;
278
279         in_row_change = true;
280
281         plugin_model->clear ();
282
283         setup_filter_string (filterstr);
284
285         ladspa_refiller (filterstr);
286         lv2_refiller (filterstr);
287         vst_refiller (filterstr);
288         au_refiller (filterstr);
289
290         in_row_change = false;
291 }
292
293 void
294 PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filterstr, const char* type)
295 {
296         char buf[16];
297
298         for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
299
300                 if (show_this_plugin (*i, filterstr)) {
301
302                         TreeModel::Row newrow = *(plugin_model->append());
303                         newrow[plugin_columns.favorite] = (manager->get_status (*i) == PluginManager::Favorite);
304                         newrow[plugin_columns.hidden] = (manager->get_status (*i) == PluginManager::Hidden);
305                         newrow[plugin_columns.name] = (*i)->name;
306                         newrow[plugin_columns.type_name] = type;
307                         newrow[plugin_columns.category] = (*i)->category;
308
309                         string creator = (*i)->creator;
310                         string::size_type pos = 0;
311
312                         /* stupid LADSPA creator strings */
313
314                         while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
315                         creator = creator.substr (0, pos);
316
317                         newrow[plugin_columns.creator] = creator;
318
319                         snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_audio());
320                         newrow[plugin_columns.audio_ins] = buf;
321                         snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_midi());
322                         newrow[plugin_columns.midi_ins] = buf;
323
324                         snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_audio());
325                         newrow[plugin_columns.audio_outs] = buf;
326                         snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_midi());
327                         newrow[plugin_columns.midi_outs] = buf;
328
329                         newrow[plugin_columns.plugin] = *i;
330                 }
331         }
332 }
333
334 void
335 PluginSelector::ladspa_refiller (const std::string& filterstr)
336 {
337         refiller (manager->ladspa_plugin_info(), filterstr, "LADSPA");
338 }
339
340 void
341 PluginSelector::lv2_refiller (const std::string& filterstr)
342 {
343 #ifdef HAVE_SLV2
344         refiller (manager->lv2_plugin_info(), filterstr, "LV2");
345 #endif
346 }
347
348 void
349 #ifdef VST_SUPPORT
350 PluginSelector::vst_refiller (const std::string& filterstr)
351 #else
352 PluginSelector::vst_refiller (const std::string&)
353 #endif
354 {
355 #ifdef VST_SUPPORT
356         refiller (manager->vst_plugin_info(), filterstr, "VST");
357 #endif
358 }
359
360 void
361 #ifdef HAVE_AUDIOUNITS
362 PluginSelector::au_refiller (const std::string& filterstr)
363 #else
364 PluginSelector::au_refiller (const std::string&)
365 #endif
366 {
367 #ifdef HAVE_AUDIOUNITS
368         refiller (manager->au_plugin_info(), filterstr, "AU");
369 #endif
370 }
371
372 PluginPtr
373 PluginSelector::load_plugin (PluginInfoPtr pi)
374 {
375         if (_session == 0) {
376                 return PluginPtr();
377         }
378
379         return pi->load (*_session);
380 }
381
382 void
383 PluginSelector::btn_add_clicked()
384 {
385         std::string name;
386         PluginInfoPtr pi;
387         TreeModel::Row newrow = *(amodel->append());
388         TreeModel::Row row;
389
390         row = *(plugin_display.get_selection()->get_selected());
391         name = row[plugin_columns.name];
392         pi = row[plugin_columns.plugin];
393
394         newrow[acols.text] = name;
395         newrow[acols.plugin] = pi;
396
397         if (!amodel->children().empty()) {
398                 set_response_sensitive (RESPONSE_APPLY, true);
399         }
400 }
401
402 void
403 PluginSelector::btn_remove_clicked()
404 {
405         TreeModel::iterator iter = added_list.get_selection()->get_selected();
406
407         amodel->erase(iter);
408         if (amodel->children().empty()) {
409                 set_response_sensitive (RESPONSE_APPLY, false);
410         }
411 }
412
413 void
414 PluginSelector::btn_update_clicked()
415 {
416         manager->refresh ();
417         refill();
418 }
419
420 void
421 PluginSelector::display_selection_changed()
422 {
423         if (plugin_display.get_selection()->count_selected_rows() != 0) {
424                 btn_add->set_sensitive (true);
425         } else {
426                 btn_add->set_sensitive (false);
427         }
428 }
429
430 void
431 PluginSelector::added_list_selection_changed()
432 {
433         if (added_list.get_selection()->count_selected_rows() != 0) {
434                 btn_remove->set_sensitive (true);
435         } else {
436                 btn_remove->set_sensitive (false);
437         }
438 }
439
440 int
441 PluginSelector::run ()
442 {
443         ResponseType r;
444         TreeModel::Children::iterator i;
445
446         bool finish = false;
447         
448         while (!finish) {
449
450                 SelectedPlugins plugins;
451                 r = (ResponseType) Dialog::run ();
452                 
453                 switch (r) {
454                 case RESPONSE_APPLY:
455                         for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
456                                 PluginInfoPtr pp = (*i)[acols.plugin];
457                                 PluginPtr p = load_plugin (pp);
458                                 if (p) {
459                                         plugins.push_back (p);
460                                 }
461                         }
462                         if (interested_object && !plugins.empty()) {
463                                 finish = !interested_object->use_plugins (plugins);
464                         }
465                         
466                         break;
467                         
468                 default:
469                         finish = true;
470                         break;
471                 }
472         }
473                 
474                 
475         hide();
476         amodel->clear();
477         interested_object = 0;
478
479         return (int) r;
480 }
481
482 void
483 PluginSelector::filter_button_clicked ()
484 {
485         filter_entry.set_text ("");
486 }
487
488 void
489 PluginSelector::filter_entry_changed ()
490 {
491         refill ();
492 }
493
494 void
495 PluginSelector::filter_mode_changed ()
496 {
497         std::string mode = filter_mode.get_active_text ();
498
499         if (mode == _("Favorites only") || mode == _("Hidden only")) {
500                 filter_entry.set_sensitive (false);
501         } else {
502                 filter_entry.set_sensitive (true);
503         }
504
505         refill ();
506 }
507
508 void
509 PluginSelector::on_show ()
510 {
511         ArdourDialog::on_show ();
512         filter_entry.grab_focus ();
513 }
514
515 struct PluginMenuCompareByCreator {
516     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
517             int cmp;
518
519             cmp = strcasecmp (a->creator.c_str(), b->creator.c_str());
520
521             if (cmp < 0) {
522                     return true;
523             } else if (cmp == 0) {
524                     /* same creator ... compare names */
525                     if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
526                             return true;
527                     }
528             }
529             return false;
530     }
531 };
532
533 struct PluginMenuCompareByName {
534     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
535             int cmp;
536
537             cmp = strcasecmp (a->name.c_str(), b->name.c_str());
538
539             if (cmp < 0) {
540                     return true;
541             } else if (cmp == 0) {
542                     /* same name ... compare type */
543                     if (a->type < b->type) {
544                             return true;
545                     }
546             }
547             return false;
548     }
549 };
550
551 struct PluginMenuCompareByCategory {
552     bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
553             int cmp;
554
555             cmp = strcasecmp (a->category.c_str(), b->category.c_str());
556
557             if (cmp < 0) {
558                     return true;
559             } else if (cmp == 0) {
560                     /* same category ... compare names */
561                     if (strcasecmp (a->name.c_str(), b->name.c_str()) < 0) {
562                             return true;
563                     }
564             }
565             return false;
566     }
567 };
568
569 /** @return Plugin menu. The caller should not delete it */
570 Gtk::Menu*
571 PluginSelector::plugin_menu()
572 {
573         return _plugin_menu;
574 }
575
576 void
577 PluginSelector::build_plugin_menu ()
578 {
579         PluginInfoList all_plugs;
580
581         all_plugs.insert (all_plugs.end(), manager->ladspa_plugin_info().begin(), manager->ladspa_plugin_info().end());
582 #ifdef VST_SUPPORT
583         all_plugs.insert (all_plugs.end(), manager->vst_plugin_info().begin(), manager->vst_plugin_info().end());
584 #endif
585 #ifdef HAVE_AUDIOUNITS
586         all_plugs.insert (all_plugs.end(), manager->au_plugin_info().begin(), manager->au_plugin_info().end());
587 #endif
588 #ifdef HAVE_SLV2
589         all_plugs.insert (all_plugs.end(), manager->lv2_plugin_info().begin(), manager->lv2_plugin_info().end());
590 #endif
591
592         using namespace Menu_Helpers;
593
594         delete _plugin_menu;
595         
596         _plugin_menu = manage (new Menu);
597         _plugin_menu->set_name("ArdourContextMenu");
598         
599         MenuList& items = _plugin_menu->items();
600         items.clear ();
601
602         Gtk::Menu* favs = create_favs_menu(all_plugs);
603         items.push_back (MenuElem (_("Favorites"), *manage (favs)));
604
605         items.push_back (MenuElem (_("Plugin Manager"), sigc::mem_fun (*this, &PluginSelector::show_manager)));
606         items.push_back (SeparatorElem ());
607
608         Menu* by_creator = create_by_creator_menu(all_plugs);
609         items.push_back (MenuElem (_("By Creator"), *manage (by_creator)));
610
611         Menu* by_category = create_by_category_menu(all_plugs);
612         items.push_back (MenuElem (_("By Category"), *manage (by_category)));
613 }
614
615 Gtk::Menu*
616 PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
617 {
618         using namespace Menu_Helpers;
619
620         Menu* favs = new Menu();
621         favs->set_name("ArdourContextMenu");
622
623         PluginMenuCompareByName cmp_by_name;
624         all_plugs.sort (cmp_by_name);
625
626         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
627                 if (manager->get_status (*i) == PluginManager::Favorite) {
628                         favs->items().push_back (MenuElem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
629                 }
630         }
631         return favs;
632 }
633
634 Gtk::Menu*
635 PluginSelector::create_by_creator_menu (ARDOUR::PluginInfoList& all_plugs)
636 {
637         using namespace Menu_Helpers;
638
639         typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
640         SubmenuMap creator_submenu_map;
641
642         Menu* by_creator = new Menu();
643         by_creator->set_name("ArdourContextMenu");
644
645         MenuList& by_creator_items = by_creator->items();
646         PluginMenuCompareByCreator cmp_by_creator;
647         all_plugs.sort (cmp_by_creator);
648
649         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
650
651                 if (manager->get_status (*i) == PluginManager::Hidden) continue;
652
653                 string creator = (*i)->creator;
654
655                 /* stupid LADSPA creator strings */
656                 string::size_type pos = 0;
657                 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
658                 creator = creator.substr (0, pos);
659
660                 SubmenuMap::iterator x;
661                 Gtk::Menu* submenu;
662                 if ((x = creator_submenu_map.find (creator)) != creator_submenu_map.end()) {
663                         submenu = x->second;
664                 } else {
665                         submenu = new Gtk::Menu;
666                         by_creator_items.push_back (MenuElem (creator, *manage (submenu)));
667                         creator_submenu_map.insert (pair<Glib::ustring,Menu*> (creator, submenu));
668                         submenu->set_name("ArdourContextMenu");
669                 }
670                 submenu->items().push_back (MenuElem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
671         }
672         return by_creator;
673 }
674
675 Gtk::Menu*
676 PluginSelector::create_by_category_menu (ARDOUR::PluginInfoList& all_plugs)
677 {
678         using namespace Menu_Helpers;
679
680         typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
681         SubmenuMap category_submenu_map;
682
683         Menu* by_category = new Menu();
684         by_category->set_name("ArdourContextMenu");
685
686         MenuList& by_category_items = by_category->items();
687         PluginMenuCompareByCategory cmp_by_category;
688         all_plugs.sort (cmp_by_category);
689
690         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
691
692                 if (manager->get_status (*i) == PluginManager::Hidden) continue;
693
694                 string category = (*i)->category;
695
696                 SubmenuMap::iterator x;
697                 Gtk::Menu* submenu;
698                 if ((x = category_submenu_map.find (category)) != category_submenu_map.end()) {
699                         submenu = x->second;
700                 } else {
701                         submenu = new Gtk::Menu;
702                         by_category_items.push_back (MenuElem (category, *manage (submenu)));
703                         category_submenu_map.insert (pair<Glib::ustring,Menu*> (category, submenu));
704                         submenu->set_name("ArdourContextMenu");
705                 }
706                 submenu->items().push_back (MenuElem ((*i)->name, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
707         }
708         return by_category;
709 }
710
711 void
712 PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
713 {
714         PluginPtr p = load_plugin (pi);
715
716         if (p && interested_object) {
717                 SelectedPlugins plugins;
718                 plugins.push_back (p);
719                 interested_object->use_plugins (plugins);
720         }
721
722         interested_object = 0;
723 }
724
725 void
726 PluginSelector::favorite_changed (const Glib::ustring& path)
727 {
728         PluginInfoPtr pi;
729
730         if (in_row_change) {
731                 return;
732         }
733
734         in_row_change = true;
735
736         TreeModel::iterator iter = plugin_model->get_iter (path);
737
738         if (iter) {
739
740                 bool favorite = !(*iter)[plugin_columns.favorite];
741
742                 /* change state */
743
744                 (*iter)[plugin_columns.favorite] = favorite;
745                 (*iter)[plugin_columns.hidden] = false;
746                 PluginManager::PluginStatusType status = (favorite ? PluginManager::Favorite : PluginManager::Normal);
747
748                 /* save new statuses list */
749
750                 pi = (*iter)[plugin_columns.plugin];
751
752                 manager->set_status (pi->type, pi->unique_id, status);
753
754                 manager->save_statuses ();
755
756                 build_plugin_menu ();
757         }
758         in_row_change = false;
759 }
760
761 void
762 PluginSelector::hidden_changed (const Glib::ustring& path)
763 {
764         PluginInfoPtr pi;
765
766         if (in_row_change) {
767                 return;
768         }
769
770         in_row_change = true;
771
772         TreeModel::iterator iter = plugin_model->get_iter (path);
773
774         if (iter) {
775
776                 bool hidden = !(*iter)[plugin_columns.hidden];
777
778                 /* change state */
779
780                 (*iter)[plugin_columns.favorite] = false;
781                 (*iter)[plugin_columns.hidden] = hidden;
782                 PluginManager::PluginStatusType status = (hidden ? PluginManager::Hidden : PluginManager::Normal);
783
784                 /* save new statuses list */
785
786                 pi = (*iter)[plugin_columns.plugin];
787
788                 manager->set_status (pi->type, pi->unique_id, status);
789
790                 manager->save_statuses ();
791         }
792         in_row_change = false;
793 }
794
795 void
796 PluginSelector::show_manager ()
797 {
798         show_all();
799         run ();
800 }
801
802 void
803 PluginSelector::set_interested_object (PluginInterestedObject& obj)
804 {
805         interested_object = &obj;
806 }