e0867fad7808916a5389988234c17c0d9b905c3d
[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
44 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
45   public:
46         GenericMidiControlProtocol (ARDOUR::Session&);
47         virtual ~GenericMidiControlProtocol();
48
49         int set_active (bool yn);
50         static bool probe() { return true; }
51
52         MIDI::Port* port () const { return _port; }
53         void set_feedback_interval (ARDOUR::microseconds_t);
54
55         int set_feedback (bool yn);
56         bool get_feedback () const;
57
58         XMLNode& get_state ();
59         int set_state (const XMLNode&, int version);
60
61         bool has_editor () const { return true; }
62         void* get_gui () const;
63         void  tear_down_gui ();
64
65         int load_bindings (const std::string&);
66         void drop_bindings ();
67         
68         std::string current_binding() const { return _current_binding; }
69
70         struct MapInfo {
71             std::string name;
72             std::string path;
73         };
74
75         std::list<MapInfo> map_info;
76         void reload_maps ();
77
78         void set_current_bank (uint32_t);
79         void next_bank ();
80         void prev_bank ();
81
82   private:
83         MIDI::Port* _port;
84         ARDOUR::microseconds_t _feedback_interval;
85         ARDOUR::microseconds_t last_feedback_time;
86
87         bool  do_feedback;
88         void _send_feedback ();
89         void  send_feedback ();
90
91         typedef std::list<MIDIControllable*> MIDIControllables;
92         MIDIControllables controllables;
93
94         typedef std::list<MIDIFunction*> MIDIFunctions;
95         MIDIFunctions functions;
96
97         typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
98         typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
99         MIDIPendingControllables pending_controllables;
100         Glib::Mutex controllables_lock;
101         Glib::Mutex pending_lock;
102
103         bool start_learning (PBD::Controllable*);
104         void stop_learning (PBD::Controllable*);
105
106         void learning_stopped (MIDIControllable*);
107
108         void create_binding (PBD::Controllable*, int, int);
109         void delete_binding (PBD::Controllable*);
110
111         MIDIControllable* create_binding (const XMLNode&);
112         MIDIFunction* create_function (const XMLNode&);
113
114         void reset_controllables ();
115         void drop_all ();
116
117         std::string _current_binding;
118         uint32_t _bank_size;
119         uint32_t _current_bank;
120
121         mutable void *gui;
122         void build_gui ();
123 };
124
125 #endif /* ardour_generic_midi_control_protocol_h */