-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidikb.h
227 lines (174 loc) · 5.29 KB
/
midikb.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* midikb - A keyboard shortcut daemon
*
* Copyright (c) 2014-2015 Len Ovens <len at ovenwerks dot net>
* Copyright (c) 2005-2006 Theodoros V. Kalamatianos <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _MIDIKB_H_
#define _MIDIKB_H_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
#include <getopt.h>
#include <syslog.h>
#include <signal.h>
#include <sys/types.h>
/* Len's additions */
#include <jack/jack.h>
#include <jack/midiport.h>
/* #include <jack/transport.h> */
#define UNUSED 0
/* Event types */
#define INVALID 0
#define KEY (1<<0)
#define REP (1<<1)
#define REL (1<<2)
#define LED (1<<3)
/* Return values */
enum { OK, USAGE, MEMERR, HOSTFAIL, DEVFAIL, READERR, WRITEERR, EVERR, CONFERR,
FORKERR, INTERR, PIDERR, NOMATCH };
/* Jack client handle */
extern jack_client_t *client;
extern jack_port_t *output_port;
extern jack_port_t *input_port;
/* strings to hold incoming midi events to turn LEDs on/off */
/* mled[0-2][] is LEDs 1 to 3
mled[][0] is controller number (0 to 121)
mled[][1] is LED state - 127 = on 0 = off and 1 = flash */
extern int mled[3][2];
/* we support midi commands up to 20 char
[0] holds the number of char because midi uses 00 as a valid char
really we only look at 3 char on MIDI in right now */
extern char midiin[21];
extern char midiout[21];
/* arrays to hold faders and controllers */
extern int faders[15];
extern int controlers[127];
/* Verbosity level */
extern int verbose;
/* Maximum number of keys */
extern int maxkey;
/* Device grab state */
extern int grabbed;
/* The device name */
extern char *device;
/* The configuration file name */
extern char *config;
/* Logging function */
int lprintf(const char *fmt, ...);
/* Device initialisation */
int init_dev();
/* Device open function */
int open_dev();
/* Device close function */
int close_dev();
/* Device grab function */
int grab_dev();
/* Device un-grab function */
int ungrab_dev();
/* add some jack/midi stuff */
/* config midi input catch events */
/*int midiledcfg(char *line); */
/* Jackd client open */
int jackconnect();
/* Jackd Transport command send */
int jacktransport(char *com);
/* convert text string to midi string */
/* hm we have mde this midiout... */
int midihex2char(char *hex);
/* Take encoder ticks and make a Pitchbend value */
int fader(char *com);
/* Take encoder ticks and make a controler value */
int controler(char *com);
/* Jackd client close */
int jackclose();
/* end of added jack/midi stuff */
/* Keyboard event receiver function */
int get_key(int *key, int *type);
/* Send an event to the input layer */
int snd_key(int key, int type);
/* Set a keyboard LED */
int set_led(int led, int on);
/* Key mask handling */
int get_masksize();
int init_mask(unsigned char **mask);
void free_mask(unsigned char **mask);
int lprint_mask(unsigned char *mask);
int strmask(unsigned char **mask, char *keys);
/* The active key mask */
int init_key_mask();
void free_key_mask();
void clear_key_mask();
int set_key_bit(int bit, int val);
int get_key_bit(int bit);
int cmp_key_mask(unsigned char *mask0, unsigned int attr);
int lprint_key_mask_delim(char c);
int lprint_key_mask();
unsigned char *get_key_mask();
/* The ignored key mask */
int init_ign_mask();
void free_ign_mask();
void clear_ign_mask();
int set_ign_bit(int bit, int val);
int get_ign_bit(int bit);
int cmp_ign_mask(unsigned char *mask0, unsigned int attr);
int lprint_ign_mask_delim(char c);
int lprint_ign_mask();
unsigned char *get_ign_mask();
void copy_key_to_ign_mask();
/* The attribute node struct */
typedef struct _attr_t attr_t;
struct _attr_t {
int type; /* Attribute type */
/* void *opt; */ /* Options for this attribute */
int opt;
attr_t *next; /* The next node */
};
/* Supported attributes */
/* Len adds some more */
#define ATTR_EXEC 0
#define ATTR_GRAB 1
#define ATTR_UNGRAB 2
#define ATTR_IGNREL 3
#define ATTR_RCVREL 4
#define ATTR_ALLREL 5
#define ATTR_KEY 6
#define ATTR_REL 7
#define ATTR_REP 8
#define ATTR_LEDON 9
#define ATTR_LEDOFF 10
#define ATTR_SET 11
#define ATTR_UNSET 12
#define ATTR_JACKT 13
#define ATTR_JACKM 14
#define ATTR_FADER 15
#define ATTR_CNTRL 16
/* The key_cmd struct */
typedef struct {
unsigned char *keys; /* The key mask */
int type; /* The event type */
char *command; /* The command to execute */
unsigned int attr_bits; /* Bitwise attributes */
attr_t *attrs; /* The attribute list */
} key_cmd;
/* The bitwise attribute values */
#define BIT_ATTR_NOEXEC (1<<0) /* Do not call system() */
#define BIT_ATTR_GRABBED (1<<1) /* Match only when the device is grabbed */
#define BIT_ATTR_UNGRABBED (1<<2) /* Match only when the device is not grabbed */
#define BIT_ATTR_NOT (1<<3) /* Match any key except for the specified ones */
#define BIT_ATTR_ALL (1<<4) /* Match if all of the specified keys is pressed */
#define BIT_ATTR_ANY (1<<5) /* Match if any of the specified keys is pressed */
/* Configuration file processing */
int open_config();
int close_config();
int match_key(int type, key_cmd **command);
#endif /* _MIDIKB_H_ */