MCP: more button tracing, more config stuff
[ardour.git] / libs / surfaces / mackie / gui.cc
1 /*
2         Copyright (C) 2010 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 <gtkmm/comboboxtext.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/spinbutton.h>
22 #include <gtkmm/table.h>
23 #include <gtkmm/treeview.h>
24 #include <gtkmm/liststore.h>
25 #include <gtkmm/treestore.h>
26 #include <gtkmm/notebook.h>
27 #include <gtkmm/cellrenderercombo.h>
28
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/actions.h"
31
32 #include "mackie_control_protocol.h"
33 #include "device_info.h"
34 #include "gui.h"
35
36 #include "i18n.h"
37
38 using namespace std;
39 using namespace Mackie;
40 using namespace Gtk;
41
42 void*
43 MackieControlProtocol::get_gui () const
44 {
45         if (!_gui) {
46                 const_cast<MackieControlProtocol*>(this)->build_gui ();
47         }
48
49         return _gui;
50 }
51
52 void
53 MackieControlProtocol::tear_down_gui ()
54 {
55         delete (MackieControlProtocolGUI*) _gui;
56 }
57
58 void
59 MackieControlProtocol::build_gui ()
60 {
61         _gui = (void *) new MackieControlProtocolGUI (*this);
62 }
63
64 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
65         : _cp (p)
66 {
67         set_border_width (12);
68
69         Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 2));
70         table->set_spacings (4);
71         
72         table->attach (*manage (new Gtk::Label (_("Surface type:"))), 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
73         table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
74
75         vector<string> surfaces;
76         
77         for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
78                 std::cerr << "Dveice known: " << i->first << endl;
79                 surfaces.push_back (i->first);
80         }
81         Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
82         _surface_combo.set_active_text (p.device_info().name());
83         _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
84
85         append_page (*table, _("Device Selection"));
86         table->show_all();
87
88         /* function key editor */
89
90         append_page (function_key_scroller, _("Function Keys"));
91         function_key_scroller.add (function_key_editor);
92         
93         rebuild_function_key_editor ();
94         function_key_scroller.show_all();
95 }
96
97 void
98 MackieControlProtocolGUI::rebuild_function_key_editor ()
99 {
100         /* build a model of all available actions (needs to be tree structured
101          * more) 
102          */
103
104         available_action_model = TreeStore::create (available_action_columns);
105
106         vector<string> a_names;
107         vector<string> a_paths;
108         vector<string> a_tooltips;
109         vector<string> a_keys;
110         vector<Gtk::AccelKey> a_bindings;
111
112         ActionManager::get_all_actions (a_names, a_paths, a_tooltips, a_keys, a_bindings);
113
114         vector<string>::iterator n = a_names.begin();
115         vector<string>::iterator p = a_paths.begin();
116         TreeModel::Row r;
117
118         for (; n != a_names.end(); ++n, ++p) {
119                 r = *(available_action_model->append());
120                 r[available_action_columns.name] = (*n);
121                 r[available_action_columns.path] = (*p);
122         }
123
124         function_key_editor.append_column (_("Key"), function_key_columns.name);
125
126         CellRendererCombo* action_renderer = manage (new CellRendererCombo);
127         action_renderer->property_model() = available_action_model;
128         action_renderer->property_editable() = true;
129         action_renderer->property_text_column() = 1;
130         action_renderer->property_has_entry() = false;
131
132         TreeViewColumn* col;
133
134         col = manage (new TreeViewColumn (_("Plain"), *action_renderer));
135         col->add_attribute (action_renderer->property_text(), function_key_columns.plain);
136         function_key_editor.append_column (*col);
137         
138         col = manage (new TreeViewColumn (_("Shift"), *action_renderer));
139         col->add_attribute (action_renderer->property_text(), function_key_columns.shift);
140         function_key_editor.append_column (*col);
141
142         col = manage (new TreeViewColumn (_("Control"), *action_renderer));
143         col->add_attribute (action_renderer->property_text(), function_key_columns.control);
144         function_key_editor.append_column (*col);
145
146         col = manage (new TreeViewColumn (_("Option"), *action_renderer));
147         col->add_attribute (action_renderer->property_text(), function_key_columns.option);
148         function_key_editor.append_column (*col);
149
150         col = manage (new TreeViewColumn (_("Cmd/Alt"), *action_renderer));
151         col->add_attribute (action_renderer->property_text(), function_key_columns.cmdalt);
152         function_key_editor.append_column (*col);
153
154         col = manage (new TreeViewColumn (_("Shift+Control"), *action_renderer));
155         col->add_attribute (action_renderer->property_text(), function_key_columns.shiftcontrol);
156         function_key_editor.append_column (*col);
157
158         /* now fill with data */
159
160         function_key_model = ListStore::create (function_key_columns);
161
162         r = *(function_key_model->append());
163         r[function_key_columns.name] = "F1";
164         r = *(function_key_model->append());
165         r[function_key_columns.name] = "F2";
166         r = *(function_key_model->append());
167         r[function_key_columns.name] = "F3";
168         r = *(function_key_model->append());
169         r[function_key_columns.name] = "F4";
170         r = *(function_key_model->append());
171         r[function_key_columns.name] = "F5";
172         r = *(function_key_model->append());
173         r[function_key_columns.name] = "F6";
174         r = *(function_key_model->append());
175         r[function_key_columns.name] = "F7";
176         r = *(function_key_model->append());
177         r[function_key_columns.name] = "F8";
178
179         function_key_editor.set_model (function_key_model);
180 }
181
182 void
183 MackieControlProtocolGUI::surface_combo_changed ()
184 {
185         _cp.set_device (_surface_combo.get_active_text());
186 }
187
188