Add small GUI to select Mackie / BCF2000 emulation for the mackie 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 "gtkmm2ext/utils.h"
22 #include "ardour/rc_configuration.h"
23 #include "mackie_control_protocol.h"
24 #include "i18n.h"
25
26 using namespace std;
27
28 class MackieControlProtocolGUI : public Gtk::VBox
29 {
30 public:
31         MackieControlProtocolGUI (MackieControlProtocol &);
32
33 private:
34
35         void surface_combo_changed ();
36         
37         MackieControlProtocol& _cp;
38         Gtk::ComboBoxText _surface_combo;
39 };
40
41 void*
42 MackieControlProtocol::get_gui () const
43 {
44         if (!_gui) {
45                 const_cast<MackieControlProtocol*>(this)->build_gui ();
46         }
47
48         return _gui;
49 }
50
51 void
52 MackieControlProtocol::tear_down_gui ()
53 {
54         delete (MackieControlProtocolGUI*) _gui;
55 }
56
57 void
58 MackieControlProtocol::build_gui ()
59 {
60         _gui = (void *) new MackieControlProtocolGUI (*this);
61 }
62
63 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
64         : _cp (p)
65 {
66         Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox);
67         hbox->set_spacing (4);
68         hbox->pack_start (*manage (new Gtk::Label (_("Surface to support:"))));
69         hbox->pack_start (_surface_combo);
70
71         vector<string> surfaces;
72         surfaces.push_back (_("Mackie Control"));
73         surfaces.push_back (_("Behringer BCF2000"));
74         Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
75
76         if (ARDOUR::Config->get_mackie_emulation () == X_("mcu")) {
77                 _surface_combo.set_active_text (surfaces.front ());
78         } else {
79                 _surface_combo.set_active_text (surfaces.back ());
80         }
81
82         pack_start (*hbox);
83
84         show_all ();
85
86         _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
87 }
88
89 void
90 MackieControlProtocolGUI::surface_combo_changed ()
91 {
92         if (_surface_combo.get_active_text() == _("Mackie Control")) {
93                 ARDOUR::Config->set_mackie_emulation (X_("mcu"));
94         } else {
95                 ARDOUR::Config->set_mackie_emulation (X_("bcf"));
96         }
97 }