2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
25 #include <gtkmm/table.h>
26 #include <gtkmm/stock.h>
27 #include <gtkmm/button.h>
28 #include <gtkmm/notebook.h>
30 #include <gtkmm2ext/utils.h>
32 #include <pbd/convert.h>
34 #include <ardour/plugin_manager.h>
35 #include <ardour/plugin.h>
36 #include <ardour/configuration.h>
38 #include "ardour_ui.h"
39 #include "plugin_selector.h"
40 #include "gui_thread.h"
44 using namespace ARDOUR;
49 static const char* _filter_mode_strings[] = {
52 N_("Author contains"),
53 N_("Library contains"),
57 PluginSelector::PluginSelector (PluginManager *mgr)
58 : ArdourDialog (_("ardour: plugins"), true, false),
59 filter_button (Stock::CLEAR)
61 set_position (Gtk::WIN_POS_MOUSE);
62 set_name ("PluginSelectorWindow");
63 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
68 current_selection = ARDOUR::LADSPA;
70 lmodel = Gtk::ListStore::create(lcols);
71 ladspa_display.set_model (lmodel);
72 ladspa_display.append_column (_("Available LADSPA Plugins"), lcols.name);
73 ladspa_display.append_column (_("Type"), lcols.type);
74 ladspa_display.append_column (_("# Inputs"),lcols.ins);
75 ladspa_display.append_column (_("# Outputs"), lcols.outs);
76 ladspa_display.set_headers_visible (true);
77 ladspa_display.set_headers_clickable (true);
78 ladspa_display.set_reorderable (false);
79 lscroller.set_border_width(10);
80 lscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
81 lscroller.add(ladspa_display);
83 amodel = Gtk::ListStore::create(acols);
84 added_list.set_model (amodel);
85 added_list.append_column (_("Plugins to be connected"), acols.text);
86 added_list.set_headers_visible (true);
87 added_list.set_reorderable (false);
89 for (int i = 0; i <=3; i++) {
90 Gtk::TreeView::Column* column = ladspa_display.get_column(i);
91 column->set_sort_column(i);
95 vmodel = ListStore::create(vcols);
96 vst_display.set_model (vmodel);
97 vst_display.append_column (_("Available plugins"), vcols.name);
98 vst_display.append_column (_("# Inputs"), vcols.ins);
99 vst_display.append_column (_("# Outputs"), vcols.outs);
100 vst_display.set_headers_visible (true);
101 vst_display.set_headers_clickable (true);
102 vst_display.set_reorderable (false);
103 vscroller.set_border_width(10);
104 vscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
105 vscroller.add(vst_display);
107 for (int i = 0; i <=2; i++) {
108 Gtk::TreeView::Column* column = vst_display.get_column(i);
109 column->set_sort_column(i);
113 #ifdef HAVE_AUDIOUNIT
114 aumodel = ListStore::create(aucols);
115 au_display.set_model (aumodel);
116 au_display.append_column (_("Available plugins"), aucols.name);
117 au_display.append_column (_("# Inputs"), aucols.ins);
118 au_display.append_column (_("# Outputs"), aucols.outs);
119 au_display.set_headers_visible (true);
120 au_display.set_headers_clickable (true);
121 au_display.set_reorderable (false);
122 auscroller.set_border_width(10);
123 auscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
124 auscroller.add(au_display);
126 for (int i = 0; i <=2; i++) {
127 Gtk::TreeView::Column* column = au_display.get_column(i);
128 column->set_sort_column(i);
132 ascroller.set_border_width(10);
133 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
134 ascroller.add(added_list);
135 btn_add = manage(new Gtk::Button(Stock::ADD));
136 ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
137 btn_add->set_sensitive (false);
138 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
139 btn_remove->set_sensitive (false);
140 ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
141 Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
142 ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
144 btn_add->set_name("PluginSelectorButton");
145 btn_remove->set_name("PluginSelectorButton");
147 Gtk::Table* table = manage(new Gtk::Table(7, 11));
148 table->set_size_request(750, 500);
149 table->attach(notebook, 0, 7, 0, 5);
151 HBox* filter_box = manage (new HBox);
153 vector<string> filter_strings = I18N (_filter_mode_strings);
154 Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
155 filter_mode.set_active_text (filter_strings.front());
157 filter_box->pack_start (filter_mode, false, false);
158 filter_box->pack_start (filter_entry, true, true);
159 filter_box->pack_start (filter_button, false, false);
161 filter_entry.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_entry_changed));
162 filter_button.signal_clicked().connect (mem_fun (*this, &PluginSelector::filter_button_clicked));
163 filter_mode.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_mode_changed));
167 filter_entry.show ();
168 filter_button.show ();
170 table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
172 table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5);
173 table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
174 table->attach(*btn_update, 5, 6, 6, 7, FILL, FILL, 5, 5);
176 table->attach(ascroller, 0, 7, 8, 10);
178 add_button (Stock::CANCEL, RESPONSE_CANCEL);
179 add_button (Stock::CONNECT, RESPONSE_APPLY);
180 set_default_response (RESPONSE_APPLY);
181 set_response_sensitive (RESPONSE_APPLY, false);
182 get_vbox()->pack_start (*table);
185 // Notebook tab order must be the same in here as in set_correct_focus()
186 using namespace Notebook_Helpers;
187 notebook.pages().push_back (TabElem (lscroller, _("LADSPA")));
190 if (Config->get_use_vst()) {
191 notebook.pages().push_back (TabElem (vscroller, _("VST")));
195 #ifdef HAVE_AUDIOUNIT
196 notebook.pages().push_back (TabElem (auscroller, _("AudioUnit")));
199 table->set_name("PluginSelectorTable");
200 ladspa_display.set_name("PluginSelectorDisplay");
201 //ladspa_display.set_name("PluginSelectorList");
202 added_list.set_name("PluginSelectorList");
204 ladspa_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
205 ladspa_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::ladspa_display_selection_changed));
206 ladspa_display.grab_focus();
209 if (Config->get_use_vst()) {
210 vst_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
211 vst_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::vst_display_selection_changed));
215 #ifdef HAVE_AUDIOUNIT
216 au_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
217 au_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::au_display_selection_changed));
220 btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
221 btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
222 btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
223 added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
231 #ifdef HAVE_AUDIOUNIT
235 signal_show().connect (mem_fun (*this, &PluginSelector::set_correct_focus));
239 * Makes sure keyboard focus is always in the plugin list
240 * of the selected notebook tab.
243 PluginSelector::set_correct_focus()
245 int cp = notebook.get_current_page();
248 ladspa_display.grab_focus();
253 if (Config->get_use_vst()) {
257 vst_display.grab_focus();
263 #ifdef HAVE_AUDIOUNIT
267 au_display.grab_focus();
274 PluginSelector::row_clicked(GdkEventButton* event)
276 if (event->type == GDK_2BUTTON_PRESS)
281 PluginSelector::set_session (Session* s)
283 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
288 session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
293 PluginSelector::show_this_plugin (PluginInfoPtr& info, const std::string& filterstr)
296 std::string mode = filter_mode.get_active_text ();
298 if (!filterstr.empty()) {
300 if (mode == _("Name contains")) {
301 compstr = info->name;
302 } else if (mode == _("Type contains")) {
303 compstr = info->category;
304 } else if (mode == _("Author contains")) {
305 compstr = info->creator;
306 } else if (mode == _("Library contains")) {
307 compstr = info->path;
310 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
312 if (compstr.find (filterstr) != string::npos) {
324 PluginSelector::setup_filter_string (string& filterstr)
326 filterstr = filter_entry.get_text ();
327 transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
331 PluginSelector::ladspa_refiller ()
334 PluginInfoList &plugs = manager->ladspa_plugin_info ();
335 PluginInfoList::iterator i;
336 char ibuf[16], obuf[16];
340 std::string filterstr;
341 setup_filter_string (filterstr);
343 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
344 if (show_this_plugin (*i, filterstr)) {
345 snprintf (ibuf, sizeof(ibuf)-1, "%u", (*i)->n_inputs.n_total());
346 snprintf (obuf, sizeof(obuf)-1, "%u", (*i)->n_outputs.n_total());
348 TreeModel::Row newrow = *(lmodel->append());
349 newrow[lcols.name] = (*i)->name.c_str();
350 newrow[lcols.type] = (*i)->category.c_str();
351 newrow[lcols.ins] = ibuf;
352 newrow[lcols.outs] = obuf;
353 newrow[lcols.plugin] = *i;
357 lmodel->set_sort_column (0, SORT_ASCENDING);
363 PluginSelector::vst_refiller ()
366 PluginInfoList &plugs = manager->vst_plugin_info ();
367 PluginInfoList::iterator i;
368 char ibuf[16], obuf[16];
371 std::string filterstr;
372 setup_filter_string (filterstr);
374 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
376 if (show_this_plugin (*i, filterstr)) {
377 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
378 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
380 TreeModel::Row newrow = *(vmodel->append());
381 newrow[vcols.name] = (*i)->name.c_str();
382 newrow[vcols.ins] = ibuf;
383 newrow[vcols.outs] = obuf;
384 newrow[vcols.plugin] = *i;
387 vmodel->set_sort_column (0, SORT_ASCENDING);
391 PluginSelector::vst_display_selection_changed()
393 if (vst_display.get_selection()->count_selected_rows() != 0) {
394 btn_add->set_sensitive (true);
396 btn_add->set_sensitive (false);
399 current_selection = ARDOUR::VST;
404 #ifdef HAVE_AUDIOUNIT
407 PluginSelector::au_refiller ()
410 PluginInfoList plugs (AUPluginInfo::discover ());
411 PluginInfoList::iterator i;
412 char ibuf[16], obuf[16];
415 std::string filterstr;
416 setup_filter_string (filterstr);
418 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
420 if (show_this_plugin (*i, filterstr)) {
422 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
423 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
425 TreeModel::Row newrow = *(aumodel->append());
426 newrow[aucols.name] = (*i)->name.c_str();
427 newrow[aucols.ins] = ibuf;
428 newrow[aucols.outs] = obuf;
429 newrow[aucols.plugin] = *i;
433 aumodel->set_sort_column (0, SORT_ASCENDING);
437 PluginSelector::au_display_selection_changed()
439 if (au_display.get_selection()->count_selected_rows() != 0) {
440 btn_add->set_sensitive (true);
442 btn_add->set_sensitive (false);
445 current_selection = ARDOUR::AudioUnit;
448 #endif //HAVE_AUDIOUNIT
451 PluginSelector::use_plugin (PluginInfoPtr pi)
457 PluginPtr plugin = pi->load (*session);
460 PluginCreated (plugin);
465 PluginSelector::btn_add_clicked()
469 TreeModel::Row newrow = *(amodel->append());
473 switch (current_selection) {
475 row = *(ladspa_display.get_selection()->get_selected());
476 name = row[lcols.name];
477 pi = row[lcols.plugin];
481 row = *(vst_display.get_selection()->get_selected());
482 name = row[vcols.name];
483 pi = row[vcols.plugin];
486 case ARDOUR::AudioUnit:
487 #ifdef HAVE_AUDIOUNIT
488 row = *(au_display.get_selection()->get_selected());
489 name = row[aucols.name];
490 pi = row[aucols.plugin];
494 error << "Programming error. Unknown plugin selected." << endmsg;
498 newrow[acols.text] = name;
499 newrow[acols.plugin] = pi;
501 if (!amodel->children().empty()) {
502 set_response_sensitive (RESPONSE_APPLY, true);
507 PluginSelector::btn_remove_clicked()
509 TreeModel::iterator iter = added_list.get_selection()->get_selected();
512 if (amodel->children().empty()) {
513 set_response_sensitive (RESPONSE_APPLY, false);
518 PluginSelector::btn_update_clicked()
525 PluginSelector::refill()
531 #ifdef HAVE_AUDIOUNIT
537 PluginSelector::ladspa_display_selection_changed()
539 if (ladspa_display.get_selection()->count_selected_rows() != 0) {
540 btn_add->set_sensitive (true);
542 btn_add->set_sensitive (false);
545 current_selection = ARDOUR::LADSPA;
549 PluginSelector::added_list_selection_changed()
551 if (added_list.get_selection()->count_selected_rows() != 0) {
552 btn_remove->set_sensitive (true);
554 btn_remove->set_sensitive (false);
559 PluginSelector::run ()
562 TreeModel::Children::iterator i;
564 r = (ResponseType) Dialog::run ();
568 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
569 use_plugin ((*i)[acols.plugin]);
583 PluginSelector::cleanup ()
590 PluginSelector::filter_button_clicked ()
592 filter_entry.set_text ("");
596 PluginSelector::filter_entry_changed ()
602 PluginSelector::filter_mode_changed ()