globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / libs / surfaces / frontier / tranzport / tranzport_control_protocol.h
1
2 #ifndef ardour_tranzport_control_protocol_h
3 #define ardour_tranzport_control_protocol_h
4
5 #include <vector>
6
7 #include <sys/time.h>
8 #include <pthread.h>
9 #include <usb.h>
10
11 #include <glibmm/threads.h>
12
13 #include "ardour/types.h"
14
15 #include "control_protocol/control_protocol.h"
16
17 class TranzportControlProtocol : public ARDOUR::ControlProtocol
18 {
19   public:
20         TranzportControlProtocol (ARDOUR::Session&);
21         virtual ~TranzportControlProtocol();
22
23         int set_active (bool yn);
24
25         static bool probe ();
26
27         XMLNode& get_state ();
28         int set_state (const XMLNode&);
29
30   private:
31         static const int VENDORID = 0x165b;
32         static const int PRODUCTID = 0x8101;
33         static const int READ_ENDPOINT  = 0x81;
34         static const int WRITE_ENDPOINT = 0x02;
35         const static int STATUS_OFFLINE  = 0xff;
36         const static int STATUS_ONLINE = 0x01;
37         const static uint8_t WheelDirectionThreshold = 0x3f;
38
39         enum LightID {
40                 LightRecord = 0,
41                 LightTrackrec,
42                 LightTrackmute,
43                 LightTracksolo,
44                 LightAnysolo,
45                 LightLoop,
46                 LightPunch
47         };
48
49         enum ButtonID {
50                 ButtonBattery = 0x00004000,
51                 ButtonBacklight = 0x00008000,
52                 ButtonTrackLeft = 0x04000000,
53                 ButtonTrackRight = 0x40000000,
54                 ButtonTrackRec = 0x00040000,
55                 ButtonTrackMute = 0x00400000,
56                 ButtonTrackSolo = 0x00000400,
57                 ButtonUndo = 0x80000000,
58                 ButtonIn = 0x02000000,
59                 ButtonOut = 0x20000000,
60                 ButtonPunch = 0x00800000,
61                 ButtonLoop = 0x00080000,
62                 ButtonPrev = 0x00020000,
63                 ButtonAdd = 0x00200000,
64                 ButtonNext = 0x00000200,
65                 ButtonRewind = 0x01000000,
66                 ButtonFastForward = 0x10000000,
67                 ButtonStop = 0x00010000,
68                 ButtonPlay = 0x00100000,
69                 ButtonRecord = 0x00000100,
70                 ButtonShift = 0x08000000
71         };
72
73         enum WheelShiftMode {
74                 WheelShiftGain,
75                 WheelShiftPan,
76                 WheelShiftMaster,
77                 WheelShiftMarker
78         };
79
80         enum WheelMode {
81                 WheelTimeline,
82                 WheelScrub,
83                 WheelShuttle
84         };
85
86         // FIXME - look at gtk2_ardour for snap settings
87
88         enum WheelIncrement {
89                WheelIncrSlave,
90                WheelIncrScreen,
91                WheelIncrSample,
92                WheelIncrBeat,
93                WheelIncrBar,
94                WheelIncrSecond,
95                WheelIncrMinute
96         };
97
98         enum DisplayMode {
99                 DisplayNormal,
100                 DisplayRecording,
101                 DisplayRecordingMeter,
102                 DisplayBigMeter,
103                 DisplayConfig,
104                 DisplayBling,
105                 DisplayBlingMeter
106         };
107
108         enum BlingMode {
109                 BlingOff,
110                 BlingKit,
111                 BlingRotating,
112                 BlingPairs,
113                 BlingRows,
114                 BlingFlashAll
115         };
116
117         pthread_t       thread;
118         uint32_t        buttonmask;
119         uint32_t        timeout;
120         uint32_t        inflight;
121         uint8_t        _datawheel;
122         uint8_t        _device_status;
123         uint32_t        current_track_id;
124         WheelMode       wheel_mode;
125         WheelShiftMode  wheel_shift_mode;
126         DisplayMode     display_mode;
127         BlingMode       bling_mode;
128         WheelIncrement  wheel_increment;
129         usb_dev_handle* udev;
130
131         ARDOUR::gain_t  gain_fraction;
132
133         Glib::Threads::Mutex update_lock;
134
135         bool screen_invalid[2][20];
136         char screen_current[2][20];
137         char screen_pending[2][20];
138         char screen_flash[2][20];
139
140         bool lights_invalid[7];
141         bool lights_current[7];
142         bool lights_pending[7];
143         bool lights_flash[7];
144
145         uint32_t       last_bars;
146         uint32_t       last_beats;
147         uint32_t       last_ticks;
148
149         bool           last_negative;
150         uint32_t       last_hrs;
151         uint32_t       last_mins;
152         uint32_t       last_secs;
153         uint32_t       last_samples;
154         samplepos_t     last_where;
155         ARDOUR::gain_t last_track_gain;
156         uint32_t       last_meter_fill;
157         uint64_t       last_wheel_motion;
158         int            last_wheel_dir;
159
160         Glib::Mutex io_lock;
161
162         int open ();
163         int read (uint8_t *buf,uint32_t timeout_override = 0);
164         int write (uint8_t* cmd, uint32_t timeout_override = 0);
165         int write_noretry (uint8_t* cmd, uint32_t timeout_override = 0);
166         int close ();
167         int save(char *name = "default");
168         int load(char *name = "default");
169         void print (int row, int col, const char* text);
170         void print_noretry (int row, int col, const char* text);
171
172         int rtpriority_set(int priority = 52);
173         int rtpriority_unset(int priority = 0);
174
175         int open_core (struct usb_device*);
176
177         static void* _monitor_work (void* arg);
178         void* monitor_work ();
179
180         int process (uint8_t *);
181         int update_state();
182         void invalidate();
183         int flush();
184         // bool isuptodate(); // think on this. It seems futile to update more than 30/sec
185
186         // A screen is a cache of what should be on the lcd
187
188         void screen_init();
189         void screen_validate();
190         void screen_invalidate();
191         int  screen_flush();
192         void screen_clear();
193         // bool screen_isuptodate(); // think on this -
194
195         // Commands to write to the lcd
196
197         int  lcd_init();
198         bool lcd_damage();
199         bool lcd_isdamaged();
200
201         bool lcd_damage(int row, int col = 0, int length = 20);
202         bool lcd_isdamaged(int row, int col = 0, int length = 20);
203
204         int  lcd_flush();
205         int  lcd_write(uint8_t* cmd, uint32_t timeout_override = 0); // pedantic alias for write
206         void lcd_fill (uint8_t fill_char);
207         void lcd_clear ();
208         void lcd_print (int row, int col, const char* text);
209         void lcd_print_noretry (int row, int col, const char* text);
210
211         // Commands to write to the lights
212         // FIXME - on some devices lights can have intensity and colors
213
214         void lights_init();
215         void lights_validate();
216         void lights_invalidate();
217         void light_validate(LightID light);
218         void light_invalidate(LightID light);
219         int  lights_flush();
220         int  lights_write(uint8_t* cmd,uint32_t timeout_override = 0); // pedantic alias to write
221
222         // a cache of what should be lit
223
224         void lights_off ();
225         void lights_on ();
226         int  light_set(LightID, bool offon = true);
227         int  light_on (LightID);
228         int  light_off (LightID);
229
230         // some modes for the lights, should probably be renamed
231
232         int  lights_show_normal();
233         int  lights_show_recording();
234         int  lights_show_tempo();
235         int  lights_show_bling();
236
237         void enter_big_meter_mode ();
238         void enter_normal_display_mode ();
239         void enter_config_mode();
240         void enter_recording_mode();
241         void enter_bling_mode();
242
243         void next_display_mode ();
244         void normal_update ();
245
246         void show_current_track ();
247         void show_track_gain ();
248         void show_transport_time ();
249         void show_bbt (samplepos_t where);
250         void show_smpte (samplepos_t where);
251         void show_wheel_mode ();
252         void show_gain ();
253         void show_pan ();
254         void show_meter ();
255
256         void datawheel ();
257         void scrub ();
258         void scroll ();
259         void shuttle ();
260         void config ();
261
262         void next_wheel_mode ();
263         void next_wheel_shift_mode ();
264
265         void set_current_track (ARDOUR::Route*);
266         void next_track ();
267         void prev_track ();
268         void step_gain_up ();
269         void step_gain_down ();
270         void step_pan_right ();
271         void step_pan_left ();
272
273
274         void button_event_battery_press (bool shifted);
275         void button_event_battery_release (bool shifted);
276         void button_event_backlight_press (bool shifted);
277         void button_event_backlight_release (bool shifted);
278         void button_event_trackleft_press (bool shifted);
279         void button_event_trackleft_release (bool shifted);
280         void button_event_trackright_press (bool shifted);
281         void button_event_trackright_release (bool shifted);
282         void button_event_trackrec_press (bool shifted);
283         void button_event_trackrec_release (bool shifted);
284         void button_event_trackmute_press (bool shifted);
285         void button_event_trackmute_release (bool shifted);
286         void button_event_tracksolo_press (bool shifted);
287         void button_event_tracksolo_release (bool shifted);
288         void button_event_undo_press (bool shifted);
289         void button_event_undo_release (bool shifted);
290         void button_event_in_press (bool shifted);
291         void button_event_in_release (bool shifted);
292         void button_event_out_press (bool shifted);
293         void button_event_out_release (bool shifted);
294         void button_event_punch_press (bool shifted);
295         void button_event_punch_release (bool shifted);
296         void button_event_loop_press (bool shifted);
297         void button_event_loop_release (bool shifted);
298         void button_event_prev_press (bool shifted);
299         void button_event_prev_release (bool shifted);
300         void button_event_add_press (bool shifted);
301         void button_event_add_release (bool shifted);
302         void button_event_next_press (bool shifted);
303         void button_event_next_release (bool shifted);
304         void button_event_rewind_press (bool shifted);
305         void button_event_rewind_release (bool shifted);
306         void button_event_fastforward_press (bool shifted);
307         void button_event_fastforward_release (bool shifted);
308         void button_event_stop_press (bool shifted);
309         void button_event_stop_release (bool shifted);
310         void button_event_play_press (bool shifted);
311         void button_event_play_release (bool shifted);
312         void button_event_record_press (bool shifted);
313         void button_event_record_release (bool shifted);
314
315         // new api
316         void button_event_mute (bool pressed, bool shifted);
317 };
318
319
320 #endif // ardour_tranzport_control_protocol_h