2 Copyright (C) 2010 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 <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>
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/actions.h"
32 #include "mackie_control_protocol.h"
33 #include "device_info.h"
39 using namespace Mackie;
43 MackieControlProtocol::get_gui () const
46 const_cast<MackieControlProtocol*>(this)->build_gui ();
53 MackieControlProtocol::tear_down_gui ()
55 delete (MackieControlProtocolGUI*) _gui;
59 MackieControlProtocol::build_gui ()
61 _gui = (void *) new MackieControlProtocolGUI (*this);
64 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
67 set_border_width (12);
69 Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 2));
70 table->set_spacings (4);
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));
75 vector<string> surfaces;
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);
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));
85 append_page (*table, _("Device Selection"));
88 /* function key editor */
90 append_page (function_key_scroller, _("Function Keys"));
91 function_key_scroller.add (function_key_editor);
93 rebuild_function_key_editor ();
94 function_key_scroller.show_all();
98 MackieControlProtocolGUI::rebuild_function_key_editor ()
100 /* build a model of all available actions (needs to be tree structured
104 available_action_model = TreeStore::create (available_action_columns);
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;
112 ActionManager::get_all_actions (a_names, a_paths, a_tooltips, a_keys, a_bindings);
114 vector<string>::iterator n = a_names.begin();
115 vector<string>::iterator p = a_paths.begin();
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);
124 function_key_editor.append_column (_("Key"), function_key_columns.name);
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() = 0;
131 TreeViewColumn* plain_column = manage (new TreeViewColumn (_("Plain"), *action_renderer));
132 function_key_editor.append_column (*plain_column);
134 TreeViewColumn* shift_column = manage (new TreeViewColumn (_("Shift"), *action_renderer));
135 function_key_editor.append_column (*shift_column);
137 TreeViewColumn* control_column = manage (new TreeViewColumn (_("Control"), *action_renderer));
138 function_key_editor.append_column (*control_column);
140 TreeViewColumn* option_column = manage (new TreeViewColumn (_("Option"), *action_renderer));
141 function_key_editor.append_column (*option_column);
143 TreeViewColumn* cmdalt_column = manage (new TreeViewColumn (_("Cmd/Alt"), *action_renderer));
144 function_key_editor.append_column (*cmdalt_column);
146 TreeViewColumn* shiftcontrol_column = manage (new TreeViewColumn (_("Shift+Control"), *action_renderer));
147 function_key_editor.append_column (*shiftcontrol_column);
149 /* now fill with data */
151 function_key_model = ListStore::create (function_key_columns);
153 r = *(function_key_model->append());
154 r[function_key_columns.name] = "F1";
155 r = *(function_key_model->append());
156 r[function_key_columns.name] = "F2";
157 r = *(function_key_model->append());
158 r[function_key_columns.name] = "F3";
159 r = *(function_key_model->append());
160 r[function_key_columns.name] = "F4";
161 r = *(function_key_model->append());
162 r[function_key_columns.name] = "F5";
163 r = *(function_key_model->append());
164 r[function_key_columns.name] = "F6";
165 r = *(function_key_model->append());
166 r[function_key_columns.name] = "F7";
167 r = *(function_key_model->append());
168 r[function_key_columns.name] = "F8";
170 function_key_editor.set_model (function_key_model);
174 MackieControlProtocolGUI::surface_combo_changed ()
176 _cp.set_device (_surface_combo.get_active_text());