MCP: switch devices on the fly; name MIDI ports appropriately; fix active state;...
[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
26 #include "mackie_control_protocol.h"
27 #include "device_info.h"
28
29 #include "i18n.h"
30
31 using namespace std;
32 using namespace Mackie;
33
34 class MackieControlProtocolGUI : public Gtk::VBox
35 {
36 public:
37         MackieControlProtocolGUI (MackieControlProtocol &);
38
39 private:
40
41         void surface_combo_changed ();
42         
43         MackieControlProtocol& _cp;
44         Gtk::ComboBoxText _surface_combo;
45 };
46
47 void*
48 MackieControlProtocol::get_gui () const
49 {
50         if (!_gui) {
51                 const_cast<MackieControlProtocol*>(this)->build_gui ();
52         }
53
54         return _gui;
55 }
56
57 void
58 MackieControlProtocol::tear_down_gui ()
59 {
60         delete (MackieControlProtocolGUI*) _gui;
61 }
62
63 void
64 MackieControlProtocol::build_gui ()
65 {
66         _gui = (void *) new MackieControlProtocolGUI (*this);
67 }
68
69 MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
70         : _cp (p)
71 {
72         Gtk::Table* table = Gtk::manage (new Gtk::Table (2, 2));
73         table->set_spacings (4);
74         
75         table->attach (*manage (new Gtk::Label (_("Surface type:"))), 0, 1, 0, 1);
76         table->attach (_surface_combo, 1, 2, 0, 1);
77
78         vector<string> surfaces;
79         
80         for (std::map<std::string,DeviceInfo>::iterator i = DeviceInfo::device_info.begin(); i != DeviceInfo::device_info.end(); ++i) {
81                 std::cerr << "Dveice known: " << i->first << endl;
82                 surfaces.push_back (i->first);
83         }
84         Gtkmm2ext::set_popdown_strings (_surface_combo, surfaces);
85         _surface_combo.set_active_text (p.device_info().name());
86
87         pack_start (*table);
88
89         set_spacing (4);
90         set_border_width (12);
91         show_all ();
92
93         _surface_combo.signal_changed().connect (sigc::mem_fun (*this, &MackieControlProtocolGUI::surface_combo_changed));
94 }
95
96 void
97 MackieControlProtocolGUI::surface_combo_changed ()
98 {
99         _cp.set_device (_surface_combo.get_active_text());
100 }
101
102