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/gtk_ui.h"
32 #include "gtkmm2ext/utils.h"
34 #include "generic_midi_control_protocol.h"
38 class GMCPGUI : public Gtk::VBox
41 GMCPGUI (GenericMidiControlProtocol&);
45 GenericMidiControlProtocol& cp;
46 Gtk::ComboBoxText map_combo;
47 Gtk::Adjustment bank_adjustment;
48 Gtk::SpinButton bank_spinner;
49 Gtk::CheckButton motorised_button;
50 Gtk::Adjustment threshold_adjustment;
51 Gtk::SpinButton threshold_spinner;
53 void binding_changed ();
55 void motorised_changed ();
56 void threshold_changed ();
60 using namespace ARDOUR;
63 using namespace Gtkmm2ext;
66 GenericMidiControlProtocol::get_gui () const
69 const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
75 GenericMidiControlProtocol::tear_down_gui ()
77 delete (GMCPGUI*) gui;
81 GenericMidiControlProtocol::build_gui ()
83 gui = (void*) new GMCPGUI (*this);
86 /*--------------------*/
88 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
90 , bank_adjustment (1, 1, 100, 1, 10)
91 , bank_spinner (bank_adjustment)
92 , motorised_button ("Motorised")
93 , threshold_adjustment (p.threshold(), 1, 127, 1, 10)
94 , threshold_spinner (threshold_adjustment)
96 vector<string> popdowns;
97 popdowns.push_back (_("Reset All"));
99 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
100 popdowns.push_back (x->name);
103 set_popdown_strings (map_combo, popdowns);
105 if (cp.current_binding().empty()) {
106 map_combo.set_active_text (popdowns[0]);
108 map_combo.set_active_text (cp.current_binding());
111 map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
114 set_border_width (6);
116 Table* table = manage (new Table);
117 table->set_row_spacings (6);
118 table->set_col_spacings (6);
123 Label* label = manage (new Label (_("MIDI Bindings:")));
124 label->set_alignment (0, 0.5);
125 table->attach (*label, 0, 1, n, n + 1);
126 table->attach (map_combo, 1, 2, n, n + 1);
132 bank_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::bank_changed));
134 label = manage (new Label (_("Current Bank:")));
135 label->set_alignment (0, 0.5);
136 table->attach (*label, 0, 1, n, n + 1);
137 table->attach (bank_spinner, 1, 2, n, n + 1);
140 bank_spinner.show ();
143 motorised_button.signal_toggled().connect (sigc::mem_fun (*this, &GMCPGUI::motorised_changed));
144 table->attach (motorised_button, 0, 2, n, n + 1);
147 motorised_button.show ();
149 threshold_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::threshold_changed));
151 Gtkmm2ext::UI::instance()->set_tip (threshold_spinner,
152 string_compose (_("Controls how %1 behaves if the MIDI controller sends discontinuous values"), PROGRAM_NAME));
154 label = manage (new Label (_("Smoothing:")));
155 label->set_alignment (0, 0.5);
156 table->attach (*label, 0, 1, n, n + 1);
157 table->attach (threshold_spinner, 1, 2, n, n + 1);
160 threshold_spinner.show ();
163 pack_start (*table, false, false);
173 GMCPGUI::bank_changed ()
175 int new_bank = bank_adjustment.get_value() - 1;
176 cp.set_current_bank (new_bank);
180 GMCPGUI::binding_changed ()
182 string str = map_combo.get_active_text ();
184 if (str == _("Reset All")) {
187 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
188 if (str == x->name) {
189 cp.load_bindings (x->path);
190 motorised_button.set_active (cp.motorised ());
191 threshold_adjustment.set_value (cp.threshold ());
199 GMCPGUI::motorised_changed ()
201 cp.set_motorised (motorised_button.get_active ());
205 GMCPGUI::threshold_changed ()
207 cp.set_threshold (threshold_adjustment.get_value());