forked from agraef/ShuttlePRO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshuttle.h
118 lines (97 loc) · 2.96 KB
/
shuttle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
// Copyright 2018 Albert Graef <[email protected]>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <linux/input.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <regex.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
// delay in ms before processing each XTest event
// CurrentTime means no delay
#define DELAY CurrentTime
// protocol for events from the shuttlepro HUD device
//
// ev.type values:
#define EVENT_TYPE_DONE 0
#define EVENT_TYPE_KEY 1
#define EVENT_TYPE_JOGSHUTTLE 2
#define EVENT_TYPE_ACTIVE_KEY 4
// ev.code when ev.type == KEY
#define EVENT_CODE_KEY1 256
// KEY2 257, etc...
// ev.value when ev.type == KEY
// 1 -> PRESS; 0 -> RELEASE
// ev.code when ev.type == JOGSHUTTLE
#define EVENT_CODE_JOG 7
#define EVENT_CODE_SHUTTLE 8
// ev.value when ev.code == JOG
// 8 bit value changing by one for each jog step
// ev.value when ev.code == SHUTTLE
// -7 .. 7 encoding shuttle position
// we define these as extra KeySyms to represent mouse events
#define XK_Button_0 0x2000000 // just an offset, not a real button
#define XK_Button_1 0x2000001
#define XK_Button_2 0x2000002
#define XK_Button_3 0x2000003
#define XK_Scroll_Up 0x2000004
#define XK_Scroll_Down 0x2000005
#define PRESS 1
#define RELEASE 2
#define PRESS_RELEASE 3
#define HOLD 4
#define NUM_KEYS 15
#define NUM_SHUTTLES 15
#define NUM_SHUTTLE_INCRS 2
#define NUM_JOGS 2
typedef struct _stroke {
struct _stroke *next;
// nonzero keysym indicates a key event
KeySym keysym;
int press; // zero -> release, non-zero -> press
// keysym == 0 => MIDI event
int status, data; // status and, if applicable, first data byte
// the incremental bit indicates an incremental control change (typically
// used with endless rotary encoders) to be represented as a sign bit value
uint8_t incr;
// the dirty bit indicates a MIDI event for which a release event still
// needs to be generated in key events
uint8_t dirty;
} stroke;
#define KJS_KEY_DOWN 1
#define KJS_KEY_UP 2
#define KJS_SHUTTLE 3
#define KJS_SHUTTLE_INCR 4
#define KJS_JOG 5
typedef struct _translation {
struct _translation *next;
char *name;
int is_default;
regex_t regex;
stroke *key_down[NUM_KEYS];
stroke *key_up[NUM_KEYS];
stroke *shuttle[NUM_SHUTTLES];
stroke *shuttle_incr[NUM_SHUTTLE_INCRS];
stroke *jog[NUM_JOGS];
} translation;
extern int read_config_file(void);
extern translation *get_translation(char *win_title, char *win_class);
extern void print_stroke_sequence(char *name, char *up_or_down, stroke *s);
extern int debug_regex, debug_strokes, debug_keys;
extern int default_debug_regex, default_debug_strokes, default_debug_keys;
extern int midi_octave;
extern char *config_file_name;