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