2 * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "pbd/convert.h"
20 #include "pbd/enumwriter.h"
21 #include "ardour/chan_count.h"
22 #include "ardour/plugin_manager.h"
23 #include "gtkmm2ext/gui_thread.h"
24 #include "instrument_selector.h"
29 using namespace ARDOUR;
31 InstrumentSelector::InstrumentSelector()
32 : _reasonable_synth_id(0)
33 , _gmsynth_id(UINT32_MAX)
37 PluginManager::instance ().PluginListChanged.connect (_update_connection, invalidator (*this), boost::bind (&InstrumentSelector::refill, this), gui_context());
41 InstrumentSelector::refill()
43 TreeModel::iterator iter = get_active();
46 const TreeModel::Row& row = (*iter);
47 selected = row[_instrument_list_columns.name];
52 build_instrument_list();
53 set_model(_instrument_list);
54 pack_start(_instrument_list_columns.name);
55 if (selected.empty ()) {
56 if (_gmsynth_id != UINT32_MAX) {
57 set_active(_gmsynth_id);
59 set_active(_reasonable_synth_id);
62 TreeModel::Children rows = _instrument_list->children();
63 TreeModel::Children::iterator i;
64 for (i = rows.begin(); i != rows.end(); ++i) {
65 std::string cn = (*i)[_instrument_list_columns.name];
72 set_button_sensitivity(Gtk::SENSITIVITY_AUTO);
76 pluginsort (const PluginInfoPtr& a, const PluginInfoPtr& b)
78 return PBD::downcase(a->name) < PBD::downcase(b->name);
82 invalid_instrument (PluginInfoPtr p) {
83 const PluginManager& manager = PluginManager::instance();
84 if (manager.get_status(p) == PluginManager::Hidden) {
87 return !p->is_instrument();
91 InstrumentSelector::build_instrument_list()
93 PluginManager& manager = PluginManager::instance();
95 PluginInfoList all_plugs;
96 all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
97 all_plugs.insert(all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
98 #ifdef WINDOWS_VST_SUPPORT
99 all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
102 all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
104 #ifdef MACVST_SUPPORT
105 all_plugs.insert(all_plugs.end(), manager.mac_vst_plugin_info().begin(), manager.mac_vst_plugin_info().end());
107 #ifdef AUDIOUNIT_SUPPORT
108 all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
111 all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
114 all_plugs.remove_if (invalid_instrument);
115 all_plugs.sort (pluginsort);
117 _instrument_list = ListStore::create(_instrument_list_columns);
119 TreeModel::Row row = *(_instrument_list->append());
120 row[_instrument_list_columns.info_ptr] = PluginInfoPtr();
121 row[_instrument_list_columns.name] = _("-none-");
125 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i, ++n) {
126 PluginInfoPtr p = *i;
132 suffix = string_compose(_("%1 outs"), n_outs);
135 if (p->multichannel_name_ambiguity) {
136 int n_outs = p->n_outputs.n_audio();
138 suffix = string_compose(_("%1 outs"), n_outs);
139 } else if (n_outs == 2) {
140 suffix = _("stereo");
145 if (p->plugintype_name_ambiguity) {
157 pt = enum_2_string (p->type);
159 if (!suffix.empty ()) {
165 std::string name = p->name;
166 if (!suffix.empty ()) {
167 name += " (" + suffix + ")";
170 row = *(_instrument_list->append());
171 row[_instrument_list_columns.name] = name;
173 row[_instrument_list_columns.info_ptr] = p;
174 if (p->unique_id == "https://community.ardour.org/node/7596") {
175 _reasonable_synth_id = n;
177 if (p->unique_id == "http://gareus.org/oss/lv2/gmsynth") {
185 InstrumentSelector::selected_instrument()
187 TreeModel::iterator iter = get_active();
189 return PluginInfoPtr();
192 const TreeModel::Row& row = (*iter);
193 return row[_instrument_list_columns.info_ptr];