summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c87
1 files changed, 75 insertions, 12 deletions
diff --git a/config.c b/config.c
index 47506d5..fb8a6fa 100644
--- a/config.c
+++ b/config.c
@@ -17,6 +17,31 @@ int g_timetosilence = 30;
17 17
18int g_min_y = 0, g_max_y; 18int g_min_y = 0, g_max_y;
19 19
20static int g_current_string;
21StringConfig
22 g_string_conf[MAX_LINECOUNT];
23int g_string_count;
24
25void
26config_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
20static char *midi_note[] = { 45static 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
59static char *modifier_names[] = {
60 "none", "pitch_bend_up", "pitch_bend_down", "midi_control", "midi_control_inverse"
61};
62
63static char *mode_names[] = {
64 "midi_one_octave", "midi_two_octaves", "midi_three_octaves", "midi_control", "midi_control_inverse"
65};
66
34enum { 67enum {
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
61typedef struct { 96typedef 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
94static int g_current_string;
95StringConfig
96 g_string_conf[MAX_LINECOUNT];
97int g_string_count;
98
99 130
100static int 131static int
101config_findkeyword(char **line) 132config_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
341void 380void
342config_reset() 381config_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
350void 396void
351config_write() 397config_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}