diff options
author | erdgeist <erdgeist@bauklotz.lan> | 2017-03-30 00:50:03 +0200 |
---|---|---|
committer | erdgeist <erdgeist@bauklotz.lan> | 2017-03-30 00:50:03 +0200 |
commit | 302e4b9e7e0dd5a2e5c3f087ef5688c046ec3b21 (patch) | |
tree | c1d29b02653da61e6c5d1ddf3b91ef75560cb023 | |
parent | 3c8653b300255e514839025f710ea8eaca28e626 (diff) |
Add config dumper
-rw-r--r-- | config.c | 87 | ||||
-rw-r--r-- | config.h | 2 |
2 files changed, 77 insertions, 12 deletions
@@ -17,6 +17,31 @@ int g_timetosilence = 30; | |||
17 | 17 | ||
18 | int g_min_y = 0, g_max_y; | 18 | int g_min_y = 0, g_max_y; |
19 | 19 | ||
20 | static int g_current_string; | ||
21 | StringConfig | ||
22 | g_string_conf[MAX_LINECOUNT]; | ||
23 | int g_string_count; | ||
24 | |||
25 | void | ||
26 | config_reset() | ||
27 | { | ||
28 | //Reinitialise string config array | ||
29 | memset(g_string_conf, 0, sizeof(g_string_conf)); | ||
30 | g_min_y = 0; | ||
31 | g_max_y = 1024; | ||
32 | g_current_string = 0; | ||
33 | |||
34 | g_midi_main_control = -1; | ||
35 | g_midi_main_channel = 0; | ||
36 | g_midi_two_octave_split = 256 / 2; | ||
37 | g_midi_three_octave_split_1 = 256 / 3; | ||
38 | g_midi_three_octave_split_2 = 512 / 3; | ||
39 | g_midi_three_octave_split_inverse = 0; | ||
40 | g_settled_dist = 5; | ||
41 | g_timetosilence = 30; | ||
42 | } | ||
43 | |||
44 | |||
20 | static char *midi_note[] = { | 45 | static char *midi_note[] = { |
21 | "C-1", "C#-1", "D-1", "D#-1", "E-1", "F-1", "F#-1", "G-1", "G#-1", "A-1", "A#-1", "B-1", | 46 | "C-1", "C#-1", "D-1", "D#-1", "E-1", "F-1", "F#-1", "G-1", "G#-1", "A-1", "A#-1", "B-1", |
22 | "C0", "C#0", "D0", "D#0", "E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0", | 47 | "C0", "C#0", "D0", "D#0", "E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0", |
@@ -31,6 +56,14 @@ static char *midi_note[] = { | |||
31 | "C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9", "G#9", "A9", "A#9", "B9" | 56 | "C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9", "G#9", "A9", "A#9", "B9" |
32 | }; | 57 | }; |
33 | 58 | ||
59 | static char *modifier_names[] = { | ||
60 | "none", "pitch_bend_up", "pitch_bend_down", "midi_control", "midi_control_inverse" | ||
61 | }; | ||
62 | |||
63 | static char *mode_names[] = { | ||
64 | "midi_one_octave", "midi_two_octaves", "midi_three_octaves", "midi_control", "midi_control_inverse" | ||
65 | }; | ||
66 | |||
34 | enum { | 67 | enum { |
35 | KEYWORD_STRINGS, | 68 | KEYWORD_STRINGS, |
36 | KEYWORD_STRING, | 69 | KEYWORD_STRING, |
@@ -51,11 +84,13 @@ enum { | |||
51 | KEYWORD_MIDI_CONTROL_INVERSE, | 84 | KEYWORD_MIDI_CONTROL_INVERSE, |
52 | KEYWORD_CONTROLLER, | 85 | KEYWORD_CONTROLLER, |
53 | KEYWORD_TIMETOSILENCE, | 86 | KEYWORD_TIMETOSILENCE, |
87 | KEYWORD_PITCHFACTOR, | ||
54 | KEYWORD_TWOOCTAVESPLIT, | 88 | KEYWORD_TWOOCTAVESPLIT, |
55 | KEYWORD_THREEOCTAVESPLIT_1, | 89 | KEYWORD_THREEOCTAVESPLIT_1, |
56 | KEYWORD_THREEOCTAVESPLIT_2, | 90 | KEYWORD_THREEOCTAVESPLIT_2, |
57 | KEYWORD_MIDI_MAIN_CONTROL, | 91 | KEYWORD_MIDI_MAIN_CONTROL, |
58 | KEYWORD_MIDI_MAIN_CHANNEL | 92 | KEYWORD_MIDI_MAIN_CHANNEL, |
93 | KEYWORD_SETTLED_DIST | ||
59 | }; | 94 | }; |
60 | 95 | ||
61 | typedef struct { | 96 | typedef struct { |
@@ -83,6 +118,7 @@ static keyword keywords[] = { | |||
83 | {KEYWORD_MIDI_CONTROL_INVERSE, "midi_control_inverse"}, | 118 | {KEYWORD_MIDI_CONTROL_INVERSE, "midi_control_inverse"}, |
84 | {KEYWORD_CONTROLLER, "Controller"}, | 119 | {KEYWORD_CONTROLLER, "Controller"}, |
85 | {KEYWORD_TIMETOSILENCE, "TimeToSilence"}, | 120 | {KEYWORD_TIMETOSILENCE, "TimeToSilence"}, |
121 | {KEYWORD_PITCHFACTOR, "PitchFactor"}, | ||
86 | {KEYWORD_TWOOCTAVESPLIT, "midi_two_octave_split"}, | 122 | {KEYWORD_TWOOCTAVESPLIT, "midi_two_octave_split"}, |
87 | {KEYWORD_THREEOCTAVESPLIT_1, "midi_three_octave_split_1"}, | 123 | {KEYWORD_THREEOCTAVESPLIT_1, "midi_three_octave_split_1"}, |
88 | {KEYWORD_THREEOCTAVESPLIT_2, "midi_three_octave_split_2"}, | 124 | {KEYWORD_THREEOCTAVESPLIT_2, "midi_three_octave_split_2"}, |
@@ -91,11 +127,6 @@ static keyword keywords[] = { | |||
91 | {-1, 0} | 127 | {-1, 0} |
92 | }; | 128 | }; |
93 | 129 | ||
94 | static int g_current_string; | ||
95 | StringConfig | ||
96 | g_string_conf[MAX_LINECOUNT]; | ||
97 | int g_string_count; | ||
98 | |||
99 | 130 | ||
100 | static int | 131 | static int |
101 | config_findkeyword(char **line) | 132 | config_findkeyword(char **line) |
@@ -265,6 +296,10 @@ config_handle_line(char *line) | |||
265 | return -1; | 296 | return -1; |
266 | } | 297 | } |
267 | break; | 298 | break; |
299 | case KEYWORD_PITCHFACTOR: | ||
300 | sc->pitch_factor = atol(line); | ||
301 | printf("String %d is given a custom pitch factor of %d\n", 1 + g_current_string, sc->pitch_factor); | ||
302 | break; | ||
268 | case KEYWORD_CONTROLLER: | 303 | case KEYWORD_CONTROLLER: |
269 | sc->controller = atol(line); | 304 | sc->controller = atol(line); |
270 | printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); | 305 | printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); |
@@ -318,6 +353,10 @@ config_handle_line(char *line) | |||
318 | return -1; | 353 | return -1; |
319 | } | 354 | } |
320 | break; | 355 | break; |
356 | case KEYWORD_SETTLED_DIST: | ||
357 | g_settled_dist = atol(line); | ||
358 | printf("All AfterTouch events take place only after movement has slown down to %d points\n", g_settled_dist); | ||
359 | break; | ||
321 | default: | 360 | default: |
322 | fprintf(stderr, "Unhandled config line: %s\n", _line); | 361 | fprintf(stderr, "Unhandled config line: %s\n", _line); |
323 | return -1; | 362 | return -1; |
@@ -339,16 +378,40 @@ config_handle_line(char *line) | |||
339 | } | 378 | } |
340 | 379 | ||
341 | void | 380 | void |
342 | config_reset() | 381 | config_dumpglobals(char *out, size_t outsize) |
343 | { | 382 | { |
344 | //Reinitialise string config array | 383 | int tos1 = g_midi_three_octave_split_inverse ? g_midi_three_octave_split_2 : g_midi_three_octave_split_1; |
345 | memset(g_string_conf, 0, sizeof(g_string_conf)); | 384 | int tos2 = g_midi_three_octave_split_inverse ? g_midi_three_octave_split_1 : g_midi_three_octave_split_2; |
346 | g_current_string = 0; | 385 | |
347 | g_max_y = 1024; | 386 | size_t off = snprintf(out, outsize, |
387 | "Strings %d\n\nmidi_two_octave_split %d\nmidi_three_octave_split_1 %d\nmidi_three_octave_split_2 %d\nmidi_main_control %d\nmidi_main_channel %d\n", | ||
388 | g_string_count, g_midi_two_octave_split, tos1, tos2, g_midi_main_control, g_midi_main_channel ); | ||
389 | |||
390 | if (g_settled_dist != 5) | ||
391 | off += snprintf(out + off, outsize - off, | ||
392 | "SettledDist %d\n\n", g_settled_dist); | ||
393 | snprintf(out + off, outsize - off, "\n" ); | ||
348 | } | 394 | } |
349 | 395 | ||
350 | void | 396 | void |
351 | config_write() | 397 | config_dumpstring(int string, char *out, size_t outsize) |
352 | { | 398 | { |
399 | StringConfig *s = g_string_conf + string; | ||
400 | |||
401 | if (string < 0 || string > g_string_count || !out) { | ||
402 | if (out && outsize) *out = 0; | ||
403 | return; | ||
404 | } | ||
405 | size_t off = snprintf(out, outsize, | ||
406 | "String %d\n Line %d %d %d %d\n Mode %s\n Channel %d\n Note %s\n AfterTouch %s\n Controller %d\n", | ||
407 | string + 1, s->line.x0, s->line.y0, s->line.x1, s->line.y1, | ||
408 | mode_names[s->mode], s->channel, midi_note[s->note], modifier_names[s->modifier], s->controller ); | ||
353 | 409 | ||
410 | if (s->timetosilence) | ||
411 | off += snprintf(out + off, outsize - off, | ||
412 | " TimeToSilence %d\n", s->timetosilence); | ||
413 | if (s->pitch_factor) | ||
414 | off += snprintf(out + off, outsize - off, | ||
415 | " PitchFactor %d\n", s->pitch_factor); | ||
416 | snprintf(out + off, outsize - off, "\n" ); | ||
354 | } | 417 | } |
@@ -70,4 +70,6 @@ extern StringConfig g_string_conf[MAX_LINECOUNT]; | |||
70 | extern int g_string_count; | 70 | extern int g_string_count; |
71 | void config_reset(); | 71 | void config_reset(); |
72 | int config_handle_line( char *line); | 72 | int config_handle_line( char *line); |
73 | void config_dumpglobals(char *out, size_t outsize); | ||
74 | void config_dumpstring(int string, char *out, size_t outsize); | ||
73 | char *config_midi_note_to_string(int string); | 75 | char *config_midi_note_to_string(int string); |