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 ();
71 static_cast<Gtk::VBox*>(gui)->show_all();
76 GenericMidiControlProtocol::tear_down_gui ()
79 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
85 delete (GMCPGUI*) gui;
90 GenericMidiControlProtocol::build_gui ()
92 gui = (void*) new GMCPGUI (*this);
95 /*--------------------*/
97 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
99 , bank_adjustment (1, 1, 100, 1, 10)
100 , bank_spinner (bank_adjustment)
101 , motorised_button ("Motorised")
102 , threshold_adjustment (p.threshold(), 1, 127, 1, 10)
103 , threshold_spinner (threshold_adjustment)
105 vector<string> popdowns;
106 popdowns.push_back (_("Reset All"));
108 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
109 popdowns.push_back (x->name);
112 set_popdown_strings (map_combo, popdowns);
114 if (cp.current_binding().empty()) {
115 map_combo.set_active_text (popdowns[0]);
117 map_combo.set_active_text (cp.current_binding());
120 map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
123 set_border_width (6);
125 Table* table = manage (new Table);
126 table->set_row_spacings (6);
127 table->set_col_spacings (6);
132 Label* label = manage (new Label (_("MIDI Bindings:")));
133 label->set_alignment (0, 0.5);
134 table->attach (*label, 0, 1, n, n + 1);
135 table->attach (map_combo, 1, 2, n, n + 1);
141 bank_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::bank_changed));
143 label = manage (new Label (_("Current Bank:")));
144 label->set_alignment (0, 0.5);
145 table->attach (*label, 0, 1, n, n + 1);
146 table->attach (bank_spinner, 1, 2, n, n + 1);
149 bank_spinner.show ();
152 motorised_button.signal_toggled().connect (sigc::mem_fun (*this, &GMCPGUI::motorised_changed));
153 table->attach (motorised_button, 0, 2, n, n + 1);
156 motorised_button.show ();
157 motorised_button.set_active (p.motorised ());
159 threshold_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::threshold_changed));
161 Gtkmm2ext::UI::instance()->set_tip (threshold_spinner,
162 string_compose (_("Controls how %1 behaves if the MIDI controller sends discontinuous values"), PROGRAM_NAME));
164 label = manage (new Label (_("Smoothing:")));
165 label->set_alignment (0, 0.5);
166 table->attach (*label, 0, 1, n, n + 1);
167 table->attach (threshold_spinner, 1, 2, n, n + 1);
170 threshold_spinner.show ();
173 pack_start (*table, false, false);
183 GMCPGUI::bank_changed ()
185 int new_bank = bank_adjustment.get_value() - 1;
186 cp.set_current_bank (new_bank);
190 GMCPGUI::binding_changed ()
192 string str = map_combo.get_active_text ();
194 if (str == _("Reset All")) {
197 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
198 if (str == x->name) {
199 cp.load_bindings (x->path);
200 motorised_button.set_active (cp.motorised ());
201 threshold_adjustment.set_value (cp.threshold ());
209 GMCPGUI::motorised_changed ()
211 cp.set_motorised (motorised_button.get_active ());
215 GMCPGUI::threshold_changed ()
217 cp.set_threshold (threshold_adjustment.get_value());