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.
23 #include <gtkmm/table.h>
24 #include <gtkmm/stock.h>
25 #include <gtkmm/button.h>
26 #include <gtkmm/notebook.h>
28 #include <ardour/plugin_manager.h>
29 #include <ardour/plugin.h>
30 #include <ardour/configuration.h>
32 #include "ardour_ui.h"
33 #include "plugin_selector.h"
34 #include "gui_thread.h"
38 using namespace ARDOUR;
42 PluginSelector::PluginSelector (PluginManager *mgr)
43 : ArdourDialog (_("ardour: plugins"), true, false)
45 set_position (Gtk::WIN_POS_MOUSE);
46 set_name ("PluginSelectorWindow");
47 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
52 current_selection = ARDOUR::LADSPA;
54 lmodel = Gtk::ListStore::create(lcols);
55 ladspa_display.set_model (lmodel);
56 ladspa_display.append_column (_("Available LADSPA Plugins"), lcols.name);
57 ladspa_display.append_column (_("Type"), lcols.type);
58 ladspa_display.append_column (_("# Inputs"),lcols.ins);
59 ladspa_display.append_column (_("# Outputs"), lcols.outs);
60 ladspa_display.set_headers_visible (true);
61 ladspa_display.set_reorderable (false);
62 lscroller.set_border_width(10);
63 lscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
64 lscroller.add(ladspa_display);
66 amodel = Gtk::ListStore::create(acols);
67 added_list.set_model (amodel);
68 added_list.append_column (_("Plugins to be Connected to Insert"), acols.text);
69 added_list.set_headers_visible (true);
70 added_list.set_reorderable (false);
72 for (int i = 0; i <=3; i++) {
73 Gtk::TreeView::Column* column = ladspa_display.get_column(i);
74 column->set_sort_column(i);
78 vmodel = ListStore::create(vcols);
79 vst_display.set_model (vmodel);
80 vst_display.append_column (_("Available plugins"), vcols.name);
81 vst_display.append_column (_("# Inputs"), vcols.ins);
82 vst_display.append_column (_("# Outputs"), vcols.outs);
83 vst_display.set_headers_visible (true);
84 vst_display.set_reorderable (false);
85 vscroller.set_border_width(10);
86 vscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87 vscroller.add(vst_display);
89 for (int i = 0; i <=2; i++) {
90 Gtk::TreeView::Column* column = vst_display.get_column(i);
91 column->set_sort_column(i);
96 aumodel = ListStore::create(aucols);
97 au_display.set_model (aumodel);
98 au_display.append_column (_("Available plugins"), aucols.name);
99 au_display.append_column (_("# Inputs"), aucols.ins);
100 au_display.append_column (_("# Outputs"), aucols.outs);
101 au_display.set_headers_visible (true);
102 au_display.set_reorderable (false);
103 auscroller.set_border_width(10);
104 auscroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
105 auscroller.add(au_display);
107 for (int i = 0; i <=2; i++) {
108 Gtk::TreeView::Column* column = au_display.get_column(i);
109 column->set_sort_column(i);
113 ascroller.set_border_width(10);
114 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
115 ascroller.add(added_list);
116 btn_add = manage(new Gtk::Button(Stock::ADD));
117 ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
118 btn_add->set_sensitive (false);
119 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
120 btn_remove->set_sensitive (false);
121 ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
122 Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
123 ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
125 btn_add->set_name("PluginSelectorButton");
126 btn_remove->set_name("PluginSelectorButton");
128 Gtk::Table* table = manage(new Gtk::Table(7, 10));
129 table->set_size_request(750, 500);
130 table->attach(notebook, 0, 7, 0, 5);
132 table->attach(*btn_add, 1, 2, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
133 table->attach(*btn_remove, 3, 4, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
134 table->attach(*btn_update, 5, 6, 5, 6, Gtk::FILL, Gtk::FILL, 5, 5);
136 table->attach(ascroller, 0, 7, 7, 9);
138 add_button (Stock::CANCEL, RESPONSE_CANCEL);
139 add_button (Stock::CONNECT, RESPONSE_APPLY);
140 set_default_response (RESPONSE_APPLY);
141 set_response_sensitive (RESPONSE_APPLY, false);
142 get_vbox()->pack_start (*table);
144 // Notebook tab order must be the same in here as in set_correct_focus()
145 using namespace Gtk::Notebook_Helpers;
146 notebook.pages().push_back (TabElem (lscroller, _("LADSPA")));
149 if (Config->get_use_vst()) {
150 notebook.pages().push_back (TabElem (vscroller, _("VST")));
154 #ifdef HAVE_AUDIOUNIT
155 notebook.pages().push_back (TabElem (auscroller, _("AudioUnit")));
158 table->set_name("PluginSelectorTable");
159 ladspa_display.set_name("PluginSelectorDisplay");
160 //ladspa_display.set_name("PluginSelectorList");
161 added_list.set_name("PluginSelectorList");
163 ladspa_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
164 ladspa_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::ladspa_display_selection_changed));
165 ladspa_display.grab_focus();
168 if (Config->get_use_vst()) {
169 vst_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
170 vst_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::vst_display_selection_changed));
174 #ifdef HAVE_AUDIOUNIT
175 au_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
176 au_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::au_display_selection_changed));
179 btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
180 btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
181 btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
182 added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
190 #ifdef HAVE_AUDIOUNIT
194 signal_show().connect (mem_fun (*this, &PluginSelector::set_correct_focus));
198 * Makes sure keyboard focus is always in the plugin list
199 * of the selected notebook tab.
202 PluginSelector::set_correct_focus()
204 int cp = notebook.get_current_page();
207 ladspa_display.grab_focus();
212 if (Config->get_use_vst()) {
216 vst_display.grab_focus();
222 #ifdef HAVE_AUDIOUNIT
226 au_display.grab_focus();
233 PluginSelector::row_clicked(GdkEventButton* event)
235 if (event->type == GDK_2BUTTON_PRESS)
240 PluginSelector::set_session (Session* s)
242 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
247 session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
252 PluginSelector::_input_refiller (void *arg)
254 ((PluginSelector *) arg)->input_refiller ();
257 int compare(const void *left, const void *right)
259 return strcmp(*((char**)left), *((char**)right));
263 PluginSelector::input_refiller ()
266 PluginInfoList &plugs = manager->ladspa_plugin_info ();
267 PluginInfoList::iterator i;
268 char ibuf[16], obuf[16];
271 // Insert into GTK list
272 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
273 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
274 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
276 Gtk::TreeModel::Row newrow = *(lmodel->append());
277 newrow[lcols.name] = (*i)->name.c_str();
278 newrow[lcols.type] = (*i)->category.c_str();
279 newrow[lcols.ins] = ibuf;
280 newrow[lcols.outs] = obuf;
281 newrow[lcols.plugin] = *i;
284 lmodel->set_sort_column (0, Gtk::SORT_ASCENDING);
290 PluginSelector::_vst_refiller (void *arg)
292 ((PluginSelector *) arg)->vst_refiller ();
296 PluginSelector::vst_refiller ()
299 PluginInfoList &plugs = manager->vst_plugin_info ();
300 PluginInfoList::iterator i;
301 char ibuf[16], obuf[16];
304 // Insert into GTK list
305 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
307 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
308 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
310 Gtk::TreeModel::Row newrow = *(vmodel->append());
311 newrow[vcols.name] = (*i)->name.c_str();
312 newrow[vcols.ins] = ibuf;
313 newrow[vcols.outs] = obuf;
314 newrow[vcols.plugin] = *i;
316 vmodel->set_sort_column (0, Gtk::SORT_ASCENDING);
320 PluginSelector::vst_display_selection_changed()
322 if (vst_display.get_selection()->count_selected_rows() != 0) {
323 btn_add->set_sensitive (true);
325 btn_add->set_sensitive (false);
328 current_selection = ARDOUR::VST;
333 #ifdef HAVE_AUDIOUNIT
336 PluginSelector::_au_refiller (void *arg)
338 ((PluginSelector *) arg)->au_refiller ();
342 PluginSelector::au_refiller ()
345 PluginInfoList plugs (AUPluginInfo::discover ());
346 PluginInfoList::iterator i;
347 char ibuf[16], obuf[16];
350 // Insert into GTK list
351 for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
353 snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
354 snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);
356 Gtk::TreeModel::Row newrow = *(aumodel->append());
357 newrow[aucols.name] = (*i)->name.c_str();
358 newrow[aucols.ins] = ibuf;
359 newrow[aucols.outs] = obuf;
360 newrow[aucols.plugin] = *i;
362 aumodel->set_sort_column (0, Gtk::SORT_ASCENDING);
366 PluginSelector::au_display_selection_changed()
368 if (au_display.get_selection()->count_selected_rows() != 0) {
369 btn_add->set_sensitive (true);
371 btn_add->set_sensitive (false);
374 current_selection = ARDOUR::AudioUnit;
377 #endif //HAVE_AUDIOUNIT
380 PluginSelector::use_plugin (PluginInfoPtr pi)
386 PluginPtr plugin = pi->load (*session);
389 PluginCreated (plugin);
394 PluginSelector::btn_add_clicked()
398 Gtk::TreeModel::Row newrow = *(amodel->append());
400 Gtk::TreeModel::Row row;
402 switch (current_selection) {
404 row = *(ladspa_display.get_selection()->get_selected());
405 name = row[lcols.name];
406 pi = row[lcols.plugin];
410 row = *(vst_display.get_selection()->get_selected());
411 name = row[vcols.name];
412 pi = row[vcols.plugin];
415 case ARDOUR::AudioUnit:
416 #ifdef HAVE_AUDIOUNIT
417 row = *(au_display.get_selection()->get_selected());
418 name = row[aucols.name];
419 pi = row[aucols.plugin];
423 error << "Programming error. Unknown plugin selected." << endmsg;
427 newrow[acols.text] = name;
428 newrow[acols.plugin] = pi;
430 if (!amodel->children().empty()) {
431 set_response_sensitive (RESPONSE_APPLY, true);
436 PluginSelector::btn_remove_clicked()
438 Gtk::TreeModel::iterator iter = added_list.get_selection()->get_selected();
441 if (amodel->children().empty()) {
442 set_response_sensitive (RESPONSE_APPLY, false);
447 PluginSelector::btn_update_clicked()
454 #ifdef HAVE_AUDIOUNIT
460 PluginSelector::ladspa_display_selection_changed()
462 if (ladspa_display.get_selection()->count_selected_rows() != 0) {
463 btn_add->set_sensitive (true);
465 btn_add->set_sensitive (false);
468 current_selection = ARDOUR::LADSPA;
472 PluginSelector::added_list_selection_changed()
474 if (added_list.get_selection()->count_selected_rows() != 0) {
475 btn_remove->set_sensitive (true);
477 btn_remove->set_sensitive (false);
482 PluginSelector::run ()
485 TreeModel::Children::iterator i;
487 r = (ResponseType) Dialog::run ();
491 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
492 use_plugin ((*i)[acols.plugin]);
506 PluginSelector::cleanup ()