Fix Python whitespace (follow PEP8 guidelines, reformatted by Python Reindent)
[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* input_port () const { return _input_port; }
54         MIDI::Port* output_port () const { return _output_port; }
55         void set_feedback_interval (ARDOUR::microseconds_t);
56
57         int set_feedback (bool yn);
58         bool get_feedback () const;
59
60         XMLNode& get_state ();
61         int set_state (const XMLNode&, int version);
62
63         bool has_editor () const { return true; }
64         void* get_gui () const;
65         void  tear_down_gui ();
66
67         int load_bindings (const std::string&);
68         void drop_bindings ();
69         
70         std::string current_binding() const { return _current_binding; }
71
72         struct MapInfo {
73             std::string name;
74             std::string path;
75         };
76
77         std::list<MapInfo> map_info;
78         void reload_maps ();
79
80         void set_current_bank (uint32_t);
81         void next_bank ();
82         void prev_bank ();
83
84   private:
85         MIDI::Port* _input_port;
86         MIDI::Port* _output_port;
87         ARDOUR::microseconds_t _feedback_interval;
88         ARDOUR::microseconds_t last_feedback_time;
89
90         bool  do_feedback;
91         void _send_feedback ();
92         void  send_feedback ();
93
94         typedef std::list<MIDIControllable*> MIDIControllables;
95         MIDIControllables controllables;
96
97         typedef std::list<MIDIFunction*> MIDIFunctions;
98         MIDIFunctions functions;
99
100         typedef std::list<MIDIAction*> MIDIActions;
101         MIDIActions actions;
102
103         typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
104         typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
105         MIDIPendingControllables pending_controllables;
106         Glib::Mutex controllables_lock;
107         Glib::Mutex pending_lock;
108
109         bool start_learning (PBD::Controllable*);
110         void stop_learning (PBD::Controllable*);
111
112         void learning_stopped (MIDIControllable*);
113
114         void create_binding (PBD::Controllable*, int, int);
115         void delete_binding (PBD::Controllable*);
116
117         MIDIControllable* create_binding (const XMLNode&);
118         MIDIFunction* create_function (const XMLNode&);
119         MIDIAction* create_action (const XMLNode&);
120
121         void reset_controllables ();
122         void drop_all ();
123
124         std::string _current_binding;
125         uint32_t _bank_size;
126         uint32_t _current_bank;
127
128         mutable void *gui;
129         void build_gui ();
130 };
131
132 #endif /* ardour_generic_midi_control_protocol_h */