0311140f8c20c77c54fe82246d84758833e5f44f
[ardour.git] / libs / surfaces / tranzport / tranzport_control_protocol.h
1 #ifndef ardour_tranzport_control_protocol_h
2 #define ardour_tranzport_control_protocol_h
3
4 #include <vector>
5
6 #include <sys/time.h>
7 #include <pbd/lockmonitor.h>
8 #include <pthread.h>
9 #include <usb.h>
10
11 #include <ardour/types.h>
12
13 #include "control_protocol.h"
14
15 class TranzportControlProtocol : public ARDOUR::ControlProtocol
16 {
17   public:
18         TranzportControlProtocol (ARDOUR::Session&);
19         virtual ~TranzportControlProtocol();
20
21         int set_active (bool yn);
22
23         static bool probe ();
24
25   private:
26         static const int VENDORID = 0x165b;
27         static const int PRODUCTID = 0x8101;
28         static const int READ_ENDPOINT  = 0x81;
29         static const int WRITE_ENDPOINT = 0x02;
30         const static int STATUS_OFFLINE  = 0xff;
31         const static int STATUS_ONLINE = 0x01;
32         const static uint8_t WheelDirectionThreshold = 0x3f;
33
34         enum LightID {
35                 LightRecord = 0,
36                 LightTrackrec,
37                 LightTrackmute,
38                 LightTracksolo,
39                 LightAnysolo,
40                 LightLoop,
41                 LightPunch
42         };
43
44         enum ButtonID {
45                 ButtonBattery = 0x00004000,
46                 ButtonBacklight = 0x00008000,
47                 ButtonTrackLeft = 0x04000000,
48                 ButtonTrackRight = 0x40000000,
49                 ButtonTrackRec = 0x00040000,
50                 ButtonTrackMute = 0x00400000,
51                 ButtonTrackSolo = 0x00000400,
52                 ButtonUndo = 0x80000000,
53                 ButtonIn = 0x02000000,
54                 ButtonOut = 0x20000000,
55                 ButtonPunch = 0x00800000,
56                 ButtonLoop = 0x00080000,
57                 ButtonPrev = 0x00020000,
58                 ButtonAdd = 0x00200000,
59                 ButtonNext = 0x00000200,
60                 ButtonRewind = 0x01000000,
61                 ButtonFastForward = 0x10000000,
62                 ButtonStop = 0x00010000,
63                 ButtonPlay = 0x00100000,
64                 ButtonRecord = 0x00000100,
65                 ButtonShift = 0x08000000
66         };
67
68         enum WheelShiftMode {
69                 WheelShiftGain,
70                 WheelShiftPan,
71                 WheelShiftMaster
72         };
73                 
74         enum WheelMode {
75                 WheelTimeline,
76                 WheelScrub,
77                 WheelShuttle
78         };
79
80         enum DisplayMode {
81                 DisplayNormal,
82                 DisplayBigMeter
83         };
84         
85         pthread_t       thread;
86         uint32_t        buttonmask;
87         uint32_t        timeout;
88         uint8_t        _datawheel;
89         uint8_t        _device_status;
90         usb_dev_handle* udev;
91
92         uint32_t        current_track_id;
93         WheelMode       wheel_mode;
94         WheelShiftMode  wheel_shift_mode;
95         DisplayMode     display_mode;
96         ARDOUR::gain_t  gain_fraction;
97
98         PBD::Lock update_lock;
99         char current_screen[2][20];
100         char pending_screen[2][20];
101         bool lights[7];
102         bool pending_lights[7];
103
104         bool           last_negative;
105         uint32_t       last_hrs;
106         uint32_t       last_mins;
107         uint32_t       last_secs;
108         uint32_t       last_frames;
109         jack_nframes_t last_where;
110         ARDOUR::gain_t last_track_gain;
111         uint32_t       last_meter_fill;
112         struct timeval last_wheel_motion;
113         int            last_wheel_dir;
114
115         PBD::Lock io_lock;
116
117         int open ();
118         int read (uint32_t timeout_override = 0);
119         int write (uint8_t* cmd, uint32_t timeout_override = 0);
120         int close ();
121
122         int open_core (struct usb_device*);
123
124         void lcd_clear ();
125         void print (int row, int col, const char* text);
126         int  light_on (LightID);
127         int  light_off (LightID);
128         void lights_off ();
129
130         void enter_big_meter_mode ();
131         void enter_normal_display_mode ();
132
133         void next_display_mode ();
134
135         void normal_update ();
136
137         void show_current_track ();
138         void show_track_gain ();
139         void show_transport_time ();
140         void show_wheel_mode ();
141         void show_gain ();
142         void show_pan ();
143         void show_meter ();
144
145         void datawheel ();
146         void scrub ();
147         void scroll ();
148         void shuttle ();
149
150         void next_wheel_mode ();
151         void next_wheel_shift_mode ();
152
153         void set_current_track (ARDOUR::Route*);
154         void next_track ();
155         void prev_track ();
156         void step_gain_up ();
157         void step_gain_down ();
158         void step_pan_right ();
159         void step_pan_left ();
160
161         static void* _monitor_work (void* arg);
162         void* monitor_work ();
163
164         void button_event_battery_press (bool shifted);
165         void button_event_battery_release (bool shifted);
166         void button_event_backlight_press (bool shifted);
167         void button_event_backlight_release (bool shifted);
168         void button_event_trackleft_press (bool shifted);
169         void button_event_trackleft_release (bool shifted);
170         void button_event_trackright_press (bool shifted);
171         void button_event_trackright_release (bool shifted);
172         void button_event_trackrec_press (bool shifted);
173         void button_event_trackrec_release (bool shifted);
174         void button_event_trackmute_press (bool shifted);
175         void button_event_trackmute_release (bool shifted);
176         void button_event_tracksolo_press (bool shifted);
177         void button_event_tracksolo_release (bool shifted);
178         void button_event_undo_press (bool shifted);
179         void button_event_undo_release (bool shifted);
180         void button_event_in_press (bool shifted);
181         void button_event_in_release (bool shifted);
182         void button_event_out_press (bool shifted);
183         void button_event_out_release (bool shifted);
184         void button_event_punch_press (bool shifted);
185         void button_event_punch_release (bool shifted);
186         void button_event_loop_press (bool shifted);
187         void button_event_loop_release (bool shifted);
188         void button_event_prev_press (bool shifted);
189         void button_event_prev_release (bool shifted);
190         void button_event_add_press (bool shifted);
191         void button_event_add_release (bool shifted);
192         void button_event_next_press (bool shifted);
193         void button_event_next_release (bool shifted);
194         void button_event_rewind_press (bool shifted);
195         void button_event_rewind_release (bool shifted);
196         void button_event_fastforward_press (bool shifted);
197         void button_event_fastforward_release (bool shifted);
198         void button_event_stop_press (bool shifted);
199         void button_event_stop_release (bool shifted);
200         void button_event_play_press (bool shifted);
201         void button_event_play_release (bool shifted);
202         void button_event_record_press (bool shifted);
203         void button_event_record_release (bool shifted);
204
205         int process (uint8_t *);
206         int update_state();
207 };
208
209
210 #endif // ardour_tranzport_control_protocol_h