2 Copyright (C) 2006 Paul Davis
3 Copyright (C) 2007 Mike Taht
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef ardour_tranzport_control_protocol_h
23 #define ardour_tranzport_control_protocol_h
25 #include "tranzport_base.h"
32 #if !HAVE_TRANZPORT_KERNEL_DRIVER
36 #include <glibmm/thread.h>
37 #include <ardour/types.h>
39 #include <control_protocol/control_protocol.h>
41 class TranzportControlProtocol : public ARDOUR::ControlProtocol
44 TranzportControlProtocol (ARDOUR::Session&);
45 virtual ~TranzportControlProtocol();
47 int set_active (bool yn);
51 XMLNode& get_state ();
52 int set_state (const XMLNode&);
55 static const int VENDORID = 0x165b;
56 static const int PRODUCTID = 0x8101;
57 static const int READ_ENDPOINT = 0x81;
58 static const int WRITE_ENDPOINT = 0x02;
59 const static int STATUS_OFFLINE = 0xff;
60 const static int STATUS_ONLINE = 0x01;
61 const static int STATUS_OK = 0x00;
63 const static int LIGHTS = 7;
64 const static int ROWS = 2;
65 const static int COLUMNS = 20;
66 const static uint8_t WheelDirectionThreshold = 0x7f;
79 ButtonBattery = 0x00004000,
80 ButtonBacklight = 0x00008000,
81 ButtonTrackLeft = 0x04000000,
82 ButtonTrackRight = 0x40000000,
83 ButtonTrackRec = 0x00040000,
84 ButtonTrackMute = 0x00400000,
85 ButtonTrackSolo = 0x00000400,
86 ButtonUndo = 0x80000000,
87 ButtonIn = 0x02000000,
88 ButtonOut = 0x20000000,
89 ButtonPunch = 0x00800000,
90 ButtonLoop = 0x00080000,
91 ButtonPrev = 0x00020000,
92 ButtonAdd = 0x00200000,
93 ButtonNext = 0x00000200,
94 ButtonRewind = 0x01000000,
95 ButtonFastForward = 0x10000000,
96 ButtonStop = 0x00010000,
97 ButtonPlay = 0x00100000,
98 ButtonRecord = 0x00000100,
99 ButtonShift = 0x08000000,
100 ButtonFootswitch = 0x00001000
103 enum WheelShiftMode {
116 // FIXME - look at gtk2_ardour for snap settings
118 enum WheelIncrement {
131 DisplayRecordingMeter,
150 #if HAVE_TRANZPORT_KERNEL_DRIVER
153 usb_dev_handle* udev;
156 #if TRANZPORT_THREADS
157 pthread_t thread_read;
164 uint32_t current_track_id;
165 #if TRANZPORT_THREADS
166 pthread_t thread_write;
168 int last_write_error;
170 uint8_t _device_status;
171 WheelMode wheel_mode;
172 WheelShiftMode wheel_shift_mode;
173 DisplayMode display_mode;
174 BlingMode bling_mode;
175 WheelIncrement wheel_increment;
177 ARDOUR::gain_t gain_fraction;
179 Glib::Mutex update_lock;
181 std::bitset<ROWS*COLUMNS> screen_invalid;
182 char screen_current[ROWS][COLUMNS];
183 char screen_pending[ROWS][COLUMNS];
184 char screen_flash[ROWS][COLUMNS];
186 std::bitset<LIGHTS> lights_invalid;
187 std::bitset<LIGHTS> lights_current;
188 std::bitset<LIGHTS> lights_pending;
189 std::bitset<LIGHTS> lights_flash;
192 char last_notify_msg[COLUMNS+1];
201 uint32_t last_frames;
202 nframes_t last_where;
203 ARDOUR::gain_t last_track_gain;
204 uint32_t last_meter_fill;
205 struct timeval last_wheel_motion;
211 int read (uint8_t *buf,uint32_t timeout_override = 0);
212 int write (uint8_t* cmd, uint32_t timeout_override = 0);
213 int write_noretry (uint8_t* cmd, uint32_t timeout_override = 0);
215 int save_config(char *name = "default");
216 int load_config(char *name = "default");
217 int save(char *name);
218 int load(char *name);
219 void print (int row, int col, const char* text);
220 void print_noretry (int row, int col, const char* text);
221 void notify(const char *msg);
223 #if HAVE_TRANZPORT_KERNEL_DRIVER
224 int rtpriority_set(int priority = 3); // we don't need serious rt privs anymore
226 int rtpriority_set(int priority = 52);
228 int rtpriority_unset(int priority = 0);
230 // I hate changing the api to do either but until I have clean io class what can you do?
231 #if !HAVE_TRANZPORT_KERNEL_DRIVER
232 int open_core (struct usb_device*);
234 static void* _monitor_work (void* arg);
235 void* monitor_work ();
237 int process (uint8_t *);
241 // bool isuptodate(); // think on this. It seems futile to update more than 30/sec
243 // A screen is a cache of what should be on the lcd
246 void screen_validate();
247 void screen_invalidate();
250 // bool screen_isuptodate(); // think on this -
251 int screen_show_bling();
253 // Commands to write to the lcd
257 bool lcd_isdamaged();
259 bool lcd_damage(int row, int col = 0, int length = COLUMNS);
260 bool lcd_isdamaged(int row, int col = 0, int length = COLUMNS);
263 int lcd_write(uint8_t* cmd, uint32_t timeout_override = 0); // pedantic alias for write
264 void lcd_fill (uint8_t fill_char);
266 void lcd_print (int row, int col, const char* text);
267 void lcd_print_noretry (int row, int col, const char* text);
269 // Commands to write to the lights
270 // FIXME - on some devices lights can have intensity and colors
273 void lights_validate();
274 void lights_invalidate();
275 void light_validate(LightID light);
276 void light_invalidate(LightID light);
278 int lights_write(uint8_t* cmd,uint32_t timeout_override = 0); // pedantic alias to write
280 // a cache of what should be lit
284 int light_set(LightID, bool offon = true);
285 int light_on (LightID);
286 int light_off (LightID);
288 // some modes for the lights, should probably be renamed
290 int lights_show_normal();
291 int lights_show_recording();
292 int lights_show_tempo();
293 int lights_show_bling();
295 void enter_big_meter_mode ();
296 void enter_normal_display_mode ();
297 void enter_config_mode();
298 void enter_recording_mode();
299 void enter_bling_mode();
301 void next_marker (); // basicui doesn't give me enough info
304 void next_display_mode ();
305 void normal_update ();
307 void show_current_track ();
308 void show_track_gain ();
309 void show_transport_time ();
310 void show_bbt (nframes_t where);
311 void show_smpte (nframes_t where);
312 void show_wheel_mode ();
316 void show_mini_meter ();
326 void next_wheel_mode ();
327 void next_wheel_shift_mode ();
329 void set_current_track (ARDOUR::Route*);
332 void step_gain_up ();
333 void step_gain_down ();
334 void step_pan_right ();
335 void step_pan_left ();
338 void button_event_battery_press (bool shifted);
339 void button_event_battery_release (bool shifted);
340 void button_event_backlight_press (bool shifted);
341 void button_event_backlight_release (bool shifted);
342 void button_event_trackleft_press (bool shifted);
343 void button_event_trackleft_release (bool shifted);
344 void button_event_trackright_press (bool shifted);
345 void button_event_trackright_release (bool shifted);
346 void button_event_trackrec_press (bool shifted);
347 void button_event_trackrec_release (bool shifted);
348 void button_event_trackmute_press (bool shifted);
349 void button_event_trackmute_release (bool shifted);
350 void button_event_tracksolo_press (bool shifted);
351 void button_event_tracksolo_release (bool shifted);
352 void button_event_undo_press (bool shifted);
353 void button_event_undo_release (bool shifted);
354 void button_event_in_press (bool shifted);
355 void button_event_in_release (bool shifted);
356 void button_event_out_press (bool shifted);
357 void button_event_out_release (bool shifted);
358 void button_event_punch_press (bool shifted);
359 void button_event_punch_release (bool shifted);
360 void button_event_loop_press (bool shifted);
361 void button_event_loop_release (bool shifted);
362 void button_event_prev_press (bool shifted);
363 void button_event_prev_release (bool shifted);
364 void button_event_add_press (bool shifted);
365 void button_event_add_release (bool shifted);
366 void button_event_next_press (bool shifted);
367 void button_event_next_release (bool shifted);
368 void button_event_rewind_press (bool shifted);
369 void button_event_rewind_release (bool shifted);
370 void button_event_fastforward_press (bool shifted);
371 void button_event_fastforward_release (bool shifted);
372 void button_event_stop_press (bool shifted);
373 void button_event_stop_release (bool shifted);
374 void button_event_play_press (bool shifted);
375 void button_event_play_release (bool shifted);
376 void button_event_record_press (bool shifted);
377 void button_event_record_release (bool shifted);
378 void button_event_footswitch_press(bool shifted);
379 void button_event_footswitch_release (bool shifted);
381 // new api - still thinking about it
382 void button_event_mute (bool pressed, bool shifted);
386 #endif // ardour_tranzport_control_protocol_h