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 plugin_model = Gtk::ListStore::create (plugin_columns);
69 plugin_display.set_model (plugin_model);
70 plugin_display.append_column (_("Available Plugins"), plugin_columns.name);
71 plugin_display.append_column (_("Type"), plugin_columns.type_name);
72 plugin_display.append_column (_("Category"), plugin_columns.category);
73 plugin_display.append_column (_("Creator"), plugin_columns.creator);
74 plugin_display.append_column (_("# Audio In"),plugin_columns.audio_ins);
75 plugin_display.append_column (_("# Audio Out"), plugin_columns.audio_outs);
76 plugin_display.append_column (_("# MIDI In"),plugin_columns.midi_ins);
77 plugin_display.append_column (_("# MIDI Out"), plugin_columns.midi_outs);
78 plugin_display.set_headers_visible (true);
79 plugin_display.set_headers_clickable (true);
80 plugin_display.set_reorderable (false);
81 scroller.set_border_width(10);
82 scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
83 scroller.add(plugin_display);
85 amodel = Gtk::ListStore::create(acols);
86 added_list.set_model (amodel);
87 added_list.append_column (_("Plugins to be connected"), acols.text);
88 added_list.set_headers_visible (true);
89 added_list.set_reorderable (false);
91 for (int i = 0; i <=7; i++) {
92 Gtk::TreeView::Column* column = plugin_display.get_column(i);
93 column->set_sort_column(i);
96 ascroller.set_border_width(10);
97 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
98 ascroller.add(added_list);
99 btn_add = manage(new Gtk::Button(Stock::ADD));
100 ARDOUR_UI::instance()->tooltips().set_tip(*btn_add, _("Add a plugin to the effect list"));
101 btn_add->set_sensitive (false);
102 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
103 btn_remove->set_sensitive (false);
104 ARDOUR_UI::instance()->tooltips().set_tip(*btn_remove, _("Remove a plugin from the effect list"));
105 Gtk::Button *btn_update = manage(new Gtk::Button(Stock::REFRESH));
106 ARDOUR_UI::instance()->tooltips().set_tip(*btn_update, _("Update available plugins"));
108 btn_add->set_name("PluginSelectorButton");
109 btn_remove->set_name("PluginSelectorButton");
111 Gtk::Table* table = manage(new Gtk::Table(7, 11));
112 table->set_size_request(750, 500);
113 table->attach(scroller, 0, 7, 0, 5);
115 HBox* filter_box = manage (new HBox);
117 vector<string> filter_strings = I18N (_filter_mode_strings);
118 Gtkmm2ext::set_popdown_strings (filter_mode, filter_strings);
119 filter_mode.set_active_text (filter_strings.front());
121 filter_box->pack_start (filter_mode, false, false);
122 filter_box->pack_start (filter_entry, true, true);
123 filter_box->pack_start (filter_button, false, false);
125 filter_entry.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_entry_changed));
126 filter_button.signal_clicked().connect (mem_fun (*this, &PluginSelector::filter_button_clicked));
127 filter_mode.signal_changed().connect (mem_fun (*this, &PluginSelector::filter_mode_changed));
131 filter_entry.show ();
132 filter_button.show ();
134 table->attach (*filter_box, 0, 7, 5, 6, FILL|EXPAND, FILL, 5, 5);
136 table->attach(*btn_add, 1, 2, 6, 7, FILL, FILL, 5, 5);
137 table->attach(*btn_remove, 3, 4, 6, 7, FILL, FILL, 5, 5);
138 table->attach(*btn_update, 5, 6, 6, 7, FILL, FILL, 5, 5);
140 table->attach(ascroller, 0, 7, 8, 10);
142 add_button (Stock::CANCEL, RESPONSE_CANCEL);
143 add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
144 set_default_response (RESPONSE_APPLY);
145 set_response_sensitive (RESPONSE_APPLY, false);
146 get_vbox()->pack_start (*table);
148 table->set_name("PluginSelectorTable");
149 plugin_display.set_name("PluginSelectorDisplay");
150 //plugin_display.set_name("PluginSelectorList");
151 added_list.set_name("PluginSelectorList");
153 plugin_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked));
154 plugin_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::display_selection_changed));
155 plugin_display.grab_focus();
157 btn_update->signal_clicked().connect (mem_fun(*this, &PluginSelector::btn_update_clicked));
158 btn_add->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_add_clicked));
159 btn_remove->signal_clicked().connect(mem_fun(*this, &PluginSelector::btn_remove_clicked));
160 added_list.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::added_list_selection_changed));
166 PluginSelector::row_clicked(GdkEventButton* event)
168 if (event->type == GDK_2BUTTON_PRESS)
173 PluginSelector::set_session (Session* s)
175 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginSelector::set_session), s));
180 session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast<Session*> (0)));
185 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& filterstr)
188 std::string mode = filter_mode.get_active_text ();
190 if (!filterstr.empty()) {
192 if (mode == _("Name contains")) {
193 compstr = info->name;
194 } else if (mode == _("Type contains")) {
195 compstr = info->category;
196 } else if (mode == _("Author contains")) {
197 compstr = info->creator;
198 } else if (mode == _("Library contains")) {
199 compstr = info->path;
202 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
204 if (compstr.find (filterstr) != string::npos) {
216 PluginSelector::setup_filter_string (string& filterstr)
218 filterstr = filter_entry.get_text ();
219 transform (filterstr.begin(), filterstr.end(), filterstr.begin(), ::toupper);
223 PluginSelector::refill ()
225 std::string filterstr;
227 plugin_model->clear ();
229 setup_filter_string (filterstr);
231 ladspa_refiller (filterstr);
232 lv2_refiller (filterstr);
233 vst_refiller (filterstr);
234 au_refiller (filterstr);
238 PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filterstr, const char* type)
242 for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
244 if (show_this_plugin (*i, filterstr)) {
246 TreeModel::Row newrow = *(plugin_model->append());
247 newrow[plugin_columns.name] = (*i)->name;
248 newrow[plugin_columns.type_name] = type;
249 newrow[plugin_columns.category] = (*i)->category;
252 string creator = (*i)->creator;
253 string::size_type pos = 0;
255 /* stupid LADSPA creator strings */
257 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
258 creator = creator.substr (0, pos);
260 newrow[plugin_columns.creator] = creator;
262 if ((*i)->n_inputs.n_total() < 0) {
263 newrow[plugin_columns.audio_ins] = "various";
264 newrow[plugin_columns.midi_ins] = "various";
266 snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_audio());
267 newrow[plugin_columns.audio_ins] = buf;
268 snprintf (buf, sizeof(buf), "%d", (*i)->n_inputs.n_midi());
269 newrow[plugin_columns.midi_ins] = buf;
271 if ((*i)->n_outputs.n_total() < 0) {
272 newrow[plugin_columns.audio_outs] = "various";
273 newrow[plugin_columns.midi_outs] = "various";
275 snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_audio());
276 newrow[plugin_columns.audio_outs] = buf;
277 snprintf (buf, sizeof(buf), "%d", (*i)->n_outputs.n_midi());
278 newrow[plugin_columns.midi_outs] = buf;
281 newrow[plugin_columns.plugin] = *i;
287 PluginSelector::ladspa_refiller (const std::string& filterstr)
289 refiller (manager->ladspa_plugin_info(), filterstr, "LADSPA");
293 PluginSelector::lv2_refiller (const std::string& filterstr)
296 refiller (manager->lv2_plugin_info(), filterstr, "LV2");
301 PluginSelector::vst_refiller (const std::string& filterstr)
304 refiller (manager->vst_plugin_info(), filterstr, "VST");
309 PluginSelector::au_refiller (const std::string& filterstr)
311 #ifdef HAVE_AUDIOUNITS
312 refiller (manager->au_plugin_info(), filterstr, "AU");
317 PluginSelector::use_plugin (PluginInfoPtr pi)
323 PluginPtr plugin = pi->load (*session);
326 PluginCreated (plugin);
331 PluginSelector::btn_add_clicked()
335 TreeModel::Row newrow = *(amodel->append());
338 row = *(plugin_display.get_selection()->get_selected());
339 name = row[plugin_columns.name];
340 pi = row[plugin_columns.plugin];
342 newrow[acols.text] = name;
343 newrow[acols.plugin] = pi;
345 if (!amodel->children().empty()) {
346 set_response_sensitive (RESPONSE_APPLY, true);
351 PluginSelector::btn_remove_clicked()
353 TreeModel::iterator iter = added_list.get_selection()->get_selected();
356 if (amodel->children().empty()) {
357 set_response_sensitive (RESPONSE_APPLY, false);
362 PluginSelector::btn_update_clicked()
369 PluginSelector::display_selection_changed()
371 if (plugin_display.get_selection()->count_selected_rows() != 0) {
372 btn_add->set_sensitive (true);
374 btn_add->set_sensitive (false);
379 PluginSelector::added_list_selection_changed()
381 if (added_list.get_selection()->count_selected_rows() != 0) {
382 btn_remove->set_sensitive (true);
384 btn_remove->set_sensitive (false);
389 PluginSelector::run ()
392 TreeModel::Children::iterator i;
394 r = (ResponseType) Dialog::run ();
398 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
399 PluginInfoPtr pp = (*i)[acols.plugin];
414 PluginSelector::cleanup ()
421 PluginSelector::filter_button_clicked ()
423 filter_entry.set_text ("");
427 PluginSelector::filter_entry_changed ()
433 PluginSelector::filter_mode_changed ()
439 PluginSelector::on_show ()
441 ArdourDialog::on_show ();
442 filter_entry.grab_focus ();