Add a GUI to set the number of active extenders for the Mackie control surface.
[ardour.git] / libs / surfaces / mackie / gui.cc
1 /*
2         Copyright (C) 2010 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #include <gtkmm/comboboxtext.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/spinbutton.h>
22 #include <gtkmm/table.h>
23 #include "gtkmm2ext/utils.h"
24 #include "ardour/rc_configuration.h"
25 #include "mackie_control_protocol.h"
26 #include "i18n.h"
27
28 using namespace std;
29
30 class MackieControlProtocolGUI : public Gtk::VBox
31 {
32 public:
33         MackieControlProtocolGUI (MackieControlProtocol &);
34
35 private:
36
37         void surface_combo_changed ();
38         void extenders_changed ();
39         
40         MackieControlProtocol& _cp;
41         Gtk::ComboBoxText _surface_combo;
42         Gtk::SpinButton _extenders;
43 };
44
45 void*
46 MackieControlProtocol::get_gui () const
47 {
48         if (!_gui) {
49                 const_cast<MackieControlProtocol*>(this)->build_gui ();
50         }
51
52         return _gui;
53 }
54
55 void
56 MackieControlProtocol::tear_down_gui ()
57 {
58         delete (MackieControlProtocolGUI*) _gui;
59 }
60
61 void
62 MackieControlProtocol::build_gui ()
63 {
64         _gui = (void *) new MackieControlProtocolGUI (*this);
65 }
66
67 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
68         : _cp (p)
69 {
70         Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 2));
71         table->set_spacings (4);
72         
73         table->attach (*manage (new Gtk::Label (_("Surface type:"))), 0, 1, 0, 1);
74         table->attach (_surface_combo, 1, 2, 0, 1);
75
76         vector<string> surfaces;
77         surfaces.push_back (_("Mackie Control"));
78         surfaces.push_back (_("Behringer BCF2000"));
79         Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
80
81         if (ARDOUR::Config->get_mackie_emulation () == X_("mcu")) {
82                 _surface_combo.set_active_text (surfaces.front ());
83         } else {
84                 _surface_combo.set_active_text (surfaces.back ());
85         }
86
87         _extenders.set_range (0, 8);
88         _extenders.set_increments (1, 4);
89
90         Gtk::Label* l = manage (new Gtk::Label (_("Extenders:")));
91         l->set_alignment (0, 0.5);
92         table->attach (*l, 0, 1, 1, 2);
93         table->attach (_extenders, 1, 2, 1, 2);
94
95         pack_start (*table);
96
97         Gtk::Label* cop_out = manage (new Gtk::Label (_("<i>You must restart Ardour for changes\nto these settings to take effect.</i>")));
98         cop_out->set_use_markup (true);
99         pack_start (*cop_out);
100
101         set_spacing (4);
102         show_all ();
103
104         _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
105         _extenders.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::extenders_changed));
106 }
107
108 void
109 MackieControlProtocolGUI::surface_combo_changed ()
110 {
111         if (_surface_combo.get_active_text() == _("Mackie Control")) {
112                 ARDOUR::Config->set_mackie_emulation (X_("mcu"));
113         } else {
114                 ARDOUR::Config->set_mackie_emulation (X_("bcf"));
115         }
116 }
117
118 void
119 MackieControlProtocolGUI::extenders_changed ()
120 {
121         ARDOUR::Config->set_mackie_extenders (_extenders.get_value_as_int ());
122 }