editors for control protocols (generalized); editor for Generic MIDI that allows...
[ardour.git] / libs / surfaces / generic_midi / gmcp_gui.cc
1 #include <iostream>
2 #include <list>
3 #include <string>
4
5 #include <gtkmm/comboboxtext.h>
6 #include <gtkmm/label.h>
7 #include <gtkmm/box.h>
8
9 #include "gtkmm2ext/utils.h"
10
11 #include "generic_midi_control_protocol.h"
12
13 #include "i18n.h"
14
15 class GMCPGUI : public Gtk::VBox 
16 {
17 public:
18     GMCPGUI (GenericMidiControlProtocol&);
19     ~GMCPGUI ();
20
21 private:
22     GenericMidiControlProtocol& cp;
23     Gtk::ComboBoxText map_combo;
24
25     void binding_changed ();
26 };
27
28 using namespace PBD;
29 using namespace ARDOUR;
30 using namespace std;
31 using namespace Gtk;
32 using namespace Gtkmm2ext;
33
34 void*
35 GenericMidiControlProtocol::get_gui () const
36 {
37         if (!gui) {
38                 const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
39         }
40         return gui;
41 }
42
43 void
44 GenericMidiControlProtocol::tear_down_gui ()
45 {
46         delete (GMCPGUI*) gui;
47 }
48
49 void
50 GenericMidiControlProtocol::build_gui ()
51 {
52         gui = (void*) new GMCPGUI (*this);
53 }
54
55 /*--------------------*/
56
57 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
58         : cp (p)
59 {
60         vector<string> popdowns;
61         popdowns.push_back (_("Reset All"));
62
63         for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
64                 popdowns.push_back ((*x).name);
65         }
66
67         set_popdown_strings (map_combo, popdowns, true, 5, 2);
68         
69         if (cp.current_binding().empty()) {
70                 map_combo.set_active_text (popdowns[0]);
71         } else {
72                 map_combo.set_active_text (cp.current_binding());
73         }
74
75         map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
76
77         set_border_width (12);
78
79         Label* label = manage (new Label (_("Available MIDI bindings:")));
80         HBox* hpack = manage (new HBox);
81
82         hpack->set_spacing (6);
83         hpack->pack_start (*label, false, false);
84         hpack->pack_start (map_combo, false, false);
85
86         pack_start (*hpack, false, false);
87
88         map_combo.show ();
89         label->show ();
90         hpack->show ();
91 }
92
93 GMCPGUI::~GMCPGUI ()
94 {
95 }
96
97 void
98 GMCPGUI::binding_changed ()
99 {
100         string str = map_combo.get_active_text ();
101
102         if (str == _("Reset All")) {
103                 cp.drop_bindings ();
104         } else {
105                 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
106                         if (str == (*x).name) {
107                                 cp.load_bindings ((*x).path);
108                                 break;
109                         }
110                 }
111         }
112 }