2 * Copyright (C) 2005-2006 Doug McLain <doug@nostar.net>
3 * Copyright (C) 2005-2007 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2006 Nick Mainsbridge <mainsbridge@gmail.com>
6 * Copyright (C) 2007-2012 David Robillard <d@drobilla.net>
7 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
8 * Copyright (C) 2013-2014 John Emmas <john@creativepost.co.uk>
9 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
10 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "gtk2ardour-config.h"
34 #include <boost/tokenizer.hpp>
36 #include <gtkmm/button.h>
37 #include <gtkmm/comboboxtext.h>
38 #include <gtkmm/frame.h>
39 #include <gtkmm/messagedialog.h>
40 #include <gtkmm/notebook.h>
41 #include <gtkmm/stock.h>
42 #include <gtkmm/table.h>
43 #include <gtkmm/treestore.h>
45 #include "gtkmm2ext/utils.h"
47 #include "widgets/tooltips.h"
49 #include "pbd/convert.h"
50 #include "pbd/tokenizer.h"
52 #include "ardour/utils.h"
54 #include "plugin_selector.h"
55 #include "gui_thread.h"
56 #include "ui_config.h"
60 using namespace ARDOUR;
64 using namespace ArdourWidgets;
66 static const uint32_t MAX_CREATOR_LEN = 24;
68 PluginSelector::PluginSelector (PluginManager& mgr)
69 : ArdourDialog (_("Plugin Manager"), true, false)
70 , search_clear_button (Stock::CLEAR)
72 , _need_tag_save (false)
73 , _need_status_save (false)
74 , _need_menu_rebuild (false)
75 , _inhibit_refill (false)
77 set_name ("PluginSelectorWindow");
78 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
81 in_row_change = false;
83 manager.PluginListChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
84 manager.PluginStatusChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
85 manager.PluginTagChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::build_plugin_menu, this), gui_context());
87 manager.PluginStatusChanged.connect (plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::plugin_status_changed, this, _1, _2, _3), gui_context());
88 manager.PluginTagChanged.connect(plugin_list_changed_connection, invalidator (*this), boost::bind (&PluginSelector::tags_changed, this, _1, _2, _3), gui_context());
90 plugin_model = Gtk::ListStore::create (plugin_columns);
91 plugin_display.set_model (plugin_model);
92 /* XXX translators: try to convert "Fav" into a short term
93 * related to "favorite" and "Hid" into a short term
96 plugin_display.append_column (_("Fav"), plugin_columns.favorite);
97 plugin_display.append_column (_("Hide"), plugin_columns.hidden);
98 plugin_display.append_column (_("Name"), plugin_columns.name);
99 plugin_display.append_column (_("Tags"), plugin_columns.tags);
100 plugin_display.append_column (_("Creator"), plugin_columns.creator);
101 plugin_display.append_column (_("Type"), plugin_columns.type_name);
102 plugin_display.append_column (_("Audio I/O"),plugin_columns.audio_io);
103 plugin_display.append_column (_("MIDI I/O"), plugin_columns.midi_io);
104 plugin_display.set_headers_visible (true);
105 plugin_display.set_headers_clickable (true);
106 plugin_display.set_reorderable (false);
107 plugin_display.set_rules_hint (true);
108 plugin_display.add_object_drag (plugin_columns.plugin.index(), "PluginInfoPtr");
109 plugin_display.set_drag_column (plugin_columns.name.index());
111 // setting a sort-column prevents re-ordering via Drag/Drop
112 plugin_model->set_sort_column (plugin_columns.name.index(), Gtk::SORT_ASCENDING);
114 plugin_display.set_name("PluginSelectorDisplay");
115 plugin_display.signal_row_activated().connect_notify (sigc::mem_fun(*this, &PluginSelector::row_activated));
116 plugin_display.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::display_selection_changed));
118 CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
119 fav_cell->property_activatable() = true;
120 fav_cell->property_radio() = true;
121 fav_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::favorite_changed));
123 CellRendererToggle* hidden_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (1));
124 hidden_cell->property_activatable() = true;
125 hidden_cell->property_radio() = true;
126 hidden_cell->signal_toggled().connect (sigc::mem_fun (*this, &PluginSelector::hidden_changed));
128 scroller.set_border_width(10);
129 scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
130 scroller.add(plugin_display);
132 amodel = Gtk::ListStore::create(acols);
133 added_list.set_model (amodel);
134 added_list.append_column (_("Plugins to be connected"), acols.text);
135 added_list.set_headers_visible (true);
136 added_list.set_reorderable (false);
138 for (int i = 2; i <= 7; ++i) {
139 Gtk::TreeView::Column* column = plugin_display.get_column(i);
141 column->set_sort_column(i);
145 ascroller.set_border_width(10);
146 ascroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
147 ascroller.add(added_list);
148 btn_add = manage(new Gtk::Button(Stock::ADD));
149 set_tooltip(*btn_add, _("Add a plugin to the effect list"));
150 btn_add->set_sensitive (false);
151 btn_remove = manage(new Gtk::Button(Stock::REMOVE));
152 btn_remove->set_sensitive (false);
153 set_tooltip(*btn_remove, _("Remove a plugin from the effect list"));
155 btn_add->set_name("PluginSelectorButton");
156 btn_remove->set_name("PluginSelectorButton");
160 Gtk::Table* search_table = manage(new Gtk::Table(2, 2));
162 search_entry.signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::search_entry_changed));
163 search_clear_button.signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::search_clear_button_clicked));
165 _search_name_checkbox = manage (new ArdourButton (_("Name"), ArdourButton::led_default_elements, true));
166 _search_name_checkbox->set_active(true);
167 _search_name_checkbox->set_name ("pluginlist filter button");
169 _search_tags_checkbox = manage (new ArdourButton (_("Tags"), ArdourButton::led_default_elements, true));
170 _search_tags_checkbox->set_active(true);
171 _search_tags_checkbox->set_name ("pluginlist filter button");
173 _search_ignore_checkbox = manage (new ArdourButton(_("Ignore Filters when searching"), ArdourButton::led_default_elements, true));
174 _search_ignore_checkbox->set_active(true);
175 _search_ignore_checkbox->set_name ("pluginlist filter button");
177 Gtk::Label* search_help_label1 = manage (new Label(
178 _("All search terms must be matched."), Gtk::ALIGN_LEFT));
180 Gtk::Label* search_help_label2 = manage (new Label(
181 _("Ex: \"ess dyn\" will find \"dynamic de-esser\" but not \"de-esser\"."), Gtk::ALIGN_LEFT));
183 search_table->attach (search_entry, 0, 3, 0, 1, FILL|EXPAND, FILL);
184 search_table->attach (search_clear_button, 3, 4, 0, 1, FILL, FILL);
185 search_table->attach (*_search_name_checkbox, 0, 1, 1, 2, FILL, FILL);
186 search_table->attach (*_search_tags_checkbox, 1, 2, 1, 2, FILL, FILL);
187 search_table->attach (*_search_ignore_checkbox,2, 3, 1, 2, FILL, FILL);
188 search_table->attach (*search_help_label1, 0, 3, 2, 3, FILL, FILL);
189 search_table->attach (*search_help_label2, 0, 3, 3, 4, FILL, FILL);
191 search_table->set_border_width (4);
192 search_table->set_col_spacings (4);
193 search_table->set_row_spacings (4);
195 Frame* search_frame = manage (new Frame);
196 search_frame->set_name ("BaseFrame");
197 search_frame->set_label (_("Search"));
198 search_frame->add (*search_table);
199 search_frame->show_all ();
201 _search_name_checkbox->signal_clicked.connect (sigc::mem_fun (*this, &PluginSelector::refill));
202 _search_tags_checkbox->signal_clicked.connect (sigc::mem_fun (*this, &PluginSelector::refill));
203 _search_ignore_checkbox->signal_clicked.connect (sigc::mem_fun (*this, &PluginSelector::set_sensitive_widgets));
207 Gtk::RadioButtonGroup fil_radio_group;
209 _fil_effects_radio = manage (new RadioButton (fil_radio_group, _("Show Effects Only")));
210 _fil_instruments_radio = manage (new RadioButton (fil_radio_group, _("Show Instruments Only")));
211 _fil_utils_radio = manage (new RadioButton (fil_radio_group, _("Show Utilities Only")));
212 _fil_favorites_radio = manage (new RadioButton (fil_radio_group, _("Show Favorites Only")));
213 _fil_hidden_radio = manage (new RadioButton (fil_radio_group, _("Show Hidden Only")));
214 _fil_all_radio = manage (new RadioButton (fil_radio_group, _("Show All")));
216 //_fil_type_combo = manage (new ComboBoxText);
217 _fil_type_combo.append_text_item (_("Show All Formats"));
218 _fil_type_combo.append_text_item (X_("VST"));
219 #ifdef AUDIOUNIT_SUPPORT
220 _fil_type_combo.append_text_item (X_("AudioUnit"));
223 _fil_type_combo.append_text_item (X_("LV2"));
225 _fil_type_combo.append_text_item (X_("Lua"));
226 _fil_type_combo.append_text_item (X_("LADSPA"));
227 _fil_type_combo.set_text (_("Show All Formats"));
229 /* note: _fil_creator_combo menu gets filled in build_plugin_menu */
230 _fil_creator_combo.set_text_ellipsize (Pango::ELLIPSIZE_END);
231 _fil_creator_combo.set_layout_ellipsize_width (PANGO_SCALE * 160 * UIConfiguration::instance ().get_ui_scale ());
233 VBox* filter_vbox = manage (new VBox);
234 filter_vbox->pack_start (*_fil_effects_radio, false, false);
235 filter_vbox->pack_start (*_fil_instruments_radio, false, false);
236 filter_vbox->pack_start (*_fil_utils_radio, false, false);
237 filter_vbox->pack_start (*_fil_favorites_radio, false, false);
238 filter_vbox->pack_start (*_fil_hidden_radio, false, false);
239 filter_vbox->pack_start (*_fil_all_radio, false, false);
240 filter_vbox->pack_start (_fil_type_combo, false, false);
241 filter_vbox->pack_start (_fil_creator_combo, false, false);
243 filter_vbox->set_border_width (4);
244 filter_vbox->set_spacing (4);
246 Frame* filter_frame = manage (new Frame);
247 filter_frame->set_name ("BaseFrame");
248 filter_frame->set_label (_("Filter"));
249 filter_frame->add (*filter_vbox);
250 filter_frame->show_all ();
252 _fil_effects_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
253 _fil_instruments_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
254 _fil_utils_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
255 _fil_favorites_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
256 _fil_hidden_radio->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::refill));
258 _fil_type_combo.StateChanged.connect (sigc::mem_fun (*this, &PluginSelector::refill));
259 _fil_creator_combo.StateChanged.connect (sigc::mem_fun (*this, &PluginSelector::refill));
263 Gtk::Table* tagging_table = manage(new Gtk::Table(1, 2));
264 tagging_table->set_border_width (4);
265 tagging_table->set_col_spacings (4);
266 tagging_table->set_row_spacings (4);
268 tag_entry = manage (new Gtk::Entry);
269 tag_entry_connection = tag_entry->signal_changed().connect (sigc::mem_fun (*this, &PluginSelector::tag_entry_changed));
271 tag_reset_button = manage (new Button (_("Reset")));
272 tag_reset_button->signal_clicked().connect (sigc::mem_fun (*this, &PluginSelector::tag_reset_button_clicked));
274 Gtk::Label* tagging_help_label1 = manage (new Label(
275 _("Enter space-separated, one-word Tags for the selected plugin."), Gtk::ALIGN_LEFT));
277 Gtk::Label* tagging_help_label2 = manage (new Label(
278 _("You can include dashes, colons or underscores in a Tag."), Gtk::ALIGN_LEFT));
280 Gtk::Label* tagging_help_label3 = manage (new Label(
281 _("Ex: \"dynamic de-esser vocal\" applies 3 Tags."), Gtk::ALIGN_LEFT));
284 tagging_table->attach (*tag_entry, 0, 1, p, p+1, FILL|EXPAND, FILL);
285 tagging_table->attach (*tag_reset_button, 1, 2, p, p+1, FILL, FILL); p++;
286 tagging_table->attach (*tagging_help_label1, 0, 2, p, p+1, FILL, FILL); p++;
287 tagging_table->attach (*tagging_help_label2, 0, 2, p, p+1, FILL, FILL); p++;
288 tagging_table->attach (*tagging_help_label3, 0, 2, p, p+1, FILL, FILL); p++;
290 Frame* tag_frame = manage (new Frame);
291 tag_frame->set_name ("BaseFrame");
292 tag_frame->set_label (_("Tags for Selected Plugin"));
293 tag_frame->add (*tagging_table);
294 tag_frame->show_all ();
296 /* Add & remove buttons */
298 HBox* add_remove = manage (new HBox);
299 add_remove->pack_start (*btn_add, true, true);
300 add_remove->pack_start (*btn_remove, true, true);
302 btn_add->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_add_clicked));
303 btn_remove->signal_clicked().connect(sigc::mem_fun(*this, &PluginSelector::btn_remove_clicked));
304 added_list.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &PluginSelector::added_list_selection_changed));
305 added_list.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::added_row_clicked));
307 added_list.set_name("PluginSelectorList");
309 /* Top-level Layout */
311 VBox* to_be_inserted_vbox = manage (new VBox);
312 to_be_inserted_vbox->pack_start (ascroller);
313 to_be_inserted_vbox->pack_start (*add_remove, false, false);
314 to_be_inserted_vbox->set_size_request (200, -1);
316 Gtk::Table* table = manage(new Gtk::Table(3, 3));
317 table->set_size_request(-1, 600);
318 table->attach (scroller, 0, 3, 0, 5); /* this is the main plugin list */
319 table->attach (*search_frame, 0, 1, 6, 7, FILL, FILL, 5, 5);
320 table->attach (*tag_frame, 0, 1, 7, 8, FILL, FILL, 5, 5);
321 table->attach (*filter_frame, 1, 2, 6, 8, FILL, FILL, 5, 5);
322 table->attach (*to_be_inserted_vbox, 2, 3, 6, 8, FILL|EXPAND, FILL, 5, 5); /* to be inserted... */
324 add_button (Stock::CLOSE, RESPONSE_CLOSE);
325 add_button (_("Insert Plugin(s)"), RESPONSE_APPLY);
326 set_default_response (RESPONSE_APPLY);
327 set_response_sensitive (RESPONSE_APPLY, false);
328 get_vbox()->pack_start (*table);
330 table->set_name("PluginSelectorTable");
332 plugin_display.grab_focus();
334 build_plugin_menu ();
335 display_selection_changed ();
338 PluginSelector::~PluginSelector ()
344 PluginSelector::row_activated(Gtk::TreeModel::Path, Gtk::TreeViewColumn*)
350 PluginSelector::added_row_clicked(GdkEventButton* event)
352 if (event->type == GDK_2BUTTON_PRESS)
353 btn_remove_clicked();
358 setup_search_string (string& searchstr)
360 transform (searchstr.begin(), searchstr.end(), searchstr.begin(), ::toupper);
364 match_search_strings (string const& haystack, string const& needle)
366 boost::char_separator<char> sep (" ");
367 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
368 tokenizer t (needle, sep);
369 for (tokenizer::iterator ti = t.begin(); ti != t.end(); ++ti) {
370 if (haystack.find (*ti) == string::npos) {
378 PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& searchstr)
381 bool maybe_show = false;
382 PluginManager::PluginStatusType status = manager.get_status (info);
384 if (!searchstr.empty()) {
386 if (_search_name_checkbox->get_active()) { /* name contains */
387 std::string compstr = info->name;
388 setup_search_string (compstr);
389 maybe_show |= match_search_strings (compstr, searchstr);
392 if (_search_tags_checkbox->get_active()) { /* tag contains */
393 std::string compstr = manager.get_tags_as_string (info);
394 setup_search_string (compstr);
395 maybe_show |= match_search_strings (compstr, searchstr);
402 /* user asked to ignore filters */
403 if (maybe_show && _search_ignore_checkbox->get_active()) {
404 if (status == PluginManager::Hidden) {
407 if (status == PluginManager::Concealed) {
414 if (_fil_effects_radio->get_active() && !info->is_effect()) {
418 if (_fil_instruments_radio->get_active() && !info->is_instrument()) {
422 if (_fil_utils_radio->get_active() && !(info->is_utility() || info->is_analyzer())) {
426 if (_fil_favorites_radio->get_active() && status != PluginManager::Favorite) {
430 if (_fil_hidden_radio->get_active() && (status != PluginManager::Hidden && status != PluginManager::Concealed)) {
434 if (!_fil_hidden_radio->get_active() && status == PluginManager::Hidden) {
438 if (!_fil_hidden_radio->get_active() && status == PluginManager::Concealed) {
442 /* Filter "type" combobox */
444 if (_fil_type_combo.get_text() == X_("VST") && PluginManager::to_generic_vst(info->type) != LXVST) {
448 if (_fil_type_combo.get_text() == X_("AudioUnit") && info->type != AudioUnit) {
453 if (_fil_type_combo.get_text() == X_("LV2") && info->type != LV2) {
458 if (_fil_type_combo.get_text() == X_("Lua") && info->type != Lua) {
462 if (_fil_type_combo.get_text() == X_("LADSPA") && info->type != LADSPA) {
466 /* Filter "creator" combobox */
468 if (_fil_creator_combo.get_text() != _("Show All Creators")) {
469 if (_fil_creator_combo.get_text() != info->creator) {
478 PluginSelector::set_sensitive_widgets ()
480 if (_search_ignore_checkbox->get_active() && !search_entry.get_text().empty()) {
481 _fil_effects_radio->set_sensitive(false);
482 _fil_instruments_radio->set_sensitive(false);
483 _fil_utils_radio->set_sensitive(false);
484 _fil_favorites_radio->set_sensitive(false);
485 _fil_hidden_radio->set_sensitive(false);
486 _fil_all_radio->set_sensitive(false);
487 _inhibit_refill = true;
488 _fil_type_combo.set_sensitive(false);
489 _fil_creator_combo.set_sensitive(false);
490 _inhibit_refill = false;
492 _fil_effects_radio->set_sensitive(true);
493 _fil_instruments_radio->set_sensitive(true);
494 _fil_utils_radio->set_sensitive(true);
495 _fil_favorites_radio->set_sensitive(true);
496 _fil_hidden_radio->set_sensitive(true);
497 _fil_all_radio->set_sensitive(true);
498 _inhibit_refill = true;
499 _fil_type_combo.set_sensitive(true);
500 _fil_creator_combo.set_sensitive(true);
501 _inhibit_refill = false;
503 if (!search_entry.get_text().empty()) {
509 PluginSelector::refill ()
511 if (_inhibit_refill) {
515 in_row_change = true;
517 plugin_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
521 bool sorted = plugin_model->get_sort_column_id (sort_col, sort_type);
523 /* Disable sorting to gain performance */
524 plugin_model->set_sort_column (-2, SORT_ASCENDING);
526 plugin_model->clear ();
528 std::string searchstr = search_entry.get_text ();
529 setup_search_string (searchstr);
531 ladspa_refiller (searchstr);
532 lv2_refiller (searchstr);
533 vst_refiller (searchstr);
534 lxvst_refiller (searchstr);
535 mac_vst_refiller (searchstr);
536 au_refiller (searchstr);
537 lua_refiller (searchstr);
539 in_row_change = false;
541 plugin_display.set_model (plugin_model);
543 plugin_model->set_sort_column (sort_col, sort_type);
548 PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& searchstr, const char* type)
552 for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
554 if (show_this_plugin (*i, searchstr)) {
556 TreeModel::Row newrow = *(plugin_model->append());
558 PluginManager::PluginStatusType status = manager.get_status (*i);
559 newrow[plugin_columns.favorite] = status == PluginManager::Favorite;
560 newrow[plugin_columns.hidden] = status == PluginManager::Hidden;
562 string name = (*i)->name;
563 if (name.length() > 48) {
564 name = name.substr (0, 48);
567 newrow[plugin_columns.name] = name;
569 newrow[plugin_columns.type_name] = type;
572 string creator = (*i)->creator;
573 string::size_type pos = 0;
574 if ((*i)->type == ARDOUR::LADSPA) {
575 /* stupid LADSPA creator strings */
576 #ifdef PLATFORM_WINDOWS
577 while (pos < creator.length() && creator[pos] > -2 && creator[pos] < 256 && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
579 while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
582 pos = creator.length ();
584 // If there were too few characters to create a
585 // meaningful name, mark this creator as 'Unknown'
586 if (creator.length() < 2 || pos < 3) {
589 creator = creator.substr (0, pos);
592 if (creator.length() > MAX_CREATOR_LEN) {
593 creator = creator.substr (0, MAX_CREATOR_LEN);
594 creator.append("...");
596 newrow[plugin_columns.creator] = creator;
599 string tags = manager.get_tags_as_string(*i);
600 if (tags.length() > 32) {
601 tags = tags.substr (0, 32);
604 newrow[plugin_columns.tags] = tags;
606 if ((*i)->reconfigurable_io ()) {
607 newrow[plugin_columns.audio_io] = "* / *";
608 newrow[plugin_columns.midi_io] = "* / *";
610 snprintf (buf, sizeof(buf), "%d / %d", (*i)->n_inputs.n_audio(), (*i)->n_outputs.n_audio());
611 newrow[plugin_columns.audio_io] = buf;
612 snprintf (buf, sizeof(buf), "%d / %d", (*i)->n_inputs.n_midi(), (*i)->n_outputs.n_midi());
613 newrow[plugin_columns.midi_io] = buf;
616 newrow[plugin_columns.plugin] = *i;
622 PluginSelector::ladspa_refiller (const std::string& searchstr)
624 refiller (manager.ladspa_plugin_info(), searchstr, "LADSPA");
628 PluginSelector::lua_refiller (const std::string& searchstr)
630 refiller (manager.lua_plugin_info(), searchstr, "Lua");
634 PluginSelector::lv2_refiller (const std::string& searchstr)
637 refiller (manager.lv2_plugin_info(), searchstr, "LV2");
642 #ifdef WINDOWS_VST_SUPPORT
643 PluginSelector::vst_refiller (const std::string& searchstr)
645 PluginSelector::vst_refiller (const std::string&)
648 #ifdef WINDOWS_VST_SUPPORT
649 refiller (manager.windows_vst_plugin_info(), searchstr, "VST");
655 PluginSelector::lxvst_refiller (const std::string& searchstr)
657 PluginSelector::lxvst_refiller (const std::string&)
661 refiller (manager.lxvst_plugin_info(), searchstr, "LXVST");
666 #ifdef MACVST_SUPPORT
667 PluginSelector::mac_vst_refiller (const std::string& searchstr)
669 PluginSelector::mac_vst_refiller (const std::string&)
672 #ifdef MACVST_SUPPORT
673 refiller (manager.mac_vst_plugin_info(), searchstr, "MacVST");
678 #ifdef AUDIOUNIT_SUPPORT
679 PluginSelector::au_refiller (const std::string& searchstr)
681 PluginSelector::au_refiller (const std::string&)
684 #ifdef AUDIOUNIT_SUPPORT
685 refiller (manager.au_plugin_info(), searchstr, "AU");
690 PluginSelector::load_plugin (PluginInfoPtr pi)
696 return pi->load (*_session);
700 PluginSelector::btn_add_clicked()
702 if (plugin_display.get_selection()->count_selected_rows() == 0) {
703 /* may happen with ctrl + double-click un-selecting but activating a row */
708 TreeModel::Row newrow = *(amodel->append());
711 row = *(plugin_display.get_selection()->get_selected());
712 name = row[plugin_columns.name];
713 pi = row[plugin_columns.plugin];
715 newrow[acols.text] = name;
716 newrow[acols.plugin] = pi;
718 if (!amodel->children().empty()) {
719 set_response_sensitive (RESPONSE_APPLY, true);
724 PluginSelector::btn_remove_clicked()
726 TreeModel::iterator iter = added_list.get_selection()->get_selected();
729 if (amodel->children().empty()) {
730 set_response_sensitive (RESPONSE_APPLY, false);
735 PluginSelector::display_selection_changed()
737 tag_entry_connection.block ();
738 if (plugin_display.get_selection()->count_selected_rows() != 0) {
740 /* a plugin row is selected; allow the user to edit the "tags" on it. */
741 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
742 string tags = manager.get_tags_as_string (row[plugin_columns.plugin]);
743 tag_entry->set_text (tags);
745 tag_entry->set_sensitive (true);
746 tag_reset_button->set_sensitive (true);
747 btn_add->set_sensitive (true);
750 tag_entry->set_text ("");
752 tag_entry->set_sensitive (false);
753 tag_reset_button->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();
818 if (_need_menu_rebuild) {
819 build_plugin_menu ();
826 PluginSelector::search_clear_button_clicked ()
828 search_entry.set_text ("");
832 PluginSelector::tag_reset_button_clicked ()
834 if (plugin_display.get_selection()->count_selected_rows() != 0) {
835 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
836 ARDOUR::PluginInfoPtr pi = row[plugin_columns.plugin];
837 manager.reset_tags (pi);
838 display_selection_changed ();
839 _need_tag_save = true;
844 PluginSelector::search_entry_changed ()
846 set_sensitive_widgets();
847 if (search_entry.get_text().empty()) {
853 PluginSelector::tag_entry_changed ()
855 if (plugin_display.get_selection()->count_selected_rows() != 0) {
856 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
858 ARDOUR::PluginInfoPtr pi = row[plugin_columns.plugin];
859 manager.set_tags (pi->type, pi->unique_id, tag_entry->get_text(), pi->name, PluginManager::FromGui);
861 _need_tag_save = true;
866 PluginSelector::tags_changed (PluginType t, std::string unique_id, std::string tags)
868 if (plugin_display.get_selection()->count_selected_rows() != 0) {
869 TreeModel::Row row = *(plugin_display.get_selection()->get_selected());
870 if (tags.length() > 32) {
871 tags = tags.substr (0, 32);
874 row[plugin_columns.tags] = tags;
879 PluginSelector::plugin_status_changed (PluginType t, std::string uid, PluginManager::PluginStatusType stat)
881 Gtk::TreeModel::iterator i;
882 for (i = plugin_model->children().begin(); i != plugin_model->children().end(); ++i) {
883 PluginInfoPtr pp = (*i)[plugin_columns.plugin];
884 if ((pp->type == t) && (pp->unique_id == uid)) {
885 (*i)[plugin_columns.favorite] = (stat == PluginManager::Favorite) ? true : false;
886 (*i)[plugin_columns.hidden] = (stat == PluginManager::Hidden) ? true : false;
888 /* if plug was hidden, remove it from the view */
889 if (stat == PluginManager::Hidden || stat == PluginManager::Concealed) {
890 if (!_fil_hidden_radio->get_active() && !_fil_all_radio->get_active()) {
891 plugin_model->erase(i);
893 } else if (_fil_hidden_radio->get_active()) {
894 plugin_model->erase(i);
896 /* if no longer a favorite, remove it from the view */
897 if (stat != PluginManager::Favorite && _fil_favorites_radio->get_active()) {
898 plugin_model->erase(i);
907 PluginSelector::on_show ()
909 ArdourDialog::on_show ();
910 search_entry.grab_focus ();
914 _need_tag_save = false;
915 _need_status_save = false;
918 struct PluginMenuCompareByCreator {
919 bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
922 cmp = cmp_nocase_utf8 (a->creator, b->creator);
926 } else if (cmp == 0) {
927 /* same creator ... compare names */
928 if (cmp_nocase_utf8 (a->name, b->name) < 0) {
936 struct PluginMenuCompareByName {
937 bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
940 cmp = cmp_nocase_utf8 (a->name, b->name);
944 } else if (cmp == 0) {
945 /* same name ... compare type */
946 if (a->type < b->type) {
954 /** @return Plugin menu. The caller should not delete it */
956 PluginSelector::plugin_menu()
962 PluginSelector::build_plugin_menu ()
965 _need_menu_rebuild = true;
968 _need_menu_rebuild = false;
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 = 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_items ();
1067 _fil_creator_combo.append_text_item (_("Show All Creators"));
1068 _fil_creator_combo.set_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 PluginManager::PluginStatusType status = manager.get_status (*i);
1086 if (status == PluginManager::Hidden) continue;
1087 if (status == PluginManager::Concealed) continue;
1089 string creator = (*i)->creator;
1091 /* If there were too few characters to create a
1092 * meaningful name, mark this creator as 'Unknown'
1094 if (creator.length() < 2) {
1095 creator = "Unknown";
1098 SubmenuMap::iterator x;
1100 if ((x = creator_submenu_map.find (creator)) != creator_submenu_map.end()) {
1101 submenu = x->second;
1104 _fil_creator_combo.append_text_item (creator);
1106 submenu = new Gtk::Menu;
1107 by_creator_items.push_back (MenuElem (creator, *manage (submenu)));
1108 creator_submenu_map.insert (pair<std::string,Menu*> (creator, submenu));
1109 submenu->set_name("ArdourContextMenu");
1111 string typ = GetPluginTypeStr(*i);
1112 MenuElem elem ((*i)->name+typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
1113 elem.get_child()->set_use_underline (false);
1114 submenu->items().push_back (elem);
1121 PluginSelector::create_by_tags_menu (ARDOUR::PluginInfoList& all_plugs)
1123 using namespace Menu_Helpers;
1125 typedef std::map<std::string,Gtk::Menu*> SubmenuMap;
1126 SubmenuMap tags_submenu_map;
1128 Menu* by_tags = new Menu();
1129 by_tags->set_name("ArdourContextMenu");
1130 MenuList& by_tags_items = by_tags->items();
1132 std::vector<std::string> all_tags = manager.get_all_tags (PluginManager::NoHidden);
1133 for (vector<string>::iterator t = all_tags.begin(); t != all_tags.end(); ++t) {
1134 Gtk::Menu *submenu = new Gtk::Menu;
1135 by_tags_items.push_back (MenuElem (*t, *manage (submenu)));
1136 tags_submenu_map.insert (pair<std::string,Menu*> (*t, submenu));
1137 submenu->set_name("ArdourContextMenu");
1140 PluginMenuCompareByName cmp_by_name;
1141 all_plugs.sort (cmp_by_name);
1143 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
1145 PluginManager::PluginStatusType status = manager.get_status (*i);
1146 if (status == PluginManager::Hidden) continue;
1147 if (status == PluginManager::Concealed) continue;
1149 /* for each tag in the plugins tag list, add it to that submenu */
1150 vector<string> tokens = manager.get_tags(*i);
1151 for (vector<string>::iterator t = tokens.begin(); t != tokens.end(); ++t) {
1152 SubmenuMap::iterator x;
1154 if ((x = tags_submenu_map.find (*t)) != tags_submenu_map.end()) {
1155 submenu = x->second;
1156 string typ = GetPluginTypeStr(*i);
1157 MenuElem elem ((*i)->name + typ, (sigc::bind (sigc::mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i)));
1158 elem.get_child()->set_use_underline (false);
1159 submenu->items().push_back (elem);
1167 PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
1169 PluginPtr p = load_plugin (pi);
1171 if (p && interested_object) {
1172 SelectedPlugins plugins;
1173 plugins.push_back (p);
1174 interested_object->use_plugins (plugins);
1177 interested_object = 0;
1181 PluginSelector::favorite_changed (const std::string& path)
1185 if (in_row_change) {
1189 in_row_change = true;
1191 TreeModel::iterator iter = plugin_model->get_iter (path);
1195 bool favorite = !(*iter)[plugin_columns.favorite];
1199 PluginManager::PluginStatusType status = (favorite ? PluginManager::Favorite : PluginManager::Normal);
1201 /* save new statuses list */
1203 pi = (*iter)[plugin_columns.plugin];
1205 manager.set_status (pi->type, pi->unique_id, status);
1207 _need_status_save = true;
1209 in_row_change = false;
1213 PluginSelector::hidden_changed (const std::string& path)
1217 if (in_row_change) {
1221 in_row_change = true;
1223 TreeModel::iterator iter = plugin_model->get_iter (path);
1227 bool hidden = !(*iter)[plugin_columns.hidden];
1231 PluginManager::PluginStatusType status = (hidden ? PluginManager::Hidden : PluginManager::Normal);
1233 /* save new statuses list */
1235 pi = (*iter)[plugin_columns.plugin];
1237 manager.set_status (pi->type, pi->unique_id, status);
1239 _need_status_save = true;
1241 in_row_change = false;
1245 PluginSelector::show_manager ()
1252 PluginSelector::set_interested_object (PluginInterestedObject& obj)
1254 interested_object = &obj;