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"
22 #include "ardour/plugin_manager.h"
23 #include "gtkmm2ext/gui_thread.h"
25 #include "instrument_selector.h"
30 using namespace ARDOUR;
32 InstrumentSelector::InstrumentSelector()
33 : _reasonable_synth_id(0)
34 , _gmsynth_id(UINT32_MAX)
38 PluginManager::instance ().PluginListChanged.connect (_update_connection, invalidator (*this), boost::bind (&InstrumentSelector::refill, this), gui_context());
42 InstrumentSelector::refill()
44 TreeModel::iterator iter = get_active();
47 const TreeModel::Row& row = (*iter);
48 selected = row[_instrument_list_columns.name];
53 build_instrument_list();
54 set_model(_instrument_list);
55 pack_start(_instrument_list_columns.name);
56 if (selected.empty ()) {
57 if (_gmsynth_id != UINT32_MAX) {
58 set_active(_gmsynth_id);
60 set_active(_reasonable_synth_id);
63 TreeModel::Children rows = _instrument_list->children();
64 TreeModel::Children::iterator i;
65 for (i = rows.begin(); i != rows.end(); ++i) {
66 std::string cn = (*i)[_instrument_list_columns.name];
73 set_button_sensitivity(Gtk::SENSITIVITY_AUTO);
77 pluginsort (const PluginInfoPtr& a, const PluginInfoPtr& b)
79 return PBD::downcase(a->name) < PBD::downcase(b->name);
83 invalid_instrument (PluginInfoPtr p) {
84 const PluginManager& manager = PluginManager::instance();
85 if (manager.get_status(p) == PluginManager::Hidden) {
88 return !p->is_instrument();
92 InstrumentSelector::build_instrument_list()
94 PluginManager& manager = PluginManager::instance();
96 PluginInfoList all_plugs;
97 all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
98 all_plugs.insert(all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
99 #ifdef WINDOWS_VST_SUPPORT
100 all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
103 all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
105 #ifdef MACVST_SUPPORT
106 all_plugs.insert(all_plugs.end(), manager.mac_vst_plugin_info().begin(), manager.mac_vst_plugin_info().end());
108 #ifdef AUDIOUNIT_SUPPORT
109 all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
112 all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
115 all_plugs.remove_if (invalid_instrument);
116 all_plugs.sort (pluginsort);
118 _instrument_list = ListStore::create(_instrument_list_columns);
120 TreeModel::Row row = *(_instrument_list->append());
121 row[_instrument_list_columns.info_ptr] = PluginInfoPtr();
122 row[_instrument_list_columns.name] = _("-none-");
126 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i, ++n) {
127 PluginInfoPtr p = *i;
132 uint32_t n_outs = p->max_configurable_ouputs ();
134 if (p->reconfigurable_io ()) {
135 suffix = string_compose(_("\u2264 %1 outs"), n_outs);
137 suffix = string_compose(_("%1 outs"), n_outs);
141 if (p->multichannel_name_ambiguity) {
142 uint32_t n_outs = p->max_configurable_ouputs ();
144 if (p->reconfigurable_io ()) {
145 suffix = string_compose(_("\u2264 %1 outs"), n_outs);
147 suffix = string_compose(_("%1 outs"), n_outs);
149 } else if (n_outs == 2) {
150 suffix = _("stereo");
155 if (p->plugintype_name_ambiguity) {
167 pt = enum_2_string (p->type);
169 if (!suffix.empty ()) {
175 std::string name = p->name;
176 if (!suffix.empty ()) {
177 name += " (" + suffix + ")";
180 row = *(_instrument_list->append());
181 row[_instrument_list_columns.name] = name;
183 row[_instrument_list_columns.info_ptr] = p;
184 if (p->unique_id == "https://community.ardour.org/node/7596") {
185 _reasonable_synth_id = n;
187 if (p->unique_id == "http://gareus.org/oss/lv2/gmsynth") {
195 InstrumentSelector::selected_instrument()
197 TreeModel::iterator iter = get_active();
199 return PluginInfoPtr();
202 const TreeModel::Row& row = (*iter);
203 return row[_instrument_list_columns.info_ptr];