enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / instrument_selector.cc
1 /*
2   Copyright (C) 2003-2014 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #include "ardour/plugin_manager.h"
20 #include "gtkmm2ext/gui_thread.h"
21 #include "instrument_selector.h"
22
23 #include "pbd/i18n.h"
24
25 using namespace Gtk;
26 using namespace ARDOUR;
27
28 InstrumentSelector::InstrumentSelector()
29         : _reasonable_synth_id(0)
30 {
31         refill ();
32
33         PluginManager::instance ().PluginListChanged.connect (_update_connection, invalidator (*this), boost::bind (&InstrumentSelector::refill, this), gui_context());
34 }
35
36 void
37 InstrumentSelector::refill()
38 {
39         TreeModel::iterator iter = get_active();
40         std::string selected;
41         if (iter) {
42                 const TreeModel::Row& row = (*iter);
43                 selected = row[_instrument_list_columns.name];
44         }
45
46         unset_model ();
47         clear ();
48         build_instrument_list();
49         set_model(_instrument_list);
50         pack_start(_instrument_list_columns.name);
51         if (selected.empty ()) {
52                 set_active(_reasonable_synth_id);
53         } else {
54                 TreeModel::Children rows = _instrument_list->children();
55                 TreeModel::Children::iterator i;
56                 for (i = rows.begin(); i != rows.end(); ++i) {
57                         std::string cn = (*i)[_instrument_list_columns.name];
58                         if (cn == selected) {
59                                 set_active(*i);
60                                 break;
61                         }
62                 }
63         }
64         set_button_sensitivity(Gtk::SENSITIVITY_AUTO);
65 }
66
67 void
68 InstrumentSelector::build_instrument_list()
69 {
70         PluginManager& manager = PluginManager::instance();
71
72         PluginInfoList all_plugs;
73         all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
74         all_plugs.insert(all_plugs.end(), manager.lua_plugin_info().begin(), manager.lua_plugin_info().end());
75 #ifdef WINDOWS_VST_SUPPORT
76         all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
77 #endif
78 #ifdef LXVST_SUPPORT
79         all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
80 #endif
81 #ifdef AUDIOUNIT_SUPPORT
82         all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
83 #endif
84 #ifdef LV2_SUPPORT
85         all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
86 #endif
87
88         _instrument_list = ListStore::create(_instrument_list_columns);
89
90         TreeModel::Row row = *(_instrument_list->append());
91         row[_instrument_list_columns.info_ptr] = PluginInfoPtr();
92         row[_instrument_list_columns.name]     = _("-none-");
93
94         uint32_t n = 1;
95         for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
96                 if (manager.get_status(*i) == PluginManager::Hidden) {
97                         continue;
98                 }
99
100                 if ((*i)->is_instrument()) {
101                         row                                    = *(_instrument_list->append());
102                         row[_instrument_list_columns.name]     = (*i)->name;
103                         row[_instrument_list_columns.info_ptr] = *i;
104                         if ((*i)->unique_id == "https://community.ardour.org/node/7596") {
105                                 _reasonable_synth_id = n;
106                         }
107                         n++;
108                 }
109         }
110 }
111
112 PluginInfoPtr
113 InstrumentSelector::selected_instrument()
114 {
115         TreeModel::iterator iter = get_active();
116         if (!iter) {
117                 return PluginInfoPtr();
118         }
119
120         const TreeModel::Row& row = (*iter);
121         return row[_instrument_list_columns.info_ptr];
122 }