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