MCP: fix uninitialized variable; start work on extending MCP gui
[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);
73         table->attach (_surface_combo, 1, 2, 0, 1);
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* plain_renderer = manage (new CellRendererCombo);
127         plain_renderer->property_model() = available_action_model;
128         plain_renderer->property_editable() = true;
129         plain_renderer->property_text_column() = 1;
130         TreeViewColumn* plain_column = manage (new TreeViewColumn (_("plain"), *plain_renderer));
131         function_key_editor.append_column (*plain_column);
132 }
133
134 void
135 MackieControlProtocolGUI::surface_combo_changed ()
136 {
137         _cp.set_device (_surface_combo.get_active_text());
138 }
139
140