5 #include "bcwindowbase.inc"
10 #include <linux/input.h>
11 #include <sys/types.h>
13 #ifdef HAVE_SHUTTLE_USB
14 #include <libusb-1.0/libusb.h>
17 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
18 // reworked 2019 for cinelerra-gg by William Morrow (aka goodguy)
20 // delay in ms before processing each XTest event
21 // CurrentTime means no delay
22 #define DELAY CurrentTime
23 // playback max speed -64x .. 64x
24 #define SHUTTLE_MAX_SPEED 64.
25 #define SHUTTLE_INTERFACE 0
27 // protocol for events from the shuttlepro HUD device
30 #define EVENT_TYPE_DONE 0
31 #define EVENT_TYPE_KEY 1
32 #define EVENT_TYPE_JOGSHUTTLE 2
33 #define EVENT_TYPE_ACTIVE_KEY 4
35 // ev.code when ev.type == KEY
36 #define EVENT_CODE_KEY1 256
39 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
40 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
43 // ev.value when ev.type == KEY
44 // 1 -> PRESS; 0 -> RELEASE
46 // ev.code when ev.type == JOGSHUTTLE
47 #define EVENT_CODE_JOG 7
48 #define EVENT_CODE_SHUTTLE 8
50 // ev.value when ev.code == JOG
51 // 8 bit value changing by one for each jog step
53 // ev.value when ev.code == SHUTTLE
54 // -7 .. 7 encoding shuttle position
56 // we define these as extra KeySyms to represent mouse events
57 #define XK_Button_0 0x2000000 // just an offset, not a real button
58 #define XK_Button_1 0x2000001
59 #define XK_Button_2 0x2000002
60 #define XK_Button_3 0x2000003
61 #define XK_Scroll_Up 0x2000004
62 #define XK_Scroll_Down 0x2000005
66 #define PRESS_RELEASE 3
70 #define NUM_SHUTTLES 15
73 #define KJS_KEY_DOWN 1
78 // cinelerra window input targets
79 #define FOCUS_DEFAULT 0
80 #define FOCUS_MWINDOW 1
81 #define FOCUS_AWINDOW 2
82 #define FOCUS_CWINDOW 3
83 #define FOCUS_VIEWER 4
89 struct { uint32_t key, msk; };
93 SKeySym(int k) { key = k; msk = 0; }
94 SKeySym(unsigned k, unsigned m) { key = k; msk = m; }
95 bool operator ==(SKeySym &ks) { return ks.v == v; }
96 operator int() { return key; }
101 static int get_mask(const char *&str);
102 static SKeySym to_keysym(const char *str);
103 static const char *to_string(SKeySym ks);
104 static KeySymMapping key_sym_mapping[];
110 class Stroke : public ListItem<Stroke>
114 int press; // 1:press, 0:release
117 class Strokes : public List<Stroke>
122 void clear() { while( last ) delete last; }
123 void add_stroke(SKeySym keysym, int press=1) {
124 Stroke *s = append();
125 s->keysym = keysym; s->press = press;
129 class Modifiers : public ArrayList<Stroke>
133 Modifiers(Translation *trans) { this->trans = trans; }
136 void mark_as_down(SKeySym sym, int hold);
137 void mark_as_up(SKeySym sym);
138 void release(int allkeys);
148 TransName(int cin, const char *nm, const char *re);
152 class TransNames : public ArrayList<TransName *>
156 ~TransNames() { remove_all_objects(); }
159 class Translation : public ListItem<Translation>
162 Translation(Shuttle *shuttle);
163 Translation(Shuttle *shuttle, const char *name);
167 void append_stroke(SKeySym sym, int press);
168 void add_release(int all_keys);
169 void add_keystroke(const char *keySymName, int press_release);
170 void add_keysym(SKeySym sym, int press_release);
171 void add_string(char *&str);
172 int start_line(const char *key);
173 void print_strokes(const char *name, const char *up_dn, Strokes *strokes);
174 void print_stroke(Stroke *s);
176 void print_line(const char *key);
181 int is_default, is_key;
182 int first_release_stroke;
183 Strokes *pressed, *released;
184 Strokes *pressed_strokes, *released_strokes;
187 Strokes key_down[NUM_KEYS];
188 Strokes key_up[NUM_KEYS];
189 Strokes shuttles[NUM_SHUTTLES];
190 Strokes jog[NUM_JOGS];
194 class Translations : public List<Translation>
199 void clear() { while( last ) delete last; }
202 class Shuttle : public Thread
205 unsigned short jogvalue, shuttlevalue;
207 #ifdef HAVE_SHUTTLE_USB
208 struct libusb_device_handle *devsh;
209 void usb_probe(int idx);
211 unsigned last_jog, last_shuttle, last_btns;
215 Translation *default_translation;
216 Translations translations;
218 Shuttle(MWindow *mwindow);
221 int send_button(unsigned int button, int press);
222 int send_keycode(unsigned key, unsigned msk, int press, int send);
223 int send_keysym(SKeySym keysym, int press);
224 void send_stroke_sequence(int kjs, int index);
225 void key(unsigned short code, unsigned int value);
226 void shuttle(int value);
227 void jog(unsigned int value);
228 void jogshuttle(unsigned short code, unsigned int value);
232 int load_translation();
233 int get_focused_window_translation();
236 int read_config_file();
237 static BC_WindowBase *owns(BC_WindowBase *wdw, Window win);
246 Translation *tr, *last_translation;
253 const char *config_path;