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;
50 void binding_changed ();
52 void motorised_changed ();
56 using namespace ARDOUR;
59 using namespace Gtkmm2ext;
62 GenericMidiControlProtocol::get_gui () const
65 const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
71 GenericMidiControlProtocol::tear_down_gui ()
73 delete (GMCPGUI*) gui;
77 GenericMidiControlProtocol::build_gui ()
79 gui = (void*) new GMCPGUI (*this);
82 /*--------------------*/
84 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
86 , bank_adjustment (1, 1, 100, 1, 10)
87 , bank_spinner (bank_adjustment)
88 , motorised_button ("Motorised")
90 vector<string> popdowns;
91 popdowns.push_back (_("Reset All"));
93 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
94 popdowns.push_back (x->name);
97 set_popdown_strings (map_combo, popdowns);
99 if (cp.current_binding().empty()) {
100 map_combo.set_active_text (popdowns[0]);
102 map_combo.set_active_text (cp.current_binding());
105 map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
108 set_border_width (6);
110 Table* table = manage (new Table);
111 table->set_row_spacings (6);
112 table->set_col_spacings (6);
117 Label* label = manage (new Label (_("MIDI Bindings:")));
118 label->set_alignment (0, 0.5);
119 table->attach (*label, 0, 1, n, n + 1);
120 table->attach (map_combo, 1, 2, n, n + 1);
126 bank_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::bank_changed));
128 label = manage (new Label (_("Current Bank:")));
129 label->set_alignment (0, 0.5);
130 table->attach (*label, 0, 1, n, n + 1);
131 table->attach (bank_spinner, 1, 2, n, n + 1);
134 bank_spinner.show ();
137 motorised_button.signal_toggled().connect (sigc::mem_fun (*this, &GMCPGUI::motorised_changed));
138 table->attach (motorised_button, 0, 2, n, n + 1);
141 motorised_button.show ();
143 pack_start (*table, false, false);
151 GMCPGUI::bank_changed ()
153 int new_bank = bank_adjustment.get_value() - 1;
154 cp.set_current_bank (new_bank);
158 GMCPGUI::binding_changed ()
160 string str = map_combo.get_active_text ();
162 if (str == _("Reset All")) {
165 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
166 if (str == x->name) {
167 cp.load_bindings (x->path);
168 motorised_button.set_active (cp.motorised ());
176 GMCPGUI::motorised_changed ()
178 cp.set_motorised (motorised_button.get_active ());