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[] = {
56 PluginSelector::PluginSelector (PluginManager *mgr)
57 : ArdourDialog (_("ardour: plugins"), true, false),
58 filter_button (_("Clear"))
60 set_position (Gtk::WIN_POS_MOUSE);
61 set_name ("PluginSelectorWindow");
62 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
67 current_selection = ARDOUR::LADSPA;
69 lmodel = Gtk::ListStore::create(lcols);
70 ladspa_display.set_model (lmodel);
71 ladspa_display.append_column (_("Available LADSPA Plugins"), lcols.name);
72 ladspa_display.append_column (_("Type"), lcols.type);
73 ladspa_display.append_column (_("# Inputs"),lcols.ins);
74 ladspa_display.append_column (_("# Outputs"), lcols.outs);
75 ladspa_display.set_headers_visible (true);
76 ladspa_display.set_headers_clickable (true);
77 ladspa_display.set_reorderable (false);
78 lscroller.set_border_width(10);
79 lscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
80 lscroller.add(ladspa_display);
82 amodel = Gtk::ListStore::create(acols);
83 added_list.set_model (amodel);
84 added_list.append_column (_("Plugins to be Connected to Insert"), acols.text);
85 added_list.set_headers_visible (true);
86 added_list.set_reorderable (false);
88 for (int i = 0; i <=3; i++) {
89 Gtk::TreeView::Column* column = ladspa_display.get_column(i);
90 column->set_sort_column(i);
94 vmodel = ListStore::create(vcols);
95 vst_display.set_model (vmodel);
96 vst_display.append_column (_("Available plugins"), vcols.name);
97 vst_display.append_column (_("# Inputs"), vcols.ins);
98 vst_display.append_column (_("# Outputs"), vcols.outs);
99 vst_display.set_headers_visible (true);
100 vst_display.set_headers_clickable (true);
101 vst_display.set_reorderable (false);
102 vscroller.set_border_width(10);
103 vscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
104 vscroller.add(vst_display);
106 for (int i = 0; i <=2; i++) {
107 Gtk::TreeView::Column* column = vst_display.get_column(i);
108 column->set_sort_column(i);
112 #ifdef HAVE_AUDIOUNIT
113 aumodel = ListStore::create(aucols);
114 au_display.set_model (aumodel);
115 au_display.append_column (_("Available plugins"), aucols.name);
116 au_display.append_column (_("# Inputs"), aucols.ins);
117 au_display.append_column (_("# Outputs"), aucols.outs);
118 au_display.set_headers_visible (true);
119 au_display.set_headers_clickable (true);
120 au_display.set_reorderable (false);
121 auscroller.set_border_width(10);
122 auscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
123 auscroller.add(au_display);
125 for (int i = 0; i <=2; i++) {
126 Gtk::TreeView::Column* column = au_display.get_column(i);
127 column->set_sort_column(i);
131 ascroller.set_border_width(10);
132 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
133 ascroller.add(added_list);
134 btn_add = manage(new Gtk::Button(Stock::ADD));
135 ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
136 btn_add->set_sensitive (false);
137 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
138 btn_remove->set_sensitive (false);
139 ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
140 Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
141 ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
143 btn_add->set_name("PluginSelectorButton");
144 btn_remove->set_name("PluginSelectorButton");
146 Gtk::Table* table = manage(new Gtk::Table(7, 11));
147 table->set_size_request(750, 500);
148 table->attach(notebook, 0, 7, 0, 5);
150 HBox* filter_box = manage (new HBox);
152 vector<string> filter_strings = I18N (_filter_mode_strings);
153 Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
154 filter_mode.set_active_text (filter_strings.front());
156 filter_box->pack_start (filter_mode, false, false);
157 filter_box->pack_start (filter_entry, true, true);
158 filter_box->pack_start (filter_button, false, false);
160 filter_entry.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_entry_changed));
161 filter_button.signal_clicked().connect (mem_fun (*this, &PluginSelector::filter_button_clicked));
162 filter_mode.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_mode_changed));
166 filter_entry.show ();
167 filter_button.show ();
169 table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
171 table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5);
172 table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
173 table->attach(*btn_update, 5, 6, 7, 7, FILL, FILL, 5, 5);
175 table->attach(ascroller, 0, 7, 8, 10);
177 add_button (Stock::CANCEL, RESPONSE_CANCEL);
178 add_button (Stock::CONNECT, RESPONSE_APPLY);
179 set_default_response (RESPONSE_APPLY);
180 set_response_sensitive (RESPONSE_APPLY, false);
181 get_vbox()->pack_start (*table);
184 // Notebook tab order must be the same in here as in set_correct_focus()
185 using namespace Notebook_Helpers;
186 notebook.pages().push_back (TabElem (lscroller, _("LADSPA")));
189 if (Config->get_use_vst()) {
190 notebook.pages().push_back (TabElem (vscroller, _("VST")));
194 #ifdef HAVE_AUDIOUNIT
195 notebook.pages().push_back (TabElem (auscroller, _("AudioUnit")));
198 table->set_name("PluginSelectorTable");
199 ladspa_display.set_name("PluginSelectorDisplay");
200 //ladspa_display.set_name("PluginSelectorList");
201 added_list.set_name("PluginSelectorList");
203 ladspa_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
204 ladspa_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::ladspa_display_selection_changed));
205 ladspa_display.grab_focus();
208 if (Config->get_use_vst()) {
209 vst_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
210 vst_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::vst_display_selection_changed));
214 #ifdef HAVE_AUDIOUNIT
215 au_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
216 au_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::au_display_selection_changed));
219 btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
220 btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
221 btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
222 added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
230 #ifdef HAVE_AUDIOUNIT
234 signal_show().connect (mem_fun (*this, &PluginSelector::set_correct_focus));
238 * Makes sure keyboard focus is always in the plugin list
239 * of the selected notebook tab.
242 PluginSelector::set_correct_focus()
244 int cp = notebook.get_current_page();
247 ladspa_display.grab_focus();
252 if (Config->get_use_vst()) {
256 vst_display.grab_focus();
262 #ifdef HAVE_AUDIOUNIT
266 au_display.grab_focus();
273 PluginSelector::row_clicked(GdkEventButton* event)
275 if (event->type == GDK_2BUTTON_PRESS)
280 PluginSelector::set_session (Session* s)
282 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
287 session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
292 PluginSelector::ladspa_refiller ()
295 PluginInfoList &plugs = manager->ladspa_plugin_info ();
296 PluginInfoList::iterator i;
297 char ibuf[16], obuf[16];
301 string mode = filter_mode.get_active_text ();
303 std::string filterstr = filter_entry.get_text ();
305 transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
307 // Insert into GTK list
309 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
310 snprintf (ibuf, sizeof(ibuf)-1, "%u", (*i)->n_inputs.n_total());
311 snprintf (obuf, sizeof(obuf)-1, "%u", (*i)->n_outputs.n_total());
317 if (!filterstr.empty()) {
319 if (mode == _("Plugin name")) {
320 compstr = (*i)->name;
321 } else if (mode == _("Plugin type")) {
322 compstr = (*i)->category;
323 } else if (mode == _("Plugin creator")) {
327 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
329 if (compstr.find (filterstr) != string::npos) {
339 TreeModel::Row newrow = *(lmodel->append());
340 newrow[lcols.name] = (*i)->name.c_str();
341 newrow[lcols.type] = (*i)->category.c_str();
342 newrow[lcols.ins] = ibuf;
343 newrow[lcols.outs] = obuf;
344 newrow[lcols.plugin] = *i;
348 lmodel->set_sort_column (0, SORT_ASCENDING);
354 PluginSelector::_vst_refiller (void *arg)
356 ((PluginSelector *) arg)->vst_refiller ();
360 PluginSelector::vst_refiller ()
363 PluginInfoList &plugs = manager->vst_plugin_info ();
364 PluginInfoList::iterator i;
365 char ibuf[16], obuf[16];
368 // Insert into GTK list
369 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
371 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
372 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
374 TreeModel::Row newrow = *(vmodel->append());
375 newrow[vcols.name] = (*i)->name.c_str();
376 newrow[vcols.ins] = ibuf;
377 newrow[vcols.outs] = obuf;
378 newrow[vcols.plugin] = *i;
380 vmodel->set_sort_column (0, SORT_ASCENDING);
384 PluginSelector::vst_display_selection_changed()
386 if (vst_display.get_selection()->count_selected_rows() != 0) {
387 btn_add->set_sensitive (true);
389 btn_add->set_sensitive (false);
392 current_selection = ARDOUR::VST;
397 #ifdef HAVE_AUDIOUNIT
400 PluginSelector::_au_refiller (void *arg)
402 ((PluginSelector *) arg)->au_refiller ();
406 PluginSelector::au_refiller ()
409 PluginInfoList plugs (AUPluginInfo::discover ());
410 PluginInfoList::iterator i;
411 char ibuf[16], obuf[16];
414 // Insert into GTK list
415 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
417 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
418 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
420 TreeModel::Row newrow = *(aumodel->append());
421 newrow[aucols.name] = (*i)->name.c_str();
422 newrow[aucols.ins] = ibuf;
423 newrow[aucols.outs] = obuf;
424 newrow[aucols.plugin] = *i;
426 aumodel->set_sort_column (0, SORT_ASCENDING);
430 PluginSelector::au_display_selection_changed()
432 if (au_display.get_selection()->count_selected_rows() != 0) {
433 btn_add->set_sensitive (true);
435 btn_add->set_sensitive (false);
438 current_selection = ARDOUR::AudioUnit;
441 #endif //HAVE_AUDIOUNIT
444 PluginSelector::use_plugin (PluginInfoPtr pi)
450 PluginPtr plugin = pi->load (*session);
453 PluginCreated (plugin);
458 PluginSelector::btn_add_clicked()
462 TreeModel::Row newrow = *(amodel->append());
466 switch (current_selection) {
468 row = *(ladspa_display.get_selection()->get_selected());
469 name = row[lcols.name];
470 pi = row[lcols.plugin];
474 row = *(vst_display.get_selection()->get_selected());
475 name = row[vcols.name];
476 pi = row[vcols.plugin];
479 case ARDOUR::AudioUnit:
480 #ifdef HAVE_AUDIOUNIT
481 row = *(au_display.get_selection()->get_selected());
482 name = row[aucols.name];
483 pi = row[aucols.plugin];
487 error << "Programming error. Unknown plugin selected." << endmsg;
491 newrow[acols.text] = name;
492 newrow[acols.plugin] = pi;
494 if (!amodel->children().empty()) {
495 set_response_sensitive (RESPONSE_APPLY, true);
500 PluginSelector::btn_remove_clicked()
502 TreeModel::iterator iter = added_list.get_selection()->get_selected();
505 if (amodel->children().empty()) {
506 set_response_sensitive (RESPONSE_APPLY, false);
511 PluginSelector::btn_update_clicked()
518 PluginSelector::refill()
524 #ifdef HAVE_AUDIOUNIT
530 PluginSelector::ladspa_display_selection_changed()
532 if (ladspa_display.get_selection()->count_selected_rows() != 0) {
533 btn_add->set_sensitive (true);
535 btn_add->set_sensitive (false);
538 current_selection = ARDOUR::LADSPA;
542 PluginSelector::added_list_selection_changed()
544 if (added_list.get_selection()->count_selected_rows() != 0) {
545 btn_remove->set_sensitive (true);
547 btn_remove->set_sensitive (false);
552 PluginSelector::run ()
555 TreeModel::Children::iterator i;
557 r = (ResponseType) Dialog::run ();
561 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
562 use_plugin ((*i)[acols.plugin]);
576 PluginSelector::cleanup ()
583 PluginSelector::filter_button_clicked ()
585 filter_entry.set_text ("");
589 PluginSelector::filter_entry_changed ()
595 PluginSelector::filter_mode_changed ()