add shuttle dev support, use dflt ff_a/v.png icons, mjpegtools typo patch
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / shuttle.h
1 #ifndef __SHUTTLE_H__
2 #define __SHUTTLE_H__
3
4 #include "arraylist.h"
5 #include "bcwindowbase.inc"
6 #include "linklist.h"
7 #include "shuttle.inc"
8 #include "thread.h"
9
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "awindow.h"
13 #include "awindowgui.h"
14 #include "cwindow.h"
15 #include "cwindowgui.h"
16 #include "vwindow.h"
17 #include "vwindowgui.h"
18
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <string.h>
25
26 #include <linux/input.h>
27 #include <linux/input-event-codes.h>
28 #include <sys/types.h>
29 #include <regex.h>
30
31
32 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
33 // reworked 2019 for cinelerra-gg by William Morrow (aka goodguy)
34
35 // delay in ms before processing each XTest event
36 // CurrentTime means no delay
37 #define DELAY CurrentTime
38
39 // protocol for events from the shuttlepro HUD device
40 //
41 // ev.type values:
42 #define EVENT_TYPE_DONE 0
43 #define EVENT_TYPE_KEY 1
44 #define EVENT_TYPE_JOGSHUTTLE 2
45 #define EVENT_TYPE_ACTIVE_KEY 4
46
47 // ev.code when ev.type == KEY
48 #define EVENT_CODE_KEY1 256
49 // KEY2 257, etc...
50
51 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
52 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
53 enum { JL=0,JR };
54
55 // ev.value when ev.type == KEY
56 // 1 -> PRESS; 0 -> RELEASE
57
58 // ev.code when ev.type == JOGSHUTTLE
59 #define EVENT_CODE_JOG 7
60 #define EVENT_CODE_SHUTTLE 8
61
62 // ev.value when ev.code == JOG
63 // 8 bit value changing by one for each jog step
64
65 // ev.value when ev.code == SHUTTLE
66 // -7 .. 7 encoding shuttle position
67
68 // we define these as extra KeySyms to represent mouse events
69 #define XK_Button_0 0x2000000 // just an offset, not a real button
70 #define XK_Button_1 0x2000001
71 #define XK_Button_2 0x2000002
72 #define XK_Button_3 0x2000003
73 #define XK_Scroll_Up 0x2000004
74 #define XK_Scroll_Down 0x2000005
75
76 #define PRESS 1
77 #define RELEASE 2
78 #define PRESS_RELEASE 3
79 #define HOLD 4
80
81 #define NUM_KEYS 15
82 #define NUM_SHUTTLES 15
83 #define NUM_JOGS 2
84
85 #define KJS_KEY_DOWN 1
86 #define KJS_KEY_UP 2
87 #define KJS_SHUTTLE 3
88 #define KJS_JOG 4
89
90 // cinelerra window input targets
91 #define FOCUS_DEFAULT 0
92 #define FOCUS_MWINDOW 1
93 #define FOCUS_AWINDOW 2
94 #define FOCUS_CWINDOW 3
95 #define FOCUS_VIEWER  4
96 #define FOCUS_LOAD    5
97
98 class KeySymMapping {
99 public:
100         static KeySym to_keysym(const char *str);
101         static const char *to_string(KeySym ks);
102         static KeySymMapping key_sym_mapping[];
103         const char *str;
104         KeySym sym;
105 };
106
107 class Stroke : public ListItem<Stroke>
108 {
109 public:
110         KeySym keysym;
111         int press; // 1:press, 0:release
112 };
113
114 class Strokes : public List<Stroke>
115 {
116 public:
117         Strokes() {}
118         ~Strokes() {}
119         void clear() { while( last ) delete last; }
120         void add_stroke(KeySym keysym, int press=1) {
121                 Stroke *s = append();
122                 s->keysym = keysym; s->press = press;
123         }
124 };
125
126 class Modifiers : public ArrayList<Stroke>
127 {
128         Translation *trans;
129 public:
130         Modifiers(Translation *trans) { this->trans = trans; }
131         ~Modifiers() {}
132
133         void mark_as_down(KeySym sym, int hold);
134         void mark_as_up(KeySym sym);
135         void release(int allkeys);
136         void re_press();
137 };
138
139 class TransName
140 {
141 public:
142         int cin, err;
143         const char *name;
144         regex_t regex;
145
146         TransName(int cin, const char *nm, const char *re);
147         ~TransName();
148 };
149
150 class TransNames : public ArrayList<TransName *>
151 {
152 public:
153         TransNames() {}
154         ~TransNames() { remove_all_objects(); }
155 };
156
157 class Translation : public ListItem<Translation>
158 {
159 public:
160         Translation(Shuttle *shuttle);
161         Translation(Shuttle *shuttle, const char *name);
162         ~Translation();
163         void init(int def);
164         void clear();
165         void append_stroke(KeySym sym, int press);
166         void add_release(int all_keys);
167         void add_keystroke(const char *keySymName, int press_release);
168         void add_keysym(KeySym sym, int press_release);
169         void add_string(const char *str);
170         int start_line(const char *key);
171         void print_strokes(const char *name, const char *up_dn, Strokes *strokes);
172         void print_stroke(Stroke *s);
173         void finish_line();
174         void print_line(const char *key);
175
176         Shuttle *shuttle;
177         TransNames names;
178         const char *name;
179         int is_default, is_key;
180         int first_release_stroke;
181         Strokes *pressed, *released;
182         Strokes *pressed_strokes, *released_strokes;
183         KeySym keysym_down;
184
185         Strokes key_down[NUM_KEYS];
186         Strokes key_up[NUM_KEYS];
187         Strokes shuttles[NUM_SHUTTLES];
188         Strokes jog[NUM_JOGS];
189         Modifiers modifiers;
190 };
191
192 class Translations : public List<Translation>
193 {
194 public:
195         Translations() {}
196         ~Translations() {}
197         void clear() { while( last ) delete last; }
198 };
199
200 class Shuttle : public Thread
201 {
202         int fd;
203         unsigned short jogvalue;
204         int shuttlevalue;
205         struct timeval last_shuttle;
206         int need_synthetic_shuttle;
207         const char *dev_name;
208         Translation *default_translation;
209         Translations translations;
210 public:
211         Shuttle(MWindow *mwindow);
212         ~Shuttle();
213
214         int send_button(unsigned int button, int press);
215         int send_key(KeySym keysym, int press);
216         int send_keysym(KeySym keysym, int press);
217         void send_stroke_sequence(int kjs, int index);
218         void key(unsigned short code, unsigned int value);
219         void shuttle(int value);
220         void jog(unsigned int value);
221         void jogshuttle(unsigned short code, unsigned int value);
222         void start(const char *dev_name);
223         void stop();
224         void handle_event();
225         int get_focused_window_translation();
226         static const char *probe();
227         void run();
228         int read_config_file();
229
230         int done;
231         int failed;
232         int first_time;
233         int debug;
234
235         MWindow *mwindow;
236         Translation *tr, *last_translation;
237         BC_WindowBase *wdw;
238         Window win;
239         unsigned msk;
240         int rx, ry, wx, wy;
241         Window last_focused;
242
243         const char *config_path;
244         time_t config_mtime;
245         input_event ev;
246 };
247
248 #endif