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.
20 #include "gtk2ardour-config.h"
28 #include <gtkmm/button.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/frame.h>
31 #include <gtkmm/messagedialog.h>
32 #include <gtkmm/notebook.h>
33 #include <gtkmm/stock.h>
34 #include <gtkmm/table.h>
36 #include "gtkmm2ext/utils.h"
38 #include "widgets/tooltips.h"
40 #include "pbd/convert.h"
41 #include "pbd/tokenizer.h"
43 #include "ardour/utils.h"
45 #include "plugin_selector.h"
46 #include "gui_thread.h"
50 using namespace ARDOUR;
54 using namespace ArdourWidgets;
56 static const uint32_t MAX_CREATOR_LEN = 24;
58 PluginSelector::PluginSelector (PluginManager& mgr)
59 : ArdourDialog (_("Plugin Manager"), true, false)
60 , search_clear_button (Stock::CLEAR)
62 , inhibit_refill (false)
64 set_name ("PluginSelectorWindow");
65 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
68 in_row_change = false;
70 manager.PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
71 manager.PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::refill, this), gui_context());
72 manager.PluginStatusesChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::plugin_status_changed, this, _1, _2, _3), gui_context());
73 manager.PluginTagsChanged.connect(plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::tags_changed, this, _1, _2, _3), gui_context());
75 plugin_model = Gtk::ListStore::create (plugin_columns);
76 plugin_display.set_model (plugin_model);
77 /* XXX translators: try to convert "Fav" into a short term
78 * related to "favorite" and "Hid" into a short term
81 plugin_display.append_column (_("Fav"), plugin_columns.favorite);
82 plugin_display.append_column (_("Hide"), plugin_columns.hidden);
83 plugin_display.append_column (_("Name"), plugin_columns.name);
84 plugin_display.append_column (_("Tags"), plugin_columns.tags);
85 plugin_display.append_column (_("Creator"), plugin_columns.creator);
86 plugin_display.append_column (_("Type"), plugin_columns.type_name);
87 plugin_display.append_column (_("Audio I/O"),plugin_columns.audio_io);
88 plugin_display.append_column (_("MIDI I/O"), plugin_columns.midi_io);
89 plugin_display.set_headers_visible (true);
90 plugin_display.set_headers_clickable (true);
91 plugin_display.set_reorderable (false);
92 plugin_display.set_rules_hint (true);
93 plugin_display.add_object_drag (plugin_columns.plugin.index(), "PluginInfoPtr");
94 plugin_display.set_drag_column (plugin_columns.name.index());
96 // setting a sort-column prevents re-ordering via Drag/Drop
97 plugin_model->set_sort_column (plugin_columns.name.index(), Gtk::SORT_ASCENDING);
99 plugin_display.set_name("PluginSelectorDisplay");
100 plugin_display.signal_row_activated().connect_notify (sigc::mem_fun(*this, &PluginSelector::row_activated));
101 plugin_display.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::display_selection_changed));
103 CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
104 fav_cell->property_activatable() = true;
105 fav_cell->property_radio() = true;
106 fav_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::favorite_changed));
108 CellRendererToggle* hidden_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (1));
109 hidden_cell->property_activatable() = true;
110 hidden_cell->property_radio() = true;
111 hidden_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::hidden_changed));
113 scroller.set_border_width(10);
114 scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
115 scroller.add(plugin_display);
117 amodel = Gtk::ListStore::create(acols);
118 added_list.set_model (amodel);
119 added_list.append_column (_("Plugins to be connected"), acols.text);
120 added_list.set_headers_visible (true);
121 added_list.set_reorderable (false);
123 for (int i = 2; i <=7; i++) {
124 Gtk::TreeView::Column* column = plugin_display.get_column(i);
126 column->set_sort_column(i);
130 ascroller.set_border_width(10);
131 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132 ascroller.add(added_list);
133 btn_add = manage(new Gtk::Button(Stock::ADD));
134 set_tooltip(*btn_add, _("Add a plugin to the effect list"));
135 btn_add->set_sensitive (false);
136 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
137 btn_remove->set_sensitive (false);
138 set_tooltip(*btn_remove, _("Remove a plugin from the effect list"));
140 btn_add->set_name("PluginSelectorButton");
141 btn_remove->set_name("PluginSelectorButton");
145 Gtk::Table* search_table = manage(new Gtk::Table(2, 2));
147 search_entry.signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::search_entry_changed));
148 search_clear_button.signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::search_clear_button_clicked));
150 _search_name_checkbox = manage (new CheckButton (_("Name")));
151 _search_name_checkbox->set_active();
153 _search_tags_checkbox = manage (new CheckButton (_("Tags")));
154 _search_tags_checkbox->set_active();
156 _search_ignore_checkbox = manage (new CheckButton(_("Ignore Filters when searching")));
157 _search_ignore_checkbox->set_active();
158 _search_ignore_checkbox->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::set_sensitive_widgets));
160 Gtk::Label* search_help_label1 = manage (new Label(
161 _("All search terms must be matched."), Gtk::ALIGN_LEFT));
163 Gtk::Label* search_help_label2 = manage (new Label(
164 _("Ex: \"ess dyn\" will return \"dynamic de-esser\" but not \"de-esser\"."), Gtk::ALIGN_LEFT));
166 search_table->attach (search_entry, 0, 3, 0, 1, FILL|EXPAND, FILL);
167 search_table->attach (search_clear_button, 3, 4, 0, 1, FILL, FILL);
168 search_table->attach (*_search_name_checkbox, 0, 1, 1, 2, FILL, FILL);
169 search_table->attach (*_search_tags_checkbox, 1, 2, 1, 2, FILL, FILL);
170 search_table->attach (*_search_ignore_checkbox,2, 3, 1, 2, FILL, FILL);
171 search_table->attach (*search_help_label1, 0, 3, 2, 3, FILL, FILL);
172 search_table->attach (*search_help_label2, 0, 3, 3, 4, FILL, FILL);
174 search_table->set_border_width (4);
175 search_table->set_col_spacings (2);
176 search_table->set_row_spacings (4);
178 Frame* search_frame = manage (new Frame);
179 search_frame->set_name ("BaseFrame");
180 search_frame->set_label (_("Search"));
181 search_frame->add (*search_table);
182 search_frame->show_all ();
184 _search_name_checkbox->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
185 _search_tags_checkbox->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
189 Gtk::Table* filter_table = manage(new Gtk::Table(1, 10));
191 Gtk::RadioButtonGroup fil_radio_group;
193 _fil_effects_radio = manage (new RadioButton (fil_radio_group, _("Show Effects Only")));
194 _fil_instruments_radio = manage (new RadioButton (fil_radio_group, _("Show Instruments Only")));
195 _fil_utils_radio = manage (new RadioButton (fil_radio_group, _("Show Utilities Only")));
196 _fil_favorites_radio = manage (new RadioButton (fil_radio_group, _("Show Favorites Only")));
197 _fil_hidden_radio = manage (new RadioButton (fil_radio_group, _("Show Hidden Only")));
198 _fil_all_radio = manage (new RadioButton (fil_radio_group, _("Show All")));
201 _fil_all_radio->set_active ();
204 _fil_type_combo = manage (new ComboBoxText);
205 _fil_type_combo->append_text (_("Show All Formats"));
206 _fil_type_combo->append_text (X_("VST"));
207 #ifdef AUDIOUNIT_SUPPORT
208 _fil_type_combo->append_text (X_("AudioUnit"));
211 _fil_type_combo->append_text (X_("LV2"));
213 _fil_type_combo->append_text (X_("LUA"));
214 _fil_type_combo->append_text (X_("LADSPA"));
215 _fil_type_combo->set_active_text (_("Show All Formats"));
217 _fil_creator_combo = manage (new ComboBoxText);
218 //note: _fil_creator_combo menu gets filled in build_plugin_menu
220 _fil_channel_combo = manage (new ComboBoxText);
221 _fil_channel_combo->append_text (_("Audio I/O"));
222 _fil_channel_combo->append_text (_("Mono Audio I/O"));
223 _fil_channel_combo->append_text (_("Stereo Audio I/O"));
224 _fil_channel_combo->append_text (_("MIDI I/O (only)"));
225 _fil_channel_combo->append_text (_("Show All I/O"));
227 _fil_channel_combo->set_active_text (_("Audio I/O"));
229 _fil_channel_combo->set_active_text (_("Show All I/O"));
233 filter_table->attach (*_fil_effects_radio, 2, 3, p, p+1, FILL, FILL); p++;
234 filter_table->attach (*_fil_instruments_radio, 2, 3, p, p+1, FILL, FILL); p++;
235 filter_table->attach (*_fil_utils_radio, 2, 3, p, p+1, FILL, FILL); p++;
236 filter_table->attach (*_fil_favorites_radio, 2, 3, p, p+1, FILL, FILL); p++;
237 filter_table->attach (*_fil_hidden_radio, 2, 3, p, p+1, FILL, FILL); p++;
238 filter_table->attach (*_fil_all_radio, 2, 3, p, p+1, FILL, FILL); p++;
239 filter_table->attach (*_fil_type_combo, 2, 3, p, p+1, FILL, FILL); p++;
240 filter_table->attach (*_fil_creator_combo, 2, 3, p, p+1, FILL, FILL); p++;
241 filter_table->attach (*_fil_channel_combo, 2, 3, p, p+1, FILL, FILL); p++;
243 filter_table->set_border_width (4);
244 filter_table->set_col_spacings (4);
245 filter_table->set_row_spacings (4);
247 Frame* filter_frame = manage (new Frame);
248 filter_frame->set_name ("BaseFrame");
249 filter_frame->set_label (_("Filter"));
250 filter_frame->add (*filter_table);
251 filter_frame->show_all ();
253 _fil_effects_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
254 _fil_instruments_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
255 _fil_utils_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
256 _fil_favorites_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
257 _fil_hidden_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
259 _fil_type_combo->signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::refill));
260 _fil_creator_combo->signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::refill));
261 _fil_channel_combo->signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::refill));
265 Gtk::Table* tagging_table = manage(new Gtk::Table(1, 2));
266 tagging_table->set_border_width (4);
267 tagging_table->set_col_spacings (4);
268 tagging_table->set_row_spacings (4);
270 tag_entry = manage (new Gtk::Entry);
271 tag_entry_connection = tag_entry->signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::tag_entry_changed));
273 Gtk::Button* tag_reset_button = manage (new Button (_("Reset")));
274 tag_reset_button->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::tag_reset_button_clicked));
276 Gtk::Label* tagging_help_label1 = manage (new Label(
277 _("Enter space-separated, one-word Tags for the selected plugin."), Gtk::ALIGN_LEFT));
279 Gtk::Label* tagging_help_label2 = manage (new Label(
280 _("You can include dashes, colons or underscores in a Tag."), Gtk::ALIGN_LEFT));
282 Gtk::Label* tagging_help_label3 = manage (new Label(
283 _("Ex: \"dynamic de-esser vocal\" applies 3 Tags."), Gtk::ALIGN_LEFT));
286 tagging_table->attach (*tag_entry, 0, 1, p, p+1, FILL|EXPAND, FILL);
287 tagging_table->attach (*tag_reset_button, 1, 2, p, p+1, FILL, FILL); p++;
288 tagging_table->attach (*tagging_help_label1, 0, 2, p, p+1, FILL, FILL); p++;
289 tagging_table->attach (*tagging_help_label2, 0, 2, p, p+1, FILL, FILL); p++;
290 tagging_table->attach (*tagging_help_label3, 0, 2, p, p+1, FILL, FILL); p++;
292 Frame* tag_frame = manage (new Frame);
293 tag_frame->set_name ("BaseFrame");
294 tag_frame->set_label (_("Tags for Selected Plugin"));
295 tag_frame->add (*tagging_table);
296 tag_frame->show_all ();
298 /* Add & remove buttons */
300 HBox* add_remove = manage (new HBox);
301 add_remove->pack_start (*btn_add, true, true);
302 add_remove->pack_start (*btn_remove, true, true);
304 btn_add->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_add_clicked));
305 btn_remove->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_remove_clicked));
306 added_list.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::added_list_selection_changed));
307 added_list.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::added_row_clicked));
309 added_list.set_name("PluginSelectorList");
311 /* Top-level Layout */
313 VBox* to_be_inserted_vbox = manage (new VBox);
314 to_be_inserted_vbox->pack_start (ascroller);
315 to_be_inserted_vbox->pack_start (*add_remove, false, false);
316 to_be_inserted_vbox->set_size_request (200, -1);
318 Gtk::Table* table = manage(new Gtk::Table(3, 3));
319 table->set_size_request(-1, 600);
320 table->attach (scroller, 0, 3, 0, 5); /* this is the main plugin list */
321 table->attach (*search_frame, 0, 1, 6, 7, FILL, FILL, 5, 5);
322 table->attach (*tag_frame, 0, 1, 7, 8, FILL, FILL, 5, 5);
323 table->attach (*filter_frame, 1, 2, 6, 8, FILL, FILL, 5, 5);
324 table->attach (*to_be_inserted_vbox, 2, 3, 6, 8, FILL|EXPAND, FILL, 5, 5); /* to be inserted... */
326 add_button (Stock::CLOSE, RESPONSE_CLOSE);
327 add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
328 set_default_response (RESPONSE_APPLY);
329 set_response_sensitive (RESPONSE_APPLY, false);
330 get_vbox()->pack_start (*table);
332 table->set_name("PluginSelectorTable");
334 plugin_display.grab_focus();
336 build_plugin_menu ();
339 PluginSelector::~PluginSelector ()
345 PluginSelector::row_activated(Gtk::TreeModel::Path, Gtk::TreeViewColumn*)
351 PluginSelector::added_row_clicked(GdkEventButton* event)
353 if (event->type == GDK_2BUTTON_PRESS)
354 btn_remove_clicked();
358 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& searchstr)
361 bool maybe_show = false;
363 if (!searchstr.empty()) {
367 if (_search_name_checkbox->get_active()) { /* name contains */
368 compstr = info->name;
369 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
370 if (compstr.find (searchstr) != string::npos) {
375 if (_search_tags_checkbox->get_active()) { /* tag contains */
376 compstr = manager.get_tags_as_string (info);
377 transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper);
378 if (compstr.find (searchstr) != string::npos) {
387 /* user asked to ignore filters */
388 if (maybe_show && _search_ignore_checkbox->get_active()) {
393 if (_fil_effects_radio->get_active() && !info->is_effect()) {
397 if (_fil_instruments_radio->get_active() && !info->is_instrument()) {
401 if (_fil_utils_radio->get_active() && !(info->is_utility() || info->is_analyzer())) {
405 if (_fil_favorites_radio->get_active() && !(manager.get_status (info) == PluginManager::Favorite)) {
409 if (_fil_hidden_radio->get_active() && !(manager.get_status (info) == PluginManager::Hidden)) {
413 if (manager.get_status (info) == PluginManager::Hidden) {
414 if (!_fil_hidden_radio->get_active() && !_fil_all_radio->get_active()) {
419 /* Filter "type" combobox */
421 if (_fil_type_combo->get_active_text() == X_("VST") && PluginManager::to_generic_vst(info->type) != LXVST) {
425 if (_fil_type_combo->get_active_text() == X_("AudioUnit") && info->type != AudioUnit) {
430 if (_fil_type_combo->get_active_text() == X_("LV2") && info->type != LV2) {
435 if (_fil_type_combo->get_active_text() == X_("LUA") && info->type != Lua) {
439 if (_fil_type_combo->get_active_text() == X_("LADSPA") && info->type != LADSPA) {
443 /* Filter "creator" combobox */
445 if (_fil_creator_combo->get_active_text() != _("Show All Creators")) {
446 string cmp = info->creator;
447 if (cmp.length() > MAX_CREATOR_LEN) {
448 cmp = cmp.substr (0, MAX_CREATOR_LEN);
451 if (_fil_creator_combo->get_active_text() != cmp) {
456 /* Filter "I/O" combobox */
458 if (_fil_channel_combo->get_active_text() != _("Show All I/O") || info->reconfigurable_io ()) {
461 if (info->reconfigurable_io ()) {
462 return true; // who knows.... ?
466 if (_fil_channel_combo->get_active_text() == _("Audio I/O")) {
467 if ((info->n_inputs.n_audio() == 0 || info->n_outputs.n_audio() == 0)) {
472 if (_fil_channel_combo->get_active_text() == _("Mono Audio I/O")) {
473 if (info->n_inputs.n_audio() != 1 || info->n_outputs.n_audio() != 1) {
478 if (_fil_channel_combo->get_active_text() == _("Stereo Audio I/O")) {
479 if (info->n_inputs.n_audio() != 2 || info->n_outputs.n_audio() != 2) {
484 if (_fil_channel_combo->get_active_text() == _("MIDI I/O (only)")) {
485 if ((info->n_inputs.n_audio() != 0 || info->n_outputs.n_audio() == 0)) {
496 PluginSelector::setup_search_string (string& searchstr)
498 searchstr = search_entry.get_text ();
499 transform (searchstr.begin(), searchstr.end(), searchstr.begin(), ::toupper);
503 PluginSelector::set_sensitive_widgets ()
505 if (_search_ignore_checkbox->get_active() && (search_entry.get_text() != "")) {
506 _fil_effects_radio->set_sensitive(false);
507 _fil_instruments_radio->set_sensitive(false);
508 _fil_utils_radio->set_sensitive(false);
509 _fil_favorites_radio->set_sensitive(false);
510 _fil_hidden_radio->set_sensitive(false);
511 _fil_all_radio->set_sensitive(false);
512 _fil_type_combo->set_sensitive(false);
513 _fil_creator_combo->set_sensitive(false);
514 _fil_channel_combo->set_sensitive(false);
516 _fil_effects_radio->set_sensitive(true);
517 _fil_instruments_radio->set_sensitive(true);
518 _fil_utils_radio->set_sensitive(true);
519 _fil_favorites_radio->set_sensitive(true);
520 _fil_hidden_radio->set_sensitive(true);
521 _fil_all_radio->set_sensitive(true);
522 _fil_type_combo->set_sensitive(true);
523 _fil_creator_combo->set_sensitive(true);
524 _fil_channel_combo->set_sensitive(true);
529 PluginSelector::refill ()
531 if (inhibit_refill) {
535 std::string searchstr;
537 in_row_change = true;
539 plugin_model->clear ();
541 setup_search_string (searchstr);
543 ladspa_refiller (searchstr);
544 lv2_refiller (searchstr);
545 vst_refiller (searchstr);
546 lxvst_refiller (searchstr);
547 mac_vst_refiller (searchstr);
548 au_refiller (searchstr);
549 lua_refiller (searchstr);
551 in_row_change = false;
555 PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& searchstr, const char* type)
559 for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
561 if (show_this_plugin (*i, searchstr)) {
563 TreeModel::Row newrow = *(plugin_model->append());
564 newrow[plugin_columns.favorite] = (manager.get_status (*i) == PluginManager::Favorite);
565 newrow[plugin_columns.hidden] = (manager.get_status (*i) == PluginManager::Hidden);
567 string name = (*i)->name;
568 if (name.length() > 48) {
569 name = name.substr (0, 48);
572 newrow[plugin_columns.name] = name;
574 newrow[plugin_columns.type_name] = type;
575 newrow[plugin_columns.category] = (*i)->category;
578 string creator = (*i)->creator;
579 string::size_type pos = 0;
580 if ((*i)->type == ARDOUR::LADSPA) {
581 /* stupid LADSPA creator strings */
582 #ifdef PLATFORM_WINDOWS
583 while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
585 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
588 pos = creator.length ();
590 // If there were too few characters to create a
591 // meaningful name, mark this creator as 'Unknown'
592 if (creator.length() < 2 || pos < 3) {
595 creator = creator.substr (0, pos);
598 if (creator.length() > MAX_CREATOR_LEN) {
599 creator = creator.substr (0, MAX_CREATOR_LEN);
600 creator.append("...");
602 newrow[plugin_columns.creator] = creator;
605 string tags = manager.get_tags_as_string(*i);
606 if (tags.length() > 32) {
607 tags = tags.substr (0, 32);
610 newrow[plugin_columns.tags] = tags;
612 if ((*i)->reconfigurable_io ()) {
613 newrow[plugin_columns.audio_io] = "* / *";
614 newrow[plugin_columns.midi_io] = "* / *";
616 snprintf (buf, sizeof(buf), "%d / %d", (*i)->n_inputs.n_audio(), (*i)->n_outputs.n_audio());
617 newrow[plugin_columns.audio_io] = buf;
618 snprintf (buf, sizeof(buf), "%d / %d", (*i)->n_inputs.n_audio(), (*i)->n_outputs.n_audio());
619 newrow[plugin_columns.midi_io] = buf;
622 newrow[plugin_columns.plugin] = *i;
628 PluginSelector::ladspa_refiller (const std::string& searchstr)
630 refiller (manager.ladspa_plugin_info(), searchstr, "LADSPA");
634 PluginSelector::lua_refiller (const std::string& searchstr)
636 refiller (manager.lua_plugin_info(), searchstr, "Lua");
640 PluginSelector::lv2_refiller (const std::string& searchstr)
643 refiller (manager.lv2_plugin_info(), searchstr, "LV2");
648 #ifdef WINDOWS_VST_SUPPORT
649 PluginSelector::vst_refiller (const std::string& searchstr)
651 PluginSelector::vst_refiller (const std::string&)
654 #ifdef WINDOWS_VST_SUPPORT
655 refiller (manager.windows_vst_plugin_info(), searchstr, "VST");
661 PluginSelector::lxvst_refiller (const std::string& searchstr)
663 PluginSelector::lxvst_refiller (const std::string&)
667 refiller (manager.lxvst_plugin_info(), searchstr, "LXVST");
672 #ifdef MACVST_SUPPORT
673 PluginSelector::mac_vst_refiller (const std::string& searchstr)
675 PluginSelector::mac_vst_refiller (const std::string&)
678 #ifdef MACVST_SUPPORT
679 refiller (manager.mac_vst_plugin_info(), searchstr, "MacVST");
684 #ifdef AUDIOUNIT_SUPPORT
685 PluginSelector::au_refiller (const std::string& searchstr)
687 PluginSelector::au_refiller (const std::string&)
690 #ifdef AUDIOUNIT_SUPPORT
691 refiller (manager.au_plugin_info(), searchstr, "AU");
696 PluginSelector::load_plugin (PluginInfoPtr pi)
702 return pi->load (*_session);
706 PluginSelector::btn_add_clicked()
710 TreeModel::Row newrow = *(amodel->append());
713 row = *(plugin_display.get_selection()->get_selected());
714 name = row[plugin_columns.name];
715 pi = row[plugin_columns.plugin];
717 newrow[acols.text] = name;
718 newrow[acols.plugin] = pi;
720 if (!amodel->children().empty()) {
721 set_response_sensitive (RESPONSE_APPLY, true);
726 PluginSelector::btn_remove_clicked()
728 TreeModel::iterator iter = added_list.get_selection()->get_selected();
731 if (amodel->children().empty()) {
732 set_response_sensitive (RESPONSE_APPLY, false);
737 PluginSelector::display_selection_changed()
739 tag_entry_connection.block ();
740 if (plugin_display.get_selection()->count_selected_rows() != 0) {
742 /* a plugin row is selected; allow the user to edit the "tags" on it. */
743 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
744 string tags = manager.get_tags_as_string (row[plugin_columns.plugin]);
745 tag_entry->set_text (tags);
747 tag_entry->set_sensitive (true);
748 btn_add->set_sensitive (true);
751 tag_entry->set_text ("");
753 tag_entry->set_sensitive (false);
754 btn_add->set_sensitive (false);
756 tag_entry_connection.unblock ();
760 PluginSelector::added_list_selection_changed()
762 if (added_list.get_selection()->count_selected_rows() != 0) {
763 btn_remove->set_sensitive (true);
765 btn_remove->set_sensitive (false);
770 PluginSelector::run ()
773 TreeModel::Children::iterator i;
779 SelectedPlugins plugins;
780 r = (ResponseType) Dialog::run ();
784 for (i = amodel->children().begin(); i != amodel->children().end(); ++i) {
785 PluginInfoPtr pp = (*i)[acols.plugin];
786 PluginPtr p = load_plugin (pp);
788 plugins.push_back (p);
790 MessageDialog msg (string_compose (_("The plugin \"%1\" could not be loaded\n\nSee the Log window for more details (maybe)"), pp->name));
794 if (interested_object && !plugins.empty()) {
795 finish = !interested_object->use_plugins (plugins);
809 interested_object = 0;
811 if (_need_tag_save) {
815 if (_need_status_save) {
816 manager.save_statuses();
819 if (_need_menu_rebuild) {
827 PluginSelector::search_clear_button_clicked ()
829 search_entry.set_text ("");
833 PluginSelector::tag_reset_button_clicked ()
835 /* XXX: this should probably be a backend function
836 * -> remove "category" from GUI and code-dup to set
837 * factory tags in PluginManager */
838 if (plugin_display.get_selection()->count_selected_rows() != 0) {
839 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
840 std::string str = row[plugin_columns.category];
841 std::transform (str.begin(), str.end(), str.begin(), ::tolower);
843 ARDOUR::PluginInfoPtr pi = row[plugin_columns.plugin];
844 manager.set_tags (pi->type, pi->unique_id, str, true, true);
845 _need_tag_save = true;
850 PluginSelector::search_entry_changed ()
852 set_sensitive_widgets();
857 PluginSelector::tag_entry_changed ()
859 if (plugin_display.get_selection()->count_selected_rows() != 0) {
860 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
862 ARDOUR::PluginInfoPtr pi = row[plugin_columns.plugin];
863 manager.set_tags (pi->type, pi->unique_id, tag_entry->get_text(), false);
865 _need_tag_save = true;
870 PluginSelector::tags_changed (PluginType t, std::string unique_id, std::string tags)
872 if (plugin_display.get_selection()->count_selected_rows() != 0) {
873 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
874 if (tags.length() > 32) {
875 tags = tags.substr (0, 32);
878 row[plugin_columns.tags] = tags;
881 /* A plugin's tags change while the user is entering them.
882 * defer a rebuilding of the "tag" menu until the dialog is closed.
884 _need_menu_rebuild = true;
888 PluginSelector::plugin_status_changed (PluginType t, std::string uid, PluginManager::PluginStatusType stat)
890 Gtk::TreeModel::iterator i;
891 for (i = plugin_model->children().begin(); i != plugin_model->children().end(); ++i) {
892 PluginInfoPtr pp = (*i)[plugin_columns.plugin];
893 if ((pp->type == t) && (pp->unique_id == uid)) {
894 (*i)[plugin_columns.favorite] = (stat == PluginManager::Favorite) ? true : false;
895 (*i)[plugin_columns.hidden] = (stat == PluginManager::Hidden) ? true : false;
897 /* if plug was hidden, remove it from the view */
898 if (stat==PluginManager::Hidden) {
899 plugin_model->erase(i);
902 /* plugin menu must be re-built to accommodate Hidden and Favorite plugins */
911 PluginSelector::on_show ()
913 ArdourDialog::on_show ();
914 search_entry.grab_focus ();
918 _need_tag_save = false;
919 _need_status_save = false;
920 _need_menu_rebuild = false;
923 struct PluginMenuCompareByCreator {
924 bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
927 cmp = cmp_nocase_utf8 (a->creator, b->creator);
931 } else if (cmp == 0) {
932 /* same creator ... compare names */
933 if (cmp_nocase_utf8 (a->name, b->name) < 0) {
941 struct PluginMenuCompareByName {
942 bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
945 cmp = cmp_nocase_utf8 (a->name, b->name);
949 } else if (cmp == 0) {
950 /* same name ... compare type */
951 if (a->type < b->type) {
959 /** @return Plugin menu. The caller should not delete it */
961 PluginSelector::plugin_menu()
967 PluginSelector::build_plugin_menu ()
969 PluginInfoList all_plugs;
971 all_plugs.insert (all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
972 all_plugs.insert (all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
973 #ifdef WINDOWS_VST_SUPPORT
974 all_plugs.insert (all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
977 all_plugs.insert (all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
979 #ifdef MACVST_SUPPORT
980 all_plugs.insert (all_plugs.end(), manager.mac_vst_plugin_info().begin(), manager.mac_vst_plugin_info().end());
982 #ifdef AUDIOUNIT_SUPPORT
983 all_plugs.insert (all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
986 all_plugs.insert (all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
989 using namespace Menu_Helpers;
993 _plugin_menu = manage (new Menu);
994 _plugin_menu->set_name("ArdourContextMenu");
996 MenuList& items = _plugin_menu->items();
999 Gtk::Menu* favs = create_favs_menu(all_plugs);
1000 items.push_back (MenuElem (_("Favorites"), *manage (favs)));
1002 items.push_back (MenuElem (_("Plugin Manager..."), sigc::mem_fun (*this, &PluginSelector::show_manager)));
1003 items.push_back (SeparatorElem ());
1005 Menu* by_creator = create_by_creator_menu(all_plugs);
1006 items.push_back (MenuElem (_("By Creator"), *manage (by_creator)));
1008 Menu* by_tags = create_by_tags_menu(all_plugs);
1009 items.push_back (MenuElem (_("By Tags"), *manage (by_tags)));
1013 GetPluginTypeStr(PluginInfoPtr info)
1017 switch (info->type) {
1019 type = X_(" (LADSPA)");
1025 type = X_(" (LV2)");
1030 type = X_(" (VST)");
1033 type = X_(" (Lua)");
1041 PluginSelector::create_favs_menu (PluginInfoList& all_plugs)
1043 using namespace Menu_Helpers;
1045 Menu* favs = new Menu();
1046 favs->set_name("ArdourContextMenu");
1048 PluginMenuCompareByName cmp_by_name;
1049 all_plugs.sort (cmp_by_name);
1051 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
1052 if (manager.get_status (*i) == PluginManager::Favorite) {
1053 string typ = GetPluginTypeStr(*i);
1054 MenuElem elem ((*i)->name + typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
1055 elem.get_child()->set_use_underline (false);
1056 favs->items().push_back (elem);
1063 PluginSelector::create_by_creator_menu (ARDOUR::PluginInfoList& all_plugs)
1065 inhibit_refill = true;
1066 _fil_creator_combo->clear();
1067 _fil_creator_combo->append_text (_("Show All Creators"));
1068 _fil_creator_combo->set_active_text (_("Show All Creators"));
1069 inhibit_refill = false;
1071 using namespace Menu_Helpers;
1073 typedef std::map<std::string,Gtk::Menu*> SubmenuMap;
1074 SubmenuMap creator_submenu_map;
1076 Menu* by_creator = new Menu();
1077 by_creator->set_name("ArdourContextMenu");
1079 MenuList& by_creator_items = by_creator->items();
1080 PluginMenuCompareByCreator cmp_by_creator;
1081 all_plugs.sort (cmp_by_creator);
1083 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
1085 if (manager.get_status (*i) == PluginManager::Hidden) continue;
1087 string creator = (*i)->creator;
1088 string::size_type pos = 0;
1090 if ((*i)->type == ARDOUR::LADSPA) {
1091 /* stupid LADSPA creator strings */
1092 #ifdef PLATFORM_WINDOWS
1093 while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
1095 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
1098 pos = creator.length ();
1101 /* If there were too few characters to create a
1102 * meaningful name, mark this creator as 'Unknown'
1104 if (creator.length() < 2 || pos < 3) {
1105 creator = "Unknown";
1107 creator = creator.substr (0, pos);
1110 /* trim the creator length so we don't make a giant pulldown menu */
1111 if (creator.length() > MAX_CREATOR_LEN) {
1112 creator = creator.substr (0, MAX_CREATOR_LEN);
1113 creator.append("...");
1116 SubmenuMap::iterator x;
1118 if ((x = creator_submenu_map.find (creator)) != creator_submenu_map.end()) {
1119 submenu = x->second;
1122 _fil_creator_combo->append_text(creator);
1124 submenu = new Gtk::Menu;
1125 by_creator_items.push_back (MenuElem (creator, *manage (submenu)));
1126 creator_submenu_map.insert (pair<std::string,Menu*> (creator, submenu));
1127 submenu->set_name("ArdourContextMenu");
1129 string typ = GetPluginTypeStr(*i);
1130 MenuElem elem ((*i)->name+typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
1131 elem.get_child()->set_use_underline (false);
1132 submenu->items().push_back (elem);
1139 PluginSelector::create_by_tags_menu (ARDOUR::PluginInfoList& all_plugs)
1141 using namespace Menu_Helpers;
1143 typedef std::map<std::string,Gtk::Menu*> SubmenuMap;
1144 SubmenuMap tags_submenu_map;
1146 Menu* by_tags = new Menu();
1147 by_tags->set_name("ArdourContextMenu");
1148 MenuList& by_tags_items = by_tags->items();
1150 std::vector<std::string> all_tags = manager.get_all_tags(false);
1151 for (vector<string>::iterator t = all_tags.begin(); t != all_tags.end(); ++t) {
1152 Gtk::Menu *submenu = new Gtk::Menu;
1153 by_tags_items.push_back (MenuElem (*t, *manage (submenu)));
1154 tags_submenu_map.insert (pair<std::string,Menu*> (*t, submenu));
1155 submenu->set_name("ArdourContextMenu");
1158 PluginMenuCompareByName cmp_by_name;
1159 all_plugs.sort (cmp_by_name);
1161 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
1163 if (manager.get_status (*i) == PluginManager::Hidden) continue;
1165 /* for each tag in the plugins tag list, add it to that submenu */
1166 vector<string> tokens = manager.get_tags(*i);
1167 for (vector<string>::iterator t = tokens.begin(); t != tokens.end(); ++t) {
1168 SubmenuMap::iterator x;
1170 if ((x = tags_submenu_map.find (*t)) != tags_submenu_map.end()) {
1171 submenu = x->second;
1174 string typ = GetPluginTypeStr(*i);
1175 MenuElem elem ((*i)->name + typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
1176 elem.get_child()->set_use_underline (false);
1177 submenu->items().push_back (elem);
1184 PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
1186 PluginPtr p = load_plugin (pi);
1188 if (p && interested_object) {
1189 SelectedPlugins plugins;
1190 plugins.push_back (p);
1191 interested_object->use_plugins (plugins);
1194 interested_object = 0;
1198 PluginSelector::favorite_changed (const std::string& path)
1202 if (in_row_change) {
1206 in_row_change = true;
1208 TreeModel::iterator iter = plugin_model->get_iter (path);
1212 bool favorite = !(*iter)[plugin_columns.favorite];
1216 PluginManager::PluginStatusType status = (favorite ? PluginManager::Favorite : PluginManager::Normal);
1218 /* save new statuses list */
1220 pi = (*iter)[plugin_columns.plugin];
1222 manager.set_status (pi->type, pi->unique_id, status);
1224 _need_status_save = true;
1226 in_row_change = false;
1230 PluginSelector::hidden_changed (const std::string& path)
1234 if (in_row_change) {
1238 in_row_change = true;
1240 TreeModel::iterator iter = plugin_model->get_iter (path);
1244 bool hidden = !(*iter)[plugin_columns.hidden];
1248 PluginManager::PluginStatusType status = (hidden ? PluginManager::Hidden : PluginManager::Normal);
1250 /* save new statuses list */
1252 pi = (*iter)[plugin_columns.plugin];
1254 manager.set_status (pi->type, pi->unique_id, status);
1256 _need_status_save = true;
1258 in_row_change = false;
1262 PluginSelector::show_manager ()
1269 PluginSelector::set_interested_object (PluginInterestedObject& obj)
1271 interested_object = &obj;