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