448d803c365e1a4f9d65d70f6f08f4a7894d4730
[ardour.git] / libs / ardour / ardour / tranzport_control_protocol.h
1 #ifndef ardour_tranzport_control_protocol_h
2 #define ardour_tranzport_control_protocol_h
3
4 #include <pthread.h>
5 #include <usb.h>
6 #include <ardour/control_protocol.h>
7 #include <ardour/types.h>
8
9 namespace ARDOUR {
10
11 class TranzportControlProtocol : public ControlProtocol {
12   public:
13         TranzportControlProtocol (Session&);
14         virtual ~TranzportControlProtocol();
15
16         int init ();
17         bool active() const;
18
19         void send_route_feedback (std::list<Route*>&);
20         void send_global_feedback ();
21
22   private:
23         static const int VENDORID = 0x165b;
24         static const int PRODUCTID = 0x8101;
25         static const int READ_ENDPOINT  = 0x81;
26         static const int WRITE_ENDPOINT = 0x02;
27         const static int STATUS_OFFLINE  = 0xff;
28         const static int STATUS_ONLINE = 0x01;
29
30         enum LightID {
31                 LightRecord = 0,
32                 LightTrackrec,
33                 LightTrackmute,
34                 LightTracksolo,
35                 LightAnysolo,
36                 LightLoop,
37                 LightPunch
38         };
39
40         enum ButtonID {
41                 ButtonBattery = 0x00004000,
42                 ButtonBacklight = 0x00008000,
43                 ButtonTrackLeft = 0x04000000,
44                 ButtonTrackRight = 0x40000000,
45                 ButtonTrackRec = 0x00040000,
46                 ButtonTrackMute = 0x00400000,
47                 ButtonTrackSolo = 0x00000400,
48                 ButtonUndo = 0x80000000,
49                 ButtonIn = 0x02000000,
50                 ButtonOut = 0x20000000,
51                 ButtonPunch = 0x00800000,
52                 ButtonLoop = 0x00080000,
53                 ButtonPrev = 0x00020000,
54                 ButtonAdd = 0x00200000,
55                 ButtonNext = 0x00000200,
56                 ButtonRewind = 0x01000000,
57                 ButtonFastForward = 0x10000000,
58                 ButtonStop = 0x00010000,
59                 ButtonPlay = 0x00100000,
60                 ButtonRecord = 0x00000100,
61                 ButtonShift = 0x08000000
62         };
63                 
64         pthread_t       thread;
65         uint32_t        buttonmask;
66         uint32_t        timeout;
67         uint8_t        _datawheel;
68         uint8_t        _device_status;
69         usb_dev_handle* udev;
70         Route*          current_route;
71         uint32_t        current_track_id;
72
73         bool     last_negative;
74         uint32_t last_hrs;
75         uint32_t last_mins;
76         uint32_t last_secs;
77         uint32_t last_frames;
78         jack_nframes_t last_where;
79
80         int open ();
81         int read ();
82         int write (uint8_t* cmd);
83         int close ();
84
85         int open_core (struct usb_device*);
86
87         void lcd_clear ();
88         int  lcd_write (uint8_t cell, const char *text);
89
90         int  light_on (LightID);
91         int  light_off (LightID);
92
93         void show_current_track ();
94
95         static void* _thread_work (void* arg);
96         void* thread_work ();
97
98         void button_event_battery_press (bool shifted);
99         void button_event_battery_release (bool shifted);
100         void button_event_backlight_press (bool shifted);
101         void button_event_backlight_release (bool shifted);
102         void button_event_trackleft_press (bool shifted);
103         void button_event_trackleft_release (bool shifted);
104         void button_event_trackright_press (bool shifted);
105         void button_event_trackright_release (bool shifted);
106         void button_event_trackrec_press (bool shifted);
107         void button_event_trackrec_release (bool shifted);
108         void button_event_trackmute_press (bool shifted);
109         void button_event_trackmute_release (bool shifted);
110         void button_event_tracksolo_press (bool shifted);
111         void button_event_tracksolo_release (bool shifted);
112         void button_event_undo_press (bool shifted);
113         void button_event_undo_release (bool shifted);
114         void button_event_in_press (bool shifted);
115         void button_event_in_release (bool shifted);
116         void button_event_out_press (bool shifted);
117         void button_event_out_release (bool shifted);
118         void button_event_punch_press (bool shifted);
119         void button_event_punch_release (bool shifted);
120         void button_event_loop_press (bool shifted);
121         void button_event_loop_release (bool shifted);
122         void button_event_prev_press (bool shifted);
123         void button_event_prev_release (bool shifted);
124         void button_event_add_press (bool shifted);
125         void button_event_add_release (bool shifted);
126         void button_event_next_press (bool shifted);
127         void button_event_next_release (bool shifted);
128         void button_event_rewind_press (bool shifted);
129         void button_event_rewind_release (bool shifted);
130         void button_event_fastforward_press (bool shifted);
131         void button_event_fastforward_release (bool shifted);
132         void button_event_stop_press (bool shifted);
133         void button_event_stop_release (bool shifted);
134         void button_event_play_press (bool shifted);
135         void button_event_play_release (bool shifted);
136         void button_event_record_press (bool shifted);
137         void button_event_record_release (bool shifted);
138 };
139
140 } // namespace
141
142 #endif // ardour_tranzport_control_protocol_h