get faderport i/o working, basics of identifying control activity
[ardour.git] / libs / surfaces / faderport / faderport.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_surface_faderport_h
21 #define ardour_surface_faderport_h
22
23 #include <list>
24 #include <glibmm/threads.h>
25
26 #include "ardour/types.h"
27
28 #include "control_protocol/control_protocol.h"
29
30 namespace PBD {
31         class Controllable;
32         class ControllableDescriptor;
33 }
34
35 #include <midi++/types.h>
36
37 //#include "pbd/signals.h"
38
39
40 //#include "midi_byte_array.h"
41 #include "types.h"
42
43 #include "glibmm/main.h"
44
45 namespace MIDI {
46         class Parser;
47         class Port;
48 }
49
50
51 namespace ARDOUR {
52         class AsyncMIDIPort;
53         class Port;
54         class Session;
55         class MidiPort;
56 }
57
58
59 class MIDIControllable;
60 class MIDIFunction;
61 class MIDIAction;
62
63 class FaderPort : public ARDOUR::ControlProtocol {
64   public:
65         FaderPort (ARDOUR::Session&);
66         virtual ~FaderPort();
67
68         int set_active (bool yn);
69
70         /* It would be nice to send a device query message here to see if
71          * faderport is out there. But the probe() API doesn't provide
72          * a set of ports to be checked, so there's really no nice
73          * way to do this. We would have to fall back on the PortManager
74          * and get a list of all physical ports. Could be done ....
75          */
76         static bool probe() { return true; }
77
78         void set_feedback_interval (ARDOUR::microseconds_t);
79
80         int set_feedback (bool yn);
81         bool get_feedback () const;
82
83         XMLNode& get_state ();
84         int set_state (const XMLNode&, int version);
85
86         bool has_editor () const { return true; }
87         void* get_gui () const;
88         void  tear_down_gui ();
89
90         void set_current_bank (uint32_t);
91         void next_bank ();
92         void prev_bank ();
93
94         void reset_controllables ();
95
96         void set_motorised (bool);
97
98         bool motorised () const {
99                 return _motorised;
100         }
101
102         void set_threshold (int);
103
104         int threshold () const {
105                 return _threshold;
106         }
107
108         bool device_active() const { return _device_active; }
109
110   private:
111         boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
112         boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
113
114         ARDOUR::microseconds_t _feedback_interval;
115         ARDOUR::microseconds_t last_feedback_time;
116         int native_counter;
117
118         bool  do_feedback;
119         void  send_feedback ();
120
121         PBD::ScopedConnectionList midi_connections;
122
123         bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
124
125         std::string _current_binding;
126         uint32_t _bank_size;
127         uint32_t _current_bank;
128         /** true if this surface is motorised.  If it is, we assume
129             that the surface's controls are never out of sync with
130             Ardour's state, so we don't have to take steps to avoid
131             values jumping around when things are not in sync.
132         */
133         bool _motorised;
134         int _threshold;
135
136         mutable void *gui;
137         void build_gui ();
138
139         bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
140         PBD::ScopedConnection port_connection;
141
142         enum ConnectionState {
143                 InputConnected = 0x1,
144                 OutputConnected = 0x2
145         };
146
147         int connection_state;
148         void connected ();
149         bool _device_active;
150         int fader_msb;
151         int fader_lsb;
152
153         void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
154         void switch_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
155         void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
156         void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
157
158         enum InButtonID {
159                 Mute = 18,
160                 Solo = 17,
161                 Rec = 16,
162                 Left = 19,
163                 Bank = 20,
164                 Right = 21,
165                 Output = 22,
166                 Read = 10,
167                 Write = 9,
168                 Touch = 8,
169                 Off = 23,
170                 Mix = 11,
171                 Proj = 12,
172                 Trns = 13,
173                 Undo = 14,
174                 Shift = 2,
175                 Punch = 1,
176                 User = 0,
177                 Loop = 15,
178                 Rewind = 3,
179                 Ffwd = 4,
180                 Stop = 5,
181                 Play = 6,
182                 RecEnable = 7,
183                 Fader = 127,
184         };
185
186         /*
187         enum OutButtonID {
188                 Mute = 18,
189                 Solo = 17,
190                 Rec = 16,
191                 Left = 19,
192                 Bank = 20,
193                 Right = 21,
194                 Output = 22,
195                 Read = 10,
196                 Write = 9,
197                 Touch = 8,
198                 Off = 23,
199                 Mix = 11,
200                 Proj = 12,
201                 Trns = 13,
202                 Undo = 14,
203                 Shift = 2,
204                 Punch = 1,
205                 User = 0,
206                 Loop = 15,
207                 Rewind = 3,
208                 Ffwd = 4,
209                 Stop = 5,
210                 Play = 6,
211                 RecEnable = 7,
212         }
213         */
214 };
215
216 #endif /* ardour_surface_faderport_h */