diff options
-rw-r--r-- | .indent.pro | 47 | ||||
-rw-r--r-- | config.c | 178 |
2 files changed, 137 insertions, 88 deletions
diff --git a/.indent.pro b/.indent.pro new file mode 100644 index 0000000..2de5cd1 --- /dev/null +++ b/.indent.pro | |||
@@ -0,0 +1,47 @@ | |||
1 | -TFILE | ||
2 | -Tfd_mask | ||
3 | -Tfd_set | ||
4 | -Tlinker_sym_tT | ||
5 | -Tu_char | ||
6 | -Tu_int | ||
7 | -Tu_long | ||
8 | -Tu_short | ||
9 | -TTAILQ_HEAD | ||
10 | -TTAILQ_ENTRY | ||
11 | -TLIST_HEAD | ||
12 | -TLIST_ENTRY | ||
13 | -TSTAILQ_HEAD | ||
14 | -TSTAILQ_ENTRY | ||
15 | -TSLIST_HEAD | ||
16 | -TSLIST_ENTRY | ||
17 | -bad | ||
18 | -bap | ||
19 | -nbbb | ||
20 | -nbc | ||
21 | -br | ||
22 | -nbs | ||
23 | -c41 | ||
24 | -cd41 | ||
25 | -cdb | ||
26 | -ce | ||
27 | -ci4 | ||
28 | -cli0 | ||
29 | -d0 | ||
30 | -di8 | ||
31 | -ndj | ||
32 | -ei | ||
33 | -nfc1 | ||
34 | -nfcb | ||
35 | -nut | ||
36 | -i8 | ||
37 | -ip8 | ||
38 | -l79 | ||
39 | -lc77 | ||
40 | -ldi0 | ||
41 | -nlp | ||
42 | -npcs | ||
43 | -psl | ||
44 | -sc | ||
45 | -nsob | ||
46 | -ta | ||
47 | -nv | ||
@@ -59,36 +59,36 @@ enum { | |||
59 | }; | 59 | }; |
60 | 60 | ||
61 | typedef struct { | 61 | typedef struct { |
62 | int id; | 62 | int id; |
63 | char *name; | 63 | char *name; |
64 | } keyword; | 64 | } keyword; |
65 | 65 | ||
66 | static keyword keywords[] = { | 66 | static keyword keywords[] = { |
67 | { KEYWORD_STRINGS, "Strings" }, | 67 | {KEYWORD_STRINGS, "Strings"}, |
68 | { KEYWORD_STRING, "String" }, | 68 | {KEYWORD_STRING, "String"}, |
69 | { KEYWORD_LINE, "Line" }, | 69 | {KEYWORD_LINE, "Line"}, |
70 | { KEYWORD_MODE, "Mode" }, | 70 | {KEYWORD_MODE, "Mode"}, |
71 | { KEYWORD_MODE_ONE_OCTAVE, "midi_one_octave" }, | 71 | {KEYWORD_MODE_ONE_OCTAVE, "midi_one_octave"}, |
72 | { KEYWORD_MODE_TWO_OCTAVES, "midi_two_octaves" }, | 72 | {KEYWORD_MODE_TWO_OCTAVES, "midi_two_octaves"}, |
73 | { KEYWORD_MODE_THREE_OCTAVES, "midi_three_octaves" }, | 73 | {KEYWORD_MODE_THREE_OCTAVES, "midi_three_octaves"}, |
74 | { KEYWORD_MODE_CONTROL, "midi_control" }, | 74 | {KEYWORD_MODE_CONTROL, "midi_control"}, |
75 | { KEYWORD_MODE_CONTROL_INVERSE, "midi_control_inverse" }, | 75 | {KEYWORD_MODE_CONTROL_INVERSE, "midi_control_inverse"}, |
76 | { KEYWORD_CHANNEL, "Channel" }, | 76 | {KEYWORD_CHANNEL, "Channel"}, |
77 | { KEYWORD_NOTE, "Note" }, | 77 | {KEYWORD_NOTE, "Note"}, |
78 | { KEYWORD_AFTERTOUCH, "AfterTouch" }, | 78 | {KEYWORD_AFTERTOUCH, "AfterTouch"}, |
79 | { KEYWORD_NONE, "none" }, | 79 | {KEYWORD_NONE, "none"}, |
80 | { KEYWORD_PITCH_BEND_UP, "pitch_bend_up" }, | 80 | {KEYWORD_PITCH_BEND_UP, "pitch_bend_up"}, |
81 | { KEYWORD_PITCH_BEND_DOWN, "pitch_bend_down" }, | 81 | {KEYWORD_PITCH_BEND_DOWN, "pitch_bend_down"}, |
82 | { KEYWORD_MIDI_CONTROL, "midi_control" }, | 82 | {KEYWORD_MIDI_CONTROL, "midi_control"}, |
83 | { KEYWORD_MIDI_CONTROL_INVERSE, "midi_control_inverse" }, | 83 | {KEYWORD_MIDI_CONTROL_INVERSE, "midi_control_inverse"}, |
84 | { KEYWORD_CONTROLLER, "Controller" }, | 84 | {KEYWORD_CONTROLLER, "Controller"}, |
85 | { KEYWORD_TIMETOSILENCE, "TimeToSilence" }, | 85 | {KEYWORD_TIMETOSILENCE, "TimeToSilence"}, |
86 | { KEYWORD_TWOOCTAVESPLIT, "midi_two_octave_split" }, | 86 | {KEYWORD_TWOOCTAVESPLIT, "midi_two_octave_split"}, |
87 | { KEYWORD_THREEOCTAVESPLIT_1, "midi_three_octave_split_1" }, | 87 | {KEYWORD_THREEOCTAVESPLIT_1, "midi_three_octave_split_1"}, |
88 | { KEYWORD_THREEOCTAVESPLIT_2, "midi_three_octave_split_2" }, | 88 | {KEYWORD_THREEOCTAVESPLIT_2, "midi_three_octave_split_2"}, |
89 | { KEYWORD_MIDI_MAIN_CONTROL, "midi_main_control" }, | 89 | {KEYWORD_MIDI_MAIN_CONTROL, "midi_main_control"}, |
90 | { KEYWORD_MIDI_MAIN_CHANNEL, "midi_main_channel" }, | 90 | {KEYWORD_MIDI_MAIN_CHANNEL, "midi_main_channel"}, |
91 | { -1, 0 } | 91 | {-1, 0} |
92 | }; | 92 | }; |
93 | 93 | ||
94 | static int g_current_string; | 94 | static int g_current_string; |
@@ -102,19 +102,20 @@ config_findkeyword(char **line) | |||
102 | while (isspace(*_l)) | 102 | while (isspace(*_l)) |
103 | ++_l; | 103 | ++_l; |
104 | 104 | ||
105 | for (i=0; keywords[i].name; ++i) { | 105 | for (i = 0; keywords[i].name; ++i) { |
106 | size_t kl = strlen(keywords[i].name); | 106 | size_t kl = strlen(keywords[i].name); |
107 | if (!strncasecmp(_l, keywords[i].name, kl)) { | ||
108 | if (!isspace(_l[kl]) && _l[kl]) | ||
109 | continue; | ||
110 | _l += strlen(keywords[i].name); | ||
111 | 107 | ||
112 | /* Skip rest of white spaces */ | 108 | if (!strncasecmp(_l, keywords[i].name, kl)) { |
113 | while (isspace(*_l)) | 109 | if (!isspace(_l[kl]) && _l[kl]) |
114 | ++_l; | 110 | continue; |
115 | *line = _l; | 111 | _l += strlen(keywords[i].name); |
116 | return keywords[i].id; | 112 | |
117 | } | 113 | /* Skip rest of white spaces */ |
114 | while (isspace(*_l)) | ||
115 | ++_l; | ||
116 | *line = _l; | ||
117 | return keywords[i].id; | ||
118 | } | ||
118 | } | 119 | } |
119 | return -1; | 120 | return -1; |
120 | } | 121 | } |
@@ -143,14 +144,14 @@ config_handle_line(char *line) | |||
143 | int split_done = 0; | 144 | int split_done = 0; |
144 | char *_line = line; | 145 | char *_line = line; |
145 | 146 | ||
146 | //Skip leading spaces | 147 | /* Skip leading spaces */ |
147 | while (isspace(*line)) | 148 | while (isspace(*line)) |
148 | ++line; | 149 | ++line; |
149 | if (*line == 0 || *line == '#' || *line == '\n') | 150 | if (*line == 0 || *line == '#' || *line == '\n') |
150 | return 0; | 151 | return 0; |
151 | 152 | ||
152 | switch (config_findkeyword(&line)) { | 153 | switch (config_findkeyword(&line)) { |
153 | case KEYWORD_STRINGS: | 154 | case KEYWORD_STRINGS: |
154 | g_string_count = atol(line); | 155 | g_string_count = atol(line); |
155 | if (!g_string_count || g_string_count > MAX_LINECOUNT) { | 156 | if (!g_string_count || g_string_count > MAX_LINECOUNT) { |
156 | fprintf(stderr, "Incorrect number of strings: %s\n", _line); | 157 | fprintf(stderr, "Incorrect number of strings: %s\n", _line); |
@@ -158,7 +159,7 @@ config_handle_line(char *line) | |||
158 | } | 159 | } |
159 | printf("GLOBAL: Configuring expected lines %d\n", g_string_count); | 160 | printf("GLOBAL: Configuring expected lines %d\n", g_string_count); |
160 | break; | 161 | break; |
161 | case KEYWORD_STRING: | 162 | case KEYWORD_STRING: |
162 | g_current_string = atol(line) - 1; | 163 | g_current_string = atol(line) - 1; |
163 | printf("Switching to string: %d\n", g_current_string + 1); | 164 | printf("Switching to string: %d\n", g_current_string + 1); |
164 | if (g_current_string < 0 || g_current_string > g_string_count) { | 165 | if (g_current_string < 0 || g_current_string > g_string_count) { |
@@ -166,57 +167,58 @@ config_handle_line(char *line) | |||
166 | return -1; | 167 | return -1; |
167 | } | 168 | } |
168 | break; | 169 | break; |
169 | case KEYWORD_LINE: | 170 | case KEYWORD_LINE: |
170 | { | 171 | { |
171 | LLine *l = &sc->line; | 172 | LLine *l = &sc->line; |
172 | if (sscanf(line, "%d %d %d %d", &l->x0, &l->y0, &l->x1, &l->y1) != 4) { | ||
173 | fprintf(stderr, "Incorrect Line statement for string\n"); | ||
174 | return -1; | ||
175 | } | ||
176 | if (l->y0 > l->y1) { | ||
177 | l->y0 ^= l->y1; | ||
178 | l->y1 ^= l->y0; | ||
179 | l->y0 ^= l->y1; | ||
180 | l->x0 ^= l->x1; | ||
181 | l->x1 ^= l->x0; | ||
182 | l->x0 ^= l->x1; | ||
183 | 173 | ||
174 | if (sscanf(line, "%d %d %d %d", &l->x0, &l->y0, &l->x1, &l->y1) != 4) { | ||
175 | fprintf(stderr, "Incorrect Line statement for string\n"); | ||
176 | return -1; | ||
177 | } | ||
178 | if (l->y0 > l->y1) { | ||
179 | l->y0 ^= l->y1; | ||
180 | l->y1 ^= l->y0; | ||
181 | l->y0 ^= l->y1; | ||
182 | l->x0 ^= l->x1; | ||
183 | l->x1 ^= l->x0; | ||
184 | l->x0 ^= l->x1; | ||
185 | |||
186 | } | ||
187 | if (l->y0 > g_min_y) | ||
188 | g_min_y = l->y0; | ||
189 | if (l->y1 < g_max_y) | ||
190 | g_max_y = l->y1; | ||
191 | break; | ||
184 | } | 192 | } |
185 | if (l->y0 > g_min_y) | 193 | case KEYWORD_MODE: |
186 | g_min_y = l->y0; | ||
187 | if (l->y1 < g_max_y) | ||
188 | g_max_y = l->y1; | ||
189 | break; | ||
190 | } | ||
191 | case KEYWORD_MODE: | ||
192 | switch (config_findkeyword(&line)) { | 194 | switch (config_findkeyword(&line)) { |
193 | case KEYWORD_MODE_ONE_OCTAVE: | 195 | case KEYWORD_MODE_ONE_OCTAVE: |
194 | sc->mode = midi_one_octave; | 196 | sc->mode = midi_one_octave; |
195 | printf("String %d is midi_one_octave\n", 1 + g_current_string); | 197 | printf("String %d is midi_one_octave\n", 1 + g_current_string); |
196 | break; | 198 | break; |
197 | case KEYWORD_MODE_TWO_OCTAVES: | 199 | case KEYWORD_MODE_TWO_OCTAVES: |
198 | sc->mode = midi_two_octaves; | 200 | sc->mode = midi_two_octaves; |
199 | printf("String %d is midi_two_octaves\n", 1 + g_current_string); | 201 | printf("String %d is midi_two_octaves\n", 1 + g_current_string); |
200 | break; | 202 | break; |
201 | case KEYWORD_MODE_THREE_OCTAVES: | 203 | case KEYWORD_MODE_THREE_OCTAVES: |
202 | sc->mode = midi_three_octaves; | 204 | sc->mode = midi_three_octaves; |
203 | printf("String %d is midi_three_octaves\n", 1 + g_current_string); | 205 | printf("String %d is midi_three_octaves\n", 1 + g_current_string); |
204 | break; | 206 | break; |
205 | case KEYWORD_MODE_CONTROL: | 207 | case KEYWORD_MODE_CONTROL: |
206 | sc->mode = midi_control; | 208 | sc->mode = midi_control; |
207 | printf("String %d is midi_control\n", 1 + g_current_string); | 209 | printf("String %d is midi_control\n", 1 + g_current_string); |
208 | break; | 210 | break; |
209 | case KEYWORD_MODE_CONTROL_INVERSE: | 211 | case KEYWORD_MODE_CONTROL_INVERSE: |
210 | sc->mode = midi_control_inv; | 212 | sc->mode = midi_control_inv; |
211 | printf("String %d is midi_control_inverse\n", 1 + g_current_string); | 213 | printf("String %d is midi_control_inverse\n", 1 + g_current_string); |
212 | break; | 214 | break; |
213 | default: | 215 | default: |
214 | fprintf(stderr, "Illegal Mode for string: %s\n", _line); | 216 | fprintf(stderr, "Illegal Mode for string: %s\n", _line); |
215 | return -1; | 217 | return -1; |
216 | 218 | ||
217 | } | 219 | } |
218 | break; | 220 | break; |
219 | case KEYWORD_CHANNEL: | 221 | case KEYWORD_CHANNEL: |
220 | sc->channel = atol(line); | 222 | sc->channel = atol(line); |
221 | if (sc->channel > 16) { | 223 | if (sc->channel > 16) { |
222 | fprintf(stderr, "Incorrect channel specified: %s.\n", _line); | 224 | fprintf(stderr, "Incorrect channel specified: %s.\n", _line); |
@@ -224,7 +226,7 @@ config_handle_line(char *line) | |||
224 | } | 226 | } |
225 | printf("String %d is on channel %d\n", g_current_string, sc->channel); | 227 | printf("String %d is on channel %d\n", g_current_string, sc->channel); |
226 | break; | 228 | break; |
227 | case KEYWORD_NOTE: | 229 | case KEYWORD_NOTE: |
228 | sc->note = config_midi_note_from_string(line); | 230 | sc->note = config_midi_note_from_string(line); |
229 | if (sc->note == 0xff) { | 231 | if (sc->note == 0xff) { |
230 | fprintf(stderr, "Unknown midi note specified: %s.\n", _line); | 232 | fprintf(stderr, "Unknown midi note specified: %s.\n", _line); |
@@ -232,42 +234,42 @@ config_handle_line(char *line) | |||
232 | } | 234 | } |
233 | printf("String %d is midi note %d\n", g_current_string, sc->note); | 235 | printf("String %d is midi note %d\n", g_current_string, sc->note); |
234 | break; | 236 | break; |
235 | case KEYWORD_AFTERTOUCH: | 237 | case KEYWORD_AFTERTOUCH: |
236 | switch (config_findkeyword(&line)) { | 238 | switch (config_findkeyword(&line)) { |
237 | case KEYWORD_NONE: | 239 | case KEYWORD_NONE: |
238 | sc->modifier = none; | 240 | sc->modifier = none; |
239 | printf("String %d does not act aftertouch\n", 1 + g_current_string); | 241 | printf("String %d does not act aftertouch\n", 1 + g_current_string); |
240 | break; | 242 | break; |
241 | case KEYWORD_PITCH_BEND_UP: | 243 | case KEYWORD_PITCH_BEND_UP: |
242 | sc->modifier = pitch_bend_up; | 244 | sc->modifier = pitch_bend_up; |
243 | printf("String %d acts aftertouch as pitch_bend_up\n", 1 + g_current_string); | 245 | printf("String %d acts aftertouch as pitch_bend_up\n", 1 + g_current_string); |
244 | break; | 246 | break; |
245 | case KEYWORD_PITCH_BEND_DOWN: | 247 | case KEYWORD_PITCH_BEND_DOWN: |
246 | sc->modifier = pitch_bend_down; | 248 | sc->modifier = pitch_bend_down; |
247 | printf("String %d acts aftertouch as pitch_bend_down\n", 1 + g_current_string); | 249 | printf("String %d acts aftertouch as pitch_bend_down\n", 1 + g_current_string); |
248 | break; | 250 | break; |
249 | case KEYWORD_MIDI_CONTROL: | 251 | case KEYWORD_MIDI_CONTROL: |
250 | sc->modifier = midi_controller; | 252 | sc->modifier = midi_controller; |
251 | printf("String %d acts aftertouch as midi_controller\n", 1 + g_current_string); | 253 | printf("String %d acts aftertouch as midi_controller\n", 1 + g_current_string); |
252 | break; | 254 | break; |
253 | case KEYWORD_MIDI_CONTROL_INVERSE: | 255 | case KEYWORD_MIDI_CONTROL_INVERSE: |
254 | sc->modifier = midi_controller_inv; | 256 | sc->modifier = midi_controller_inv; |
255 | printf("String %d acts aftertouch as midi_controller_inverse\n", 1 + g_current_string); | 257 | printf("String %d acts aftertouch as midi_controller_inverse\n", 1 + g_current_string); |
256 | break; | 258 | break; |
257 | default: | 259 | default: |
258 | fprintf(stderr, "Illegal Modifier for string: %s\n", _line); | 260 | fprintf(stderr, "Illegal Modifier for string: %s\n", _line); |
259 | return -1; | 261 | return -1; |
260 | } | 262 | } |
261 | break; | 263 | break; |
262 | case KEYWORD_CONTROLLER: | 264 | case KEYWORD_CONTROLLER: |
263 | sc->controller = atol(line); | 265 | sc->controller = atol(line); |
264 | printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); | 266 | printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); |
265 | break; | 267 | break; |
266 | case KEYWORD_TIMETOSILENCE: | 268 | case KEYWORD_TIMETOSILENCE: |
267 | sc->timetosilence = atol(line); | 269 | sc->timetosilence = atol(line); |
268 | printf("String %d has a timetosilence of %d\n", 1 + g_current_string, sc->timetosilence); | 270 | printf("String %d has a timetosilence of %d\n", 1 + g_current_string, sc->timetosilence); |
269 | break; | 271 | break; |
270 | case KEYWORD_TWOOCTAVESPLIT: | 272 | case KEYWORD_TWOOCTAVESPLIT: |
271 | g_midi_two_octave_split = atol(line); | 273 | g_midi_two_octave_split = atol(line); |
272 | printf("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split); | 274 | printf("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split); |
273 | if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) { | 275 | if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) { |
@@ -276,7 +278,7 @@ config_handle_line(char *line) | |||
276 | } | 278 | } |
277 | g_midi_two_octave_split = (256 * g_midi_two_octave_split) / 100; | 279 | g_midi_two_octave_split = (256 * g_midi_two_octave_split) / 100; |
278 | break; | 280 | break; |
279 | case KEYWORD_THREEOCTAVESPLIT_1: | 281 | case KEYWORD_THREEOCTAVESPLIT_1: |
280 | g_midi_three_octave_split_1 = atol(line); | 282 | g_midi_three_octave_split_1 = atol(line); |
281 | printf("Splitting THREE octaves top above %d%%\n", g_midi_three_octave_split_1); | 283 | printf("Splitting THREE octaves top above %d%%\n", g_midi_three_octave_split_1); |
282 | if (g_midi_three_octave_split_1 < 0 || g_midi_three_octave_split_1 > 100) { | 284 | if (g_midi_three_octave_split_1 < 0 || g_midi_three_octave_split_1 > 100) { |
@@ -286,7 +288,7 @@ config_handle_line(char *line) | |||
286 | g_midi_three_octave_split_1 = (256 * g_midi_three_octave_split_1) / 100; | 288 | g_midi_three_octave_split_1 = (256 * g_midi_three_octave_split_1) / 100; |
287 | split_done = 1; | 289 | split_done = 1; |
288 | break; | 290 | break; |
289 | case KEYWORD_THREEOCTAVESPLIT_2: | 291 | case KEYWORD_THREEOCTAVESPLIT_2: |
290 | g_midi_three_octave_split_2 = atol(line); | 292 | g_midi_three_octave_split_2 = atol(line); |
291 | printf("Splitting THREE octaves bottom below %d%%\n", g_midi_three_octave_split_2); | 293 | printf("Splitting THREE octaves bottom below %d%%\n", g_midi_three_octave_split_2); |
292 | if (g_midi_three_octave_split_2 < 0 || g_midi_three_octave_split_2 > 100) { | 294 | if (g_midi_three_octave_split_2 < 0 || g_midi_three_octave_split_2 > 100) { |
@@ -296,7 +298,7 @@ config_handle_line(char *line) | |||
296 | g_midi_three_octave_split_2 = (256 * g_midi_three_octave_split_2) / 100; | 298 | g_midi_three_octave_split_2 = (256 * g_midi_three_octave_split_2) / 100; |
297 | split_done = 1; | 299 | split_done = 1; |
298 | break; | 300 | break; |
299 | case KEYWORD_MIDI_MAIN_CONTROL: | 301 | case KEYWORD_MIDI_MAIN_CONTROL: |
300 | g_midi_main_control = atol(line); | 302 | g_midi_main_control = atol(line); |
301 | printf("All Strings modify controller %d\n", g_midi_main_control); | 303 | printf("All Strings modify controller %d\n", g_midi_main_control); |
302 | if (g_midi_main_control > 127) { | 304 | if (g_midi_main_control > 127) { |
@@ -304,7 +306,7 @@ config_handle_line(char *line) | |||
304 | return -1; | 306 | return -1; |
305 | } | 307 | } |
306 | break; | 308 | break; |
307 | case KEYWORD_MIDI_MAIN_CHANNEL: | 309 | case KEYWORD_MIDI_MAIN_CHANNEL: |
308 | g_midi_main_channel = atol(line); | 310 | g_midi_main_channel = atol(line); |
309 | printf("All Strings modify controller %d on channel %d\n", g_midi_main_control, g_midi_main_channel); | 311 | printf("All Strings modify controller %d on channel %d\n", g_midi_main_control, g_midi_main_channel); |
310 | if (g_midi_main_channel < 1 || g_midi_main_channel > 16) { | 312 | if (g_midi_main_channel < 1 || g_midi_main_channel > 16) { |
@@ -312,13 +314,13 @@ config_handle_line(char *line) | |||
312 | return -1; | 314 | return -1; |
313 | } | 315 | } |
314 | break; | 316 | break; |
315 | default: | 317 | default: |
316 | fprintf(stderr, "Unhandled config line: %s\n", _line); | 318 | fprintf(stderr, "Unhandled config line: %s\n", _line); |
317 | return -1; | 319 | return -1; |
318 | 320 | ||
319 | } | 321 | } |
320 | if (!split_done) | 322 | if (!split_done) |
321 | return 0; | 323 | return 0; |
322 | 324 | ||
323 | /* split also true for two octaves */ | 325 | /* split also true for two octaves */ |
324 | if (g_midi_three_octave_split_2 < g_midi_three_octave_split_1) { | 326 | if (g_midi_three_octave_split_2 < g_midi_three_octave_split_1) { |