add support for "msg=" bindings and also action="SomeGroup/Action"
[ardour.git] / libs / surfaces / generic_midi / generic_midi_control_protocol.h
1 /*
2     Copyright (C) 2006 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
20 #ifndef ardour_generic_midi_control_protocol_h
21 #define ardour_generic_midi_control_protocol_h
22
23 #include <list>
24 #include <glibmm/thread.h>
25 #include "ardour/types.h"
26
27 #include "control_protocol/control_protocol.h"
28
29 namespace MIDI {
30         class Port;
31 }
32
33 namespace PBD {
34         class Controllable;
35 }       
36
37 namespace ARDOUR {
38         class Session;
39 }
40
41 class MIDIControllable;
42 class MIDIFunction;
43 class MIDIAction;
44
45 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
46   public:
47         GenericMidiControlProtocol (ARDOUR::Session&);
48         virtual ~GenericMidiControlProtocol();
49
50         int set_active (bool yn);
51         static bool probe() { return true; }
52
53         MIDI::Port* port () const { return _port; }
54         void set_feedback_interval (ARDOUR::microseconds_t);
55
56         int set_feedback (bool yn);
57         bool get_feedback () const;
58
59         XMLNode& get_state ();
60         int set_state (const XMLNode&, int version);
61
62         bool has_editor () const { return true; }
63         void* get_gui () const;
64         void  tear_down_gui ();
65
66         int load_bindings (const std::string&);
67         void drop_bindings ();
68         
69         std::string current_binding() const { return _current_binding; }
70
71         struct MapInfo {
72             std::string name;
73             std::string path;
74         };
75
76         std::list<MapInfo> map_info;
77         void reload_maps ();
78
79         void set_current_bank (uint32_t);
80         void next_bank ();
81         void prev_bank ();
82
83   private:
84         MIDI::Port* _port;
85         ARDOUR::microseconds_t _feedback_interval;
86         ARDOUR::microseconds_t last_feedback_time;
87
88         bool  do_feedback;
89         void _send_feedback ();
90         void  send_feedback ();
91
92         typedef std::list<MIDIControllable*> MIDIControllables;
93         MIDIControllables controllables;
94
95         typedef std::list<MIDIFunction*> MIDIFunctions;
96         MIDIFunctions functions;
97
98         typedef std::list<MIDIAction*> MIDIActions;
99         MIDIActions actions;
100
101         typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
102         typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
103         MIDIPendingControllables pending_controllables;
104         Glib::Mutex controllables_lock;
105         Glib::Mutex pending_lock;
106
107         bool start_learning (PBD::Controllable*);
108         void stop_learning (PBD::Controllable*);
109
110         void learning_stopped (MIDIControllable*);
111
112         void create_binding (PBD::Controllable*, int, int);
113         void delete_binding (PBD::Controllable*);
114
115         MIDIControllable* create_binding (const XMLNode&);
116         MIDIFunction* create_function (const XMLNode&);
117         MIDIAction* create_action (const XMLNode&);
118
119         void reset_controllables ();
120         void drop_all ();
121
122         std::string _current_binding;
123         uint32_t _bank_size;
124         uint32_t _current_bank;
125
126         mutable void *gui;
127         void build_gui ();
128 };
129
130 #endif /* ardour_generic_midi_control_protocol_h */