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