use correct (RCConfig-based) name for MIDI port in generic MIDI control stuff; make...
[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 #include <gtkmm/adjustment.h>
9 #include <gtkmm/spinbutton.h>
10
11 #include "gtkmm2ext/utils.h"
12
13 #include "generic_midi_control_protocol.h"
14
15 #include "i18n.h"
16
17 class GMCPGUI : public Gtk::VBox 
18 {
19 public:
20     GMCPGUI (GenericMidiControlProtocol&);
21     ~GMCPGUI ();
22
23 private:
24     GenericMidiControlProtocol& cp;
25     Gtk::ComboBoxText map_combo;
26     Gtk::Adjustment bank_adjustment;
27     Gtk::SpinButton bank_spinner;
28
29     void binding_changed ();
30     void bank_change ();
31 };
32
33 using namespace PBD;
34 using namespace ARDOUR;
35 using namespace std;
36 using namespace Gtk;
37 using namespace Gtkmm2ext;
38
39 void*
40 GenericMidiControlProtocol::get_gui () const
41 {
42         if (!gui) {
43                 const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
44         }
45         return gui;
46 }
47
48 void
49 GenericMidiControlProtocol::tear_down_gui ()
50 {
51         delete (GMCPGUI*) gui;
52 }
53
54 void
55 GenericMidiControlProtocol::build_gui ()
56 {
57         gui = (void*) new GMCPGUI (*this);
58 }
59
60 /*--------------------*/
61
62 GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
63         : cp (p)
64         , bank_adjustment (1, 1, 100, 1, 10)
65         , bank_spinner (bank_adjustment)
66 {
67         vector<string> popdowns;
68         popdowns.push_back (_("Reset All"));
69
70         for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
71                 popdowns.push_back ((*x).name);
72         }
73
74         set_popdown_strings (map_combo, popdowns, true, 5, 2);
75         
76         if (cp.current_binding().empty()) {
77                 map_combo.set_active_text (popdowns[0]);
78         } else {
79                 map_combo.set_active_text (cp.current_binding());
80         }
81
82         map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
83
84         set_spacing (6);
85         set_border_width (12);
86
87         Label* label = manage (new Label (_("Available MIDI bindings:")));
88         HBox* hpack = manage (new HBox);
89
90         hpack->set_spacing (6);
91         hpack->pack_start (*label, false, false);
92         hpack->pack_start (map_combo, false, false);
93
94         map_combo.show ();
95         label->show ();
96         hpack->show ();
97         
98         pack_start (*hpack, false, false);
99
100
101         bank_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::bank_change));
102
103         label = manage (new Label (_("Current Bank:")));
104         hpack = manage (new HBox);
105
106         hpack->set_spacing (6);
107         hpack->pack_start (*label, false, false);
108         hpack->pack_start (bank_spinner, false, false);
109
110
111         bank_spinner.show ();
112         label->show ();
113         hpack->show ();
114
115         pack_start (*hpack, false, false);
116
117 }
118
119 GMCPGUI::~GMCPGUI ()
120 {
121 }
122
123 void
124 GMCPGUI::bank_change ()
125 {
126         int new_bank = bank_adjustment.get_value() - 1;
127         cp.set_current_bank (new_bank);
128 }
129
130 void
131 GMCPGUI::binding_changed ()
132 {
133         string str = map_combo.get_active_text ();
134
135         if (str == _("Reset All")) {
136                 cp.drop_bindings ();
137         } else {
138                 for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
139                         if (str == (*x).name) {
140                                 cp.load_bindings ((*x).path);
141                                 break;
142                         }
143                 }
144         }
145 }