diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 529 |
1 files changed, 284 insertions, 245 deletions
@@ -1,5 +1,4 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <fcntl.h> | ||
3 | #include <stdio.h> | 2 | #include <stdio.h> |
4 | #include <string.h> | 3 | #include <string.h> |
5 | #include <ctype.h> | 4 | #include <ctype.h> |
@@ -32,6 +31,94 @@ static char *midi_note[] = { | |||
32 | "C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9", "G#9", "A9", "A#9", "B9" | 31 | "C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9", "G#9", "A9", "A#9", "B9" |
33 | }; | 32 | }; |
34 | 33 | ||
34 | enum { | ||
35 | KEYWORD_STRINGS, | ||
36 | KEYWORD_STRING, | ||
37 | KEYWORD_LINE, | ||
38 | KEYWORD_MODE, | ||
39 | KEYWORD_MODE_ONE_OCTAVE, | ||
40 | KEYWORD_MODE_TWO_OCTAVES, | ||
41 | KEYWORD_MODE_THREE_OCTAVES, | ||
42 | KEYWORD_MODE_CONTROL, | ||
43 | KEYWORD_MODE_CONTROL_INVERSE, | ||
44 | KEYWORD_CHANNEL, | ||
45 | KEYWORD_NOTE, | ||
46 | KEYWORD_AFTERTOUCH, | ||
47 | KEYWORD_NONE, | ||
48 | KEYWORD_PITCH_BEND_UP, | ||
49 | KEYWORD_PITCH_BEND_DOWN, | ||
50 | KEYWORD_MIDI_CONTROL, | ||
51 | KEYWORD_MIDI_CONTROL_INVERSE, | ||
52 | KEYWORD_CONTROLLER, | ||
53 | KEYWORD_TIMETOSILENCE, | ||
54 | KEYWORD_TWOOCTAVESPLIT, | ||
55 | KEYWORD_THREEOCTAVESPLIT_1, | ||
56 | KEYWORD_THREEOCTAVESPLIT_2, | ||
57 | KEYWORD_MIDI_MAIN_CONTROL, | ||
58 | KEYWORD_MIDI_MAIN_CHANNEL | ||
59 | }; | ||
60 | |||
61 | typedef struct { | ||
62 | int id; | ||
63 | char *name; | ||
64 | } keyword; | ||
65 | |||
66 | static keyword keywords[] = { | ||
67 | { KEYWORD_STRINGS, "Strings" }, | ||
68 | { KEYWORD_STRING, "String" }, | ||
69 | { KEYWORD_LINE, "Line" }, | ||
70 | { KEYWORD_MODE, "Mode" }, | ||
71 | { KEYWORD_MODE_ONE_OCTAVE, "midi_one_octave" }, | ||
72 | { KEYWORD_MODE_TWO_OCTAVES, "midi_two_octaves" }, | ||
73 | { KEYWORD_MODE_THREE_OCTAVES, "midi_three_octaves" }, | ||
74 | { KEYWORD_MODE_CONTROL, "midi_control" }, | ||
75 | { KEYWORD_MODE_CONTROL_INVERSE, "midi_control_inverse" }, | ||
76 | { KEYWORD_CHANNEL, "Channel" }, | ||
77 | { KEYWORD_NOTE, "Note" }, | ||
78 | { KEYWORD_AFTERTOUCH, "AfterTouch" }, | ||
79 | { KEYWORD_NONE, "none" }, | ||
80 | { KEYWORD_PITCH_BEND_UP, "pitch_bend_up" }, | ||
81 | { KEYWORD_PITCH_BEND_DOWN, "pitch_bend_down" }, | ||
82 | { KEYWORD_MIDI_CONTROL, "midi_control" }, | ||
83 | { KEYWORD_MIDI_CONTROL_INVERSE, "midi_control_inverse" }, | ||
84 | { KEYWORD_CONTROLLER, "Controller" }, | ||
85 | { KEYWORD_TIMETOSILENCE, "TimeToSilence" }, | ||
86 | { KEYWORD_TWOOCTAVESPLIT, "midi_two_octave_split" }, | ||
87 | { KEYWORD_THREEOCTAVESPLIT_1, "midi_three_octave_split_1" }, | ||
88 | { KEYWORD_THREEOCTAVESPLIT_2, "midi_three_octave_split_2" }, | ||
89 | { KEYWORD_MIDI_MAIN_CONTROL, "midi_main_control" }, | ||
90 | { KEYWORD_MIDI_MAIN_CHANNEL, "midi_main_channel" }, | ||
91 | { -1, 0 } | ||
92 | }; | ||
93 | |||
94 | static int g_current_string; | ||
95 | |||
96 | static int | ||
97 | config_findkeyword(char **line) | ||
98 | { | ||
99 | char *_l = *line; | ||
100 | int i; | ||
101 | |||
102 | while (isspace(*_l)) | ||
103 | ++_l; | ||
104 | |||
105 | for (i=0; keywords[i].name; ++i) { | ||
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 | |||
112 | /* Skip rest of white spaces */ | ||
113 | while (isspace(*_l)) | ||
114 | ++_l; | ||
115 | *line = _l; | ||
116 | return keywords[i].id; | ||
117 | } | ||
118 | } | ||
119 | return -1; | ||
120 | } | ||
121 | |||
35 | static uint8_t | 122 | static uint8_t |
36 | config_midi_note_from_string(char *string) | 123 | config_midi_note_from_string(char *string) |
37 | { | 124 | { |
@@ -43,263 +130,215 @@ config_midi_note_from_string(char *string) | |||
43 | return 0xff; | 130 | return 0xff; |
44 | } | 131 | } |
45 | 132 | ||
46 | char *config_midi_note_to_string(int string) { | 133 | char * |
134 | config_midi_note_to_string(int string) | ||
135 | { | ||
47 | return midi_note[string]; | 136 | return midi_note[string]; |
48 | } | 137 | } |
49 | 138 | ||
50 | #define LINEBUFFER 512 | 139 | int |
51 | static char *config_file; | 140 | config_handle_line(char *line) |
52 | void | ||
53 | config_parse(char *config_file_in) | ||
54 | { | 141 | { |
55 | FILE *fh; | 142 | StringConfig *sc = g_string_conf + g_current_string; |
56 | char line_in[LINEBUFFER]; | 143 | int split_done = 0; |
57 | int current_string = -1; | 144 | char *_line = line; |
58 | 145 | ||
59 | if (!config_file_in && !config_file) | 146 | //Skip leading spaces |
60 | return; | 147 | while (isspace(*line)) |
61 | if (config_file_in) | 148 | ++line; |
62 | config_file = config_file_in; | 149 | if (*line == 0 || *line == '#' || *line == '\n') |
63 | fh = fopen(config_file, "r"); | 150 | return 0; |
64 | |||
65 | if (!fh) { | ||
66 | fprintf(stderr, "Couldn't open config file %s, exiting.\n", config_file); | ||
67 | exit(1); | ||
68 | } | ||
69 | |||
70 | //Reinitialise string config array | ||
71 | memset(g_string_conf, 0, sizeof(g_string_conf)); | ||
72 | g_max_y = 1024; | ||
73 | 151 | ||
74 | while (!feof(fh)) { | 152 | switch (config_findkeyword(&line)) { |
75 | char *line = fgets(line_in, LINEBUFFER, fh); | 153 | case KEYWORD_STRINGS: |
154 | g_string_count = atol(line); | ||
155 | if (!g_string_count || g_string_count > MAX_LINECOUNT) { | ||
156 | fprintf(stderr, "Incorrect number of strings: %s\n", _line); | ||
157 | return -1; | ||
158 | } | ||
159 | printf("GLOBAL: Configuring expected lines %d\n", g_string_count); | ||
160 | break; | ||
161 | case KEYWORD_STRING: | ||
162 | g_current_string = atol(line) - 1; | ||
163 | printf("Switching to string: %d\n", g_current_string + 1); | ||
164 | if (g_current_string < 0 || g_current_string > g_string_count) { | ||
165 | fprintf(stderr, "Incorrect string selected: %s\n", _line); | ||
166 | return -1; | ||
167 | } | ||
168 | break; | ||
169 | case KEYWORD_LINE: | ||
170 | { | ||
171 | 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; | ||
76 | 183 | ||
77 | if (!line) | 184 | } |
185 | if (l->y0 > g_min_y) | ||
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)) { | ||
193 | case KEYWORD_MODE_ONE_OCTAVE: | ||
194 | sc->mode = midi_one_octave; | ||
195 | printf("String %d is midi_one_octave\n", 1 + g_current_string); | ||
78 | break; | 196 | break; |
197 | case KEYWORD_MODE_TWO_OCTAVES: | ||
198 | sc->mode = midi_two_octaves; | ||
199 | printf("String %d is midi_two_octaves\n", 1 + g_current_string); | ||
200 | break; | ||
201 | case KEYWORD_MODE_THREE_OCTAVES: | ||
202 | sc->mode = midi_three_octaves; | ||
203 | printf("String %d is midi_three_octaves\n", 1 + g_current_string); | ||
204 | break; | ||
205 | case KEYWORD_MODE_CONTROL: | ||
206 | sc->mode = midi_control; | ||
207 | printf("String %d is midi_control\n", 1 + g_current_string); | ||
208 | break; | ||
209 | case KEYWORD_MODE_CONTROL_INVERSE: | ||
210 | sc->mode = midi_control_inv; | ||
211 | printf("String %d is midi_control_inverse\n", 1 + g_current_string); | ||
212 | break; | ||
213 | default: | ||
214 | fprintf(stderr, "Illegal Mode for string: %s\n", _line); | ||
215 | return -1; | ||
79 | 216 | ||
80 | //Skip leading spaces | 217 | } |
81 | while (isspace(*line)) | 218 | break; |
82 | ++line; | 219 | case KEYWORD_CHANNEL: |
83 | if (*line == 0 || *line == '#' || *line == '\n') | 220 | sc->channel = atol(line); |
84 | continue; | 221 | if (sc->channel > 16) { |
85 | 222 | fprintf(stderr, "Incorrect channel specified: %s.\n", _line); | |
86 | if (!strncasecmp(line, "Strings", 7) && isspace(line[7])) { | 223 | return -1; |
87 | line += 7; | 224 | } |
88 | while (isspace(*line)) | 225 | printf("String %d is on channel %d\n", g_current_string, sc->channel); |
89 | ++line; | 226 | break; |
90 | g_string_count = atol(line); | 227 | case KEYWORD_NOTE: |
91 | if (!g_string_count || g_string_count > MAX_LINECOUNT) { | 228 | sc->note = config_midi_note_from_string(line); |
92 | fprintf(stderr, "Incorrect number of strings: %s\n", line); | 229 | if (sc->note == 0xff) { |
93 | exit(1); | 230 | fprintf(stderr, "Unknown midi note specified: %s.\n", _line); |
94 | } | 231 | return -1; |
95 | printf("GLOBAL: Configuring expected lines %d\n", g_string_count); | 232 | } |
96 | } else if (!strncasecmp(line, "String", 6) && isspace(line[6])) { | 233 | printf("String %d is midi note %d\n", g_current_string, sc->note); |
97 | line += 6; | 234 | break; |
98 | while (isspace(*line)) | 235 | case KEYWORD_AFTERTOUCH: |
99 | ++line; | 236 | switch (config_findkeyword(&line)) { |
100 | current_string = atol(line); | 237 | case KEYWORD_NONE: |
101 | printf("Switching to string: %d\n", current_string); | 238 | sc->modifier = none; |
102 | if (current_string < 0 || current_string > g_string_count) { | 239 | printf("String %d does not act aftertouch\n", 1 + g_current_string); |
103 | fprintf(stderr, "Incorrect string selected: %s\n", line); | 240 | break; |
104 | exit(1); | 241 | case KEYWORD_PITCH_BEND_UP: |
105 | } | 242 | sc->modifier = pitch_bend_up; |
106 | } else if (!strncasecmp(line, "Line", 4) && isspace(line[4])) { | 243 | printf("String %d acts aftertouch as pitch_bend_up\n", 1 + g_current_string); |
107 | LLine *l = &g_string_conf[current_string - 1].line; | 244 | break; |
108 | 245 | case KEYWORD_PITCH_BEND_DOWN: | |
109 | if (current_string == -1) { | 246 | sc->modifier = pitch_bend_down; |
110 | fprintf(stderr, "No string selected yet.\n"); | 247 | printf("String %d acts aftertouch as pitch_bend_down\n", 1 + g_current_string); |
111 | exit(1); | 248 | break; |
112 | } | 249 | case KEYWORD_MIDI_CONTROL: |
113 | line += 4; | 250 | sc->modifier = midi_controller; |
114 | while (isspace(*line)) | 251 | printf("String %d acts aftertouch as midi_controller\n", 1 + g_current_string); |
115 | ++line; | 252 | break; |
116 | if (sscanf(line, "%d %d %d %d", &l->x0, &l->y0, &l->x1, &l->y1) != 4) { | 253 | case KEYWORD_MIDI_CONTROL_INVERSE: |
117 | fprintf(stderr, "Incorrect Line statement for string\n"); | 254 | sc->modifier = midi_controller_inv; |
118 | exit(1); | 255 | printf("String %d acts aftertouch as midi_controller_inverse\n", 1 + g_current_string); |
119 | } | 256 | break; |
120 | if (l->y0 > l->y1) { | 257 | default: |
121 | l->y0 ^= l->y1; | 258 | fprintf(stderr, "Illegal Modifier for string: %s\n", _line); |
122 | l->y1 ^= l->y0; | 259 | return -1; |
123 | l->y0 ^= l->y1; | 260 | } |
124 | l->x0 ^= l->x1; | 261 | break; |
125 | l->x1 ^= l->x0; | 262 | case KEYWORD_CONTROLLER: |
126 | l->x0 ^= l->x1; | 263 | sc->controller = atol(line); |
127 | 264 | printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); | |
128 | } | 265 | break; |
129 | if (l->y0 > g_min_y) | 266 | case KEYWORD_TIMETOSILENCE: |
130 | g_min_y = l->y0; | 267 | sc->timetosilence = atol(line); |
131 | if (l->y1 < g_max_y) | 268 | printf("String %d has a timetosilence of %d\n", 1 + g_current_string, sc->timetosilence); |
132 | g_max_y = l->y1; | 269 | break; |
133 | } else if (!strncasecmp(line, "Mode", 4) && isspace(line[4])) { | 270 | case KEYWORD_TWOOCTAVESPLIT: |
134 | if (current_string == -1) { | 271 | g_midi_two_octave_split = atol(line); |
135 | fprintf(stderr, "No string selected yet.\n"); | 272 | printf("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split); |
136 | exit(1); | 273 | if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) { |
137 | } | 274 | fprintf(stderr, "Invalid percentage in line: %s\n", _line); |
138 | line += 4; | ||
139 | while (isspace(*line)) | ||
140 | ++line; | ||
141 | if (!strncasecmp(line, "midi_one_octave", 15) && (!line[15] || isspace(line[15]))) { | ||
142 | g_string_conf[current_string - 1].mode = midi_one_octave; | ||
143 | printf("String %d is midi_one_octave\n", current_string); | ||
144 | } else if (!strncasecmp(line, "midi_two_octaves", 16) && (!line[16] || isspace(line[16]))) { | ||
145 | g_string_conf[current_string - 1].mode = midi_two_octaves; | ||
146 | printf("String %d is midi_two_octaves\n", current_string); | ||
147 | } else if (!strncasecmp(line, "midi_three_octaves", 18) && (!line[18] || isspace(line[18]))) { | ||
148 | g_string_conf[current_string - 1].mode = midi_three_octaves; | ||
149 | printf("String %d is midi_three_octaves\n", current_string); | ||
150 | } else if (!strncasecmp(line, "midi_control", 12) && (!line[12] || isspace(line[12]))) { | ||
151 | g_string_conf[current_string - 1].mode = midi_control; | ||
152 | printf("String %d is midi_control\n", current_string); | ||
153 | } else if (!strncasecmp(line, "midi_control_inverse", 20) && (!line[20] || isspace(line[20]))) { | ||
154 | g_string_conf[current_string - 1].mode = midi_control_inv; | ||
155 | printf("String %d is midi_control_inverse\n", current_string); | ||
156 | } else { | ||
157 | fprintf(stderr, "Illegal Mode for string: %s\n", line); | ||
158 | exit(1); | ||
159 | } | ||
160 | } else if (!strncasecmp(line, "Channel", 7) && isspace(line[7])) { | ||
161 | if (current_string == -1) { | ||
162 | fprintf(stderr, "No string selected yet.\n"); | ||
163 | exit(1); | ||
164 | } | ||
165 | line += 7; | ||
166 | while (isspace(*line)) | ||
167 | ++line; | ||
168 | g_string_conf[current_string - 1].channel = atol(line); | ||
169 | if (g_string_conf[current_string - 1].channel > 16) { | ||
170 | fprintf(stderr, "Incorrect channel specified: %s.\n", line); | ||
171 | exit(1); | ||
172 | } | ||
173 | printf("String %d is on channel %d\n", current_string, g_string_conf[current_string - 1].channel); | ||
174 | } else if (!strncasecmp(line, "Note", 4) && isspace(line[4])) { | ||
175 | if (current_string == -1) { | ||
176 | fprintf(stderr, "No string selected yet.\n"); | ||
177 | exit(1); | ||
178 | } | ||
179 | line += 4; | ||
180 | while (isspace(*line)) | ||
181 | ++line; | ||
182 | g_string_conf[current_string - 1].note = config_midi_note_from_string(line); | ||
183 | if (g_string_conf[current_string - 1].note == 0xff) { | ||
184 | fprintf(stderr, "Unknown midi note specified: %s.\n", line); | ||
185 | exit(1); | ||
186 | } | ||
187 | printf("String %d is midi note %d\n", current_string, g_string_conf[current_string - 1].note); | ||
188 | } else if (!strncasecmp(line, "AfterTouch", 10) && isspace(line[10])) { | ||
189 | if (current_string == -1) { | ||
190 | fprintf(stderr, "No string selected yet.\n"); | ||
191 | exit(1); | ||
192 | } | ||
193 | line += 10; | ||
194 | while (isspace(*line)) | ||
195 | ++line; | ||
196 | if (!strncasecmp(line, "none", 4) && (!line[4] || isspace(line[4]))) { | ||
197 | g_string_conf[current_string - 1].modifier = none; | ||
198 | printf("String %d does not act aftertouch\n", current_string); | ||
199 | } else if (!strncasecmp(line, "pitch_bend_up", 13) && (!line[13] || isspace(line[13]))) { | ||
200 | g_string_conf[current_string - 1].modifier = pitch_bend_up; | ||
201 | printf("String %d acts aftertouch as pitch_bend_up\n", current_string); | ||
202 | } else if (!strncasecmp(line, "pitch_bend_down", 15) && (!line[15] || isspace(line[15]))) { | ||
203 | g_string_conf[current_string - 1].modifier = pitch_bend_down; | ||
204 | printf("String %d acts aftertouch as pitch_bend_down\n", current_string); | ||
205 | } else if (!strncasecmp(line, "midi_control", 12) && (!line[12] || isspace(line[12]))) { | ||
206 | g_string_conf[current_string - 1].modifier = midi_controller; | ||
207 | printf("String %d acts aftertouch as midi_controller\n", current_string); | ||
208 | } else if (!strncasecmp(line, "midi_control_inverse", 20) && (!line[20] || isspace(line[20]))) { | ||
209 | g_string_conf[current_string - 1].modifier = midi_controller_inv; | ||
210 | printf("String %d acts aftertouch as midi_controller_inverse\n", current_string); | ||
211 | } else { | ||
212 | fprintf(stderr, "Illegal Modifier for string: %s\n", line); | ||
213 | exit(1); | ||
214 | } | ||
215 | } else if (!strncasecmp(line, "Controller", 10) && isspace(line[10])) { | ||
216 | if (current_string == -1) { | ||
217 | fprintf(stderr, "No string selected yet.\n"); | ||
218 | exit(1); | ||
219 | } | ||
220 | line += 10; | ||
221 | while (isspace(*line)) | ||
222 | ++line; | ||
223 | g_string_conf[current_string - 1].controller = atol(line); | ||
224 | printf("String %d is on midi_controller line %d\n", current_string, g_string_conf[current_string - 1].controller); | ||
225 | } else if (!strncasecmp(line, "TimeToSilence", 13) && isspace(line[13])) { | ||
226 | if (current_string == -1) { | ||
227 | fprintf(stderr, "No string selected yet.\n"); | ||
228 | exit(1); | ||
229 | } | ||
230 | line += 13; | ||
231 | while (isspace(*line)) | ||
232 | ++line; | ||
233 | g_string_conf[current_string - 1].timetosilence = atol(line); | ||
234 | printf("String %d has a timetosilence of %d\n", current_string, g_string_conf[current_string - 1].timetosilence); | ||
235 | } else if (!strncasecmp(line, "midi_two_octave_split", 21) && isspace(line[21])) { | ||
236 | line += 21; | ||
237 | while (isspace(*line)) | ||
238 | ++line; | ||
239 | g_midi_two_octave_split = atol(line); | ||
240 | printf("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split); | ||
241 | if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) { | ||
242 | fprintf(stderr, "Invalid percentage in line: %s\n", line); | ||
243 | exit(1); | ||
244 | } | ||
245 | g_midi_two_octave_split = (256 * g_midi_two_octave_split) / 100; | ||
246 | } else if (!strncasecmp(line, "midi_three_octave_split_1", 25) && isspace(line[25])) { | ||
247 | line += 25; | ||
248 | while (isspace(*line)) | ||
249 | ++line; | ||
250 | g_midi_three_octave_split_1 = atol(line); | ||
251 | printf("Splitting THREE octaves top above %d%%\n", g_midi_three_octave_split_1); | ||
252 | if (g_midi_three_octave_split_1 < 0 || g_midi_three_octave_split_1 > 100) { | ||
253 | fprintf(stderr, "Invalid percentage in line: %s\n", line); | ||
254 | exit(1); | ||
255 | } | ||
256 | g_midi_three_octave_split_1 = (256 * g_midi_three_octave_split_1) / 100; | ||
257 | } else if (!strncasecmp(line, "midi_three_octave_split_2", 25) && isspace(line[25])) { | ||
258 | line += 25; | ||
259 | while (isspace(*line)) | ||
260 | ++line; | ||
261 | g_midi_three_octave_split_2 = atol(line); | ||
262 | printf("Splitting THREE octaves bottom below %d%%\n", g_midi_three_octave_split_2); | ||
263 | if (g_midi_three_octave_split_2 < 0 || g_midi_three_octave_split_2 > 100) { | ||
264 | fprintf(stderr, "Invalid percentage in line: %s\n", line); | ||
265 | exit(1); | ||
266 | } | ||
267 | g_midi_three_octave_split_2 = (256 * g_midi_three_octave_split_2) / 100; | ||
268 | } else if (!strncasecmp(line, "midi_main_control", 17) && isspace(line[17])) { | ||
269 | line += 17; | ||
270 | while (isspace(*line)) | ||
271 | ++line; | ||
272 | g_midi_main_control = atol(line); | ||
273 | printf("All Strings modify controller %d\n", g_midi_main_control); | ||
274 | if (g_midi_main_control > 127) { | ||
275 | fprintf(stderr, "Invalid controller number %d in line: %s\n", g_midi_main_control, line); | ||
276 | exit(1); | ||
277 | } | ||
278 | } else if (!strncasecmp(line, "midi_main_channel", 17) && isspace(line[17])) { | ||
279 | line += 17; | ||
280 | while (isspace(*line)) | ||
281 | ++line; | ||
282 | g_midi_main_channel = atol(line); | ||
283 | printf("All Strings modify controller %d on channel %d\n", g_midi_main_control, g_midi_main_channel); | ||
284 | if (g_midi_main_channel < 1 || g_midi_main_channel > 16) { | ||
285 | fprintf(stderr, "Invalid channel number %d in line: %s\n", g_midi_main_channel, line); | ||
286 | exit(1); | ||
287 | } | ||
288 | } else { | ||
289 | fprintf(stderr, "Unhandled config line: %s\n", line); | ||
290 | exit(1); | 275 | exit(1); |
291 | } | 276 | } |
277 | g_midi_two_octave_split = (256 * g_midi_two_octave_split) / 100; | ||
278 | break; | ||
279 | case KEYWORD_THREEOCTAVESPLIT_1: | ||
280 | g_midi_three_octave_split_1 = atol(line); | ||
281 | 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) { | ||
283 | fprintf(stderr, "Invalid percentage in line: %s\n", _line); | ||
284 | exit(1); | ||
285 | } | ||
286 | g_midi_three_octave_split_1 = (256 * g_midi_three_octave_split_1) / 100; | ||
287 | split_done = 1; | ||
288 | break; | ||
289 | case KEYWORD_THREEOCTAVESPLIT_2: | ||
290 | g_midi_three_octave_split_2 = atol(line); | ||
291 | 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) { | ||
293 | fprintf(stderr, "Invalid percentage in line: %s\n", _line); | ||
294 | return -1; | ||
295 | } | ||
296 | g_midi_three_octave_split_2 = (256 * g_midi_three_octave_split_2) / 100; | ||
297 | split_done = 1; | ||
298 | break; | ||
299 | case KEYWORD_MIDI_MAIN_CONTROL: | ||
300 | g_midi_main_control = atol(line); | ||
301 | printf("All Strings modify controller %d\n", g_midi_main_control); | ||
302 | if (g_midi_main_control > 127) { | ||
303 | fprintf(stderr, "Invalid controller number %d in line: %s\n", g_midi_main_control, _line); | ||
304 | return -1; | ||
305 | } | ||
306 | break; | ||
307 | case KEYWORD_MIDI_MAIN_CHANNEL: | ||
308 | 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); | ||
310 | if (g_midi_main_channel < 1 || g_midi_main_channel > 16) { | ||
311 | fprintf(stderr, "Invalid channel number %d in line: %s\n", g_midi_main_channel, _line); | ||
312 | return -1; | ||
313 | } | ||
314 | break; | ||
315 | default: | ||
316 | fprintf(stderr, "Unhandled config line: %s\n", _line); | ||
317 | return -1; | ||
292 | 318 | ||
293 | // split also true for two octaves | ||
294 | if (g_midi_three_octave_split_2 < g_midi_three_octave_split_1) { | ||
295 | g_midi_three_octave_split_inverse = g_midi_three_octave_split_1; | ||
296 | g_midi_three_octave_split_1 = g_midi_three_octave_split_2; | ||
297 | g_midi_three_octave_split_2 = g_midi_three_octave_split_inverse; | ||
298 | g_midi_three_octave_split_inverse = 1; | ||
299 | } else | ||
300 | g_midi_three_octave_split_inverse = 0; | ||
301 | } | 319 | } |
302 | fclose(fh); | 320 | if (!split_done) |
321 | return 0; | ||
322 | |||
323 | /* split also true for two octaves */ | ||
324 | if (g_midi_three_octave_split_2 < g_midi_three_octave_split_1) { | ||
325 | g_midi_three_octave_split_inverse = g_midi_three_octave_split_1; | ||
326 | g_midi_three_octave_split_1 = g_midi_three_octave_split_2; | ||
327 | g_midi_three_octave_split_2 = g_midi_three_octave_split_inverse; | ||
328 | g_midi_three_octave_split_inverse = 1; | ||
329 | } else | ||
330 | g_midi_three_octave_split_inverse = 0; | ||
331 | |||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | void | ||
336 | config_reset() | ||
337 | { | ||
338 | //Reinitialise string config array | ||
339 | memset(g_string_conf, 0, sizeof(g_string_conf)); | ||
340 | g_current_string = 0; | ||
341 | g_max_y = 1024; | ||
303 | } | 342 | } |
304 | 343 | ||
305 | void | 344 | void |