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() = 1;
130 action_renderer->property_has_entry() = false;
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);
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);
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);
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);
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);
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);
158 /* now fill with data */
160 function_key_model = ListStore::create (function_key_columns);
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";
179 function_key_editor.set_model (function_key_model);
183 MackieControlProtocolGUI::surface_combo_changed ()
185 _cp.set_device (_surface_combo.get_active_text());