2 Copyright (C) 2009-2012 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.
24 #include <gtkmm/comboboxtext.h>
25 #include <gtkmm/label.h>
26 #include <gtkmm/box.h>
27 #include <gtkmm/adjustment.h>
28 #include <gtkmm/spinbutton.h>
29 #include <gtkmm/table.h>
31 #include "gtkmm2ext/utils.h"
33 #include "generic_midi_control_protocol.h"
37 class GMCPGUI : public Gtk::VBox
40 GMCPGUI (GenericMidiControlProtocol&);
44 GenericMidiControlProtocol& cp;
45 Gtk::ComboBoxText map_combo;
46 Gtk::Adjustment bank_adjustment;
47 Gtk::SpinButton bank_spinner;
48 Gtk::CheckButton motorised_button;
49 Gtk::Adjustment threshold_adjustment;
50 Gtk::SpinButton threshold_spinner;
52 void binding_changed ();
54 void motorised_changed ();
55 void threshold_changed ();
59 using namespace ARDOUR;
62 using namespace Gtkmm2ext;
65 GenericMidiControlProtocol::get_gui () const
68 const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
74 GenericMidiControlProtocol::tear_down_gui ()
76 delete (GMCPGUI*) gui;
80 GenericMidiControlProtocol::build_gui ()
82 gui = (void*) new GMCPGUI (*this);
85 /*--------------------*/
87 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
89 , bank_adjustment (1, 1, 100, 1, 10)
90 , bank_spinner (bank_adjustment)
91 , motorised_button ("Motorised")
92 , threshold_adjustment (1, 1, 127, 1, 10)
93 , threshold_spinner (threshold_adjustment)
95 vector<string> popdowns;
96 popdowns.push_back (_("Reset All"));
98 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
99 popdowns.push_back (x->name);
102 set_popdown_strings (map_combo, popdowns);
104 if (cp.current_binding().empty()) {
105 map_combo.set_active_text (popdowns[0]);
107 map_combo.set_active_text (cp.current_binding());
110 map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
113 set_border_width (6);
115 Table* table = manage (new Table);
116 table->set_row_spacings (6);
117 table->set_col_spacings (6);
122 Label* label = manage (new Label (_("MIDI Bindings:")));
123 label->set_alignment (0, 0.5);
124 table->attach (*label, 0, 1, n, n + 1);
125 table->attach (map_combo, 1, 2, n, n + 1);
131 bank_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::bank_changed));
133 label = manage (new Label (_("Current Bank:")));
134 label->set_alignment (0, 0.5);
135 table->attach (*label, 0, 1, n, n + 1);
136 table->attach (bank_spinner, 1, 2, n, n + 1);
139 bank_spinner.show ();
142 motorised_button.signal_toggled().connect (sigc::mem_fun (*this, &GMCPGUI::motorised_changed));
143 table->attach (motorised_button, 0, 2, n, n + 1);
146 motorised_button.show ();
148 threshold_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::threshold_changed));
150 label = manage (new Label (_("Threshold:")));
151 label->set_alignment (0, 0.5);
152 table->attach (*label, 0, 1, n, n + 1);
153 table->attach (threshold_spinner, 1, 2, n, n + 1);
156 threshold_spinner.show ();
159 pack_start (*table, false, false);
169 GMCPGUI::bank_changed ()
171 int new_bank = bank_adjustment.get_value() - 1;
172 cp.set_current_bank (new_bank);
176 GMCPGUI::binding_changed ()
178 string str = map_combo.get_active_text ();
180 if (str == _("Reset All")) {
183 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
184 if (str == x->name) {
185 cp.load_bindings (x->path);
186 motorised_button.set_active (cp.motorised ());
187 threshold_adjustment.set_value (cp.threshold ());
195 GMCPGUI::motorised_changed ()
197 cp.set_motorised (motorised_button.get_active ());
201 GMCPGUI::threshold_changed ()
203 cp.set_threshold (threshold_adjustment.get_value());