2 Copyright (C) 2003-2014 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.
19 #include "pbd/convert.h"
20 #include "pbd/enumwriter.h"
21 #include "ardour/plugin_manager.h"
22 #include "gtkmm2ext/gui_thread.h"
23 #include "instrument_selector.h"
28 using namespace ARDOUR;
30 InstrumentSelector::InstrumentSelector()
31 : _reasonable_synth_id(0)
32 , _gmsynth_id(UINT32_MAX)
36 PluginManager::instance ().PluginListChanged.connect (_update_connection, invalidator (*this), boost::bind (&InstrumentSelector::refill, this), gui_context());
40 InstrumentSelector::refill()
42 TreeModel::iterator iter = get_active();
45 const TreeModel::Row& row = (*iter);
46 selected = row[_instrument_list_columns.name];
51 build_instrument_list();
52 set_model(_instrument_list);
53 pack_start(_instrument_list_columns.name);
54 if (selected.empty ()) {
55 if (_gmsynth_id != UINT32_MAX) {
56 set_active(_gmsynth_id);
58 set_active(_reasonable_synth_id);
61 TreeModel::Children rows = _instrument_list->children();
62 TreeModel::Children::iterator i;
63 for (i = rows.begin(); i != rows.end(); ++i) {
64 std::string cn = (*i)[_instrument_list_columns.name];
71 set_button_sensitivity(Gtk::SENSITIVITY_AUTO);
75 pluginsort (const PluginInfoPtr& a, const PluginInfoPtr& b)
77 return PBD::downcase(a->name) < PBD::downcase(b->name);
81 invalid_instrument (PluginInfoPtr p) {
82 const PluginManager& manager = PluginManager::instance();
83 if (manager.get_status(p) == PluginManager::Hidden) {
86 return !p->is_instrument();
90 InstrumentSelector::build_instrument_list()
92 PluginManager& manager = PluginManager::instance();
94 PluginInfoList all_plugs;
95 all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
96 all_plugs.insert(all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
97 #ifdef WINDOWS_VST_SUPPORT
98 all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
101 all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
103 #ifdef MACVST_SUPPORT
104 all_plugs.insert(all_plugs.end(), manager.mac_vst_plugin_info().begin(), manager.mac_vst_plugin_info().end());
106 #ifdef AUDIOUNIT_SUPPORT
107 all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
110 all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
113 all_plugs.remove_if (invalid_instrument);
114 all_plugs.sort (pluginsort);
116 _instrument_list = ListStore::create(_instrument_list_columns);
118 TreeModel::Row row = *(_instrument_list->append());
119 row[_instrument_list_columns.info_ptr] = PluginInfoPtr();
120 row[_instrument_list_columns.name] = _("-none-");
124 for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end();) {
125 PluginInfoPtr p = *i;
127 bool suffix_type = prev == p->name;
128 if (!suffix_type && i != all_plugs.end() && (*i)->name == p->name) {
132 row = *(_instrument_list->append());
145 pt = enum_2_string (p->type);
147 row[_instrument_list_columns.name] = p->name + " (" + pt + ")";
149 row[_instrument_list_columns.name] = p->name;
151 row[_instrument_list_columns.info_ptr] = p;
152 if (p->unique_id == "https://community.ardour.org/node/7596") {
153 _reasonable_synth_id = n;
155 if (p->unique_id == "http://gareus.org/oss/lv2/gmsynth") {
156 _reasonable_synth_id = n;
164 InstrumentSelector::selected_instrument()
166 TreeModel::iterator iter = get_active();
168 return PluginInfoPtr();
171 const TreeModel::Row& row = (*iter);
172 return row[_instrument_list_columns.info_ptr];