summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@bauklotz.fritz.box>2018-04-02 01:37:40 +0200
committererdgeist <erdgeist@bauklotz.fritz.box>2018-04-02 01:37:40 +0200
commitfa0cb86eec43978054f9db295a77449d6b83ba43 (patch)
tree1d9cc1b5d7dcf9d3a1ecc1d9e10e7cab1466f6a8
parentc12537f51ecd538f74efe568e9965bb79a68ddd2 (diff)
Too many changes
-rw-r--r--config.c88
-rw-r--r--config.h10
2 files changed, 60 insertions, 38 deletions
diff --git a/config.c b/config.c
index e373727..6b00e5b 100644
--- a/config.c
+++ b/config.c
@@ -22,6 +22,10 @@ StringConfig
22 g_string_conf[MAX_LINECOUNT]; 22 g_string_conf[MAX_LINECOUNT];
23int g_string_count; 23int g_string_count;
24 24
25ConfigSource g_config_source = source_none;
26int g_importing_config;
27int g_calibration_running = 0;
28
25void 29void
26config_reset() 30config_reset()
27{ 31{
@@ -191,16 +195,16 @@ config_handle_line(char *line)
191 case KEYWORD_STRINGS: 195 case KEYWORD_STRINGS:
192 g_string_count = atol(line); 196 g_string_count = atol(line);
193 if (!g_string_count || g_string_count > MAX_LINECOUNT) { 197 if (!g_string_count || g_string_count > MAX_LINECOUNT) {
194 fprintf(stderr, "Incorrect number of strings: %s\n", _line); 198 harfe_error(stderr, "Incorrect number of strings: %s\n", _line);
195 return -1; 199 return -1;
196 } 200 }
197 printf("GLOBAL: Configuring expected lines %d\n", g_string_count); 201 harfe_debug("GLOBAL: Configuring expected lines %d\n", g_string_count);
198 break; 202 break;
199 case KEYWORD_STRING: 203 case KEYWORD_STRING:
200 g_current_string = atol(line) - 1; 204 g_current_string = atol(line) - 1;
201 printf("Switching to string: %d\n", g_current_string + 1); 205 harfe_debug("Switching to string: %d\n", g_current_string + 1);
202 if (g_current_string < 0 || g_current_string > g_string_count) { 206 if (g_current_string < 0 || g_current_string > g_string_count) {
203 fprintf(stderr, "Incorrect string selected: %s\n", _line); 207 harfe_error(stderr, "Incorrect string selected: %s\n", _line);
204 return -1; 208 return -1;
205 } 209 }
206 break; 210 break;
@@ -209,7 +213,7 @@ config_handle_line(char *line)
209 LLine *l = &sc->line; 213 LLine *l = &sc->line;
210 214
211 if (sscanf(line, "%d %d %d %d", &l->p0.x, &l->p0.y, &l->p1.x, &l->p1.y) != 4) { 215 if (sscanf(line, "%d %d %d %d", &l->p0.x, &l->p0.y, &l->p1.x, &l->p1.y) != 4) {
212 fprintf(stderr, "Incorrect Line statement for string\n"); 216 harfe_error(stderr, "Incorrect Line statement for string\n");
213 return -1; 217 return -1;
214 } 218 }
215 if (l->p0.y > l->p1.y) { 219 if (l->p0.y > l->p1.y) {
@@ -227,26 +231,26 @@ config_handle_line(char *line)
227 switch (config_findkeyword(&line)) { 231 switch (config_findkeyword(&line)) {
228 case KEYWORD_MODE_ONE_OCTAVE: 232 case KEYWORD_MODE_ONE_OCTAVE:
229 sc->mode = midi_one_octave; 233 sc->mode = midi_one_octave;
230 printf("String %d is midi_one_octave\n", 1 + g_current_string); 234 harfe_debug("String %d is midi_one_octave\n", 1 + g_current_string);
231 break; 235 break;
232 case KEYWORD_MODE_TWO_OCTAVES: 236 case KEYWORD_MODE_TWO_OCTAVES:
233 sc->mode = midi_two_octaves; 237 sc->mode = midi_two_octaves;
234 printf("String %d is midi_two_octaves\n", 1 + g_current_string); 238 harfe_debug("String %d is midi_two_octaves\n", 1 + g_current_string);
235 break; 239 break;
236 case KEYWORD_MODE_THREE_OCTAVES: 240 case KEYWORD_MODE_THREE_OCTAVES:
237 sc->mode = midi_three_octaves; 241 sc->mode = midi_three_octaves;
238 printf("String %d is midi_three_octaves\n", 1 + g_current_string); 242 harfe_debug("String %d is midi_three_octaves\n", 1 + g_current_string);
239 break; 243 break;
240 case KEYWORD_MODE_CONTROL: 244 case KEYWORD_MODE_CONTROL:
241 sc->mode = midi_control; 245 sc->mode = midi_control;
242 printf("String %d is midi_control\n", 1 + g_current_string); 246 harfe_debug("String %d is midi_control\n", 1 + g_current_string);
243 break; 247 break;
244 case KEYWORD_MODE_CONTROL_INVERSE: 248 case KEYWORD_MODE_CONTROL_INVERSE:
245 sc->mode = midi_control_inv; 249 sc->mode = midi_control_inv;
246 printf("String %d is midi_control_inverse\n", 1 + g_current_string); 250 harfe_debug("String %d is midi_control_inverse\n", 1 + g_current_string);
247 break; 251 break;
248 default: 252 default:
249 fprintf(stderr, "Illegal Mode for string: %s\n", _line); 253 harfe_error(stderr, "Illegal Mode for string: %s\n", _line);
250 return -1; 254 return -1;
251 255
252 } 256 }
@@ -254,106 +258,106 @@ config_handle_line(char *line)
254 case KEYWORD_CHANNEL: 258 case KEYWORD_CHANNEL:
255 sc->channel = atol(line); 259 sc->channel = atol(line);
256 if (sc->channel > 16) { 260 if (sc->channel > 16) {
257 fprintf(stderr, "Incorrect channel specified: %s.\n", _line); 261 harfe_error(stderr, "Incorrect channel specified: %s.\n", _line);
258 return -1; 262 return -1;
259 } 263 }
260 printf("String %d is on channel %d\n", 1 + g_current_string, sc->channel); 264 harfe_debug("String %d is on channel %d\n", 1 + g_current_string, sc->channel);
261 break; 265 break;
262 case KEYWORD_NOTE: 266 case KEYWORD_NOTE:
263 sc->note = config_midi_note_from_string(line); 267 sc->note = config_midi_note_from_string(line);
264 if (sc->note == 0xff) { 268 if (sc->note == 0xff) {
265 fprintf(stderr, "Unknown midi note specified: %s.\n", _line); 269 harfe_error(stderr, "Unknown midi note specified: %s.\n", _line);
266 return -1; 270 return -1;
267 } 271 }
268 printf("String %d is midi note %d\n", 1 + g_current_string, sc->note); 272 harfe_debug("String %d is midi note %d\n", 1 + g_current_string, sc->note);
269 break; 273 break;
270 case KEYWORD_AFTERTOUCH: 274 case KEYWORD_AFTERTOUCH:
271 switch (config_findkeyword(&line)) { 275 switch (config_findkeyword(&line)) {
272 case KEYWORD_NONE: 276 case KEYWORD_NONE:
273 sc->modifier = none; 277 sc->modifier = none;
274 printf("String %d does not act aftertouch\n", 1 + g_current_string); 278 harfe_debug("String %d does not act aftertouch\n", 1 + g_current_string);
275 break; 279 break;
276 case KEYWORD_PITCH_BEND_UP: 280 case KEYWORD_PITCH_BEND_UP:
277 sc->modifier = pitch_bend_up; 281 sc->modifier = pitch_bend_up;
278 printf("String %d acts aftertouch as pitch_bend_up\n", 1 + g_current_string); 282 harfe_debug("String %d acts aftertouch as pitch_bend_up\n", 1 + g_current_string);
279 break; 283 break;
280 case KEYWORD_PITCH_BEND_DOWN: 284 case KEYWORD_PITCH_BEND_DOWN:
281 sc->modifier = pitch_bend_down; 285 sc->modifier = pitch_bend_down;
282 printf("String %d acts aftertouch as pitch_bend_down\n", 1 + g_current_string); 286 harfe_debug("String %d acts aftertouch as pitch_bend_down\n", 1 + g_current_string);
283 break; 287 break;
284 case KEYWORD_MIDI_CONTROL: 288 case KEYWORD_MIDI_CONTROL:
285 sc->modifier = midi_controller; 289 sc->modifier = midi_controller;
286 printf("String %d acts aftertouch as midi_controller\n", 1 + g_current_string); 290 harfe_debug("String %d acts aftertouch as midi_controller\n", 1 + g_current_string);
287 break; 291 break;
288 case KEYWORD_MIDI_CONTROL_INVERSE: 292 case KEYWORD_MIDI_CONTROL_INVERSE:
289 sc->modifier = midi_controller_inv; 293 sc->modifier = midi_controller_inv;
290 printf("String %d acts aftertouch as midi_controller_inverse\n", 1 + g_current_string); 294 harfe_debug("String %d acts aftertouch as midi_controller_inverse\n", 1 + g_current_string);
291 break; 295 break;
292 default: 296 default:
293 fprintf(stderr, "Illegal Modifier for string: %s\n", _line); 297 harfe_error(stderr, "Illegal Modifier for string: %s\n", _line);
294 return -1; 298 return -1;
295 } 299 }
296 break; 300 break;
297 case KEYWORD_PITCHFACTOR: 301 case KEYWORD_PITCHFACTOR:
298 sc->pitch_factor = atol(line); 302 sc->pitch_factor = atol(line);
299 printf("String %d is given a custom pitch factor of %d\n", 1 + g_current_string, sc->pitch_factor); 303 harfe_debug("String %d is given a custom pitch factor of %d\n", 1 + g_current_string, sc->pitch_factor);
300 break; 304 break;
301 case KEYWORD_CONTROLLER: 305 case KEYWORD_CONTROLLER:
302 sc->controller = atol(line); 306 sc->controller = atol(line);
303 printf("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller); 307 harfe_debug("String %d is on midi_controller line %d\n", 1 + g_current_string, sc->controller);
304 break; 308 break;
305 case KEYWORD_TIMETOSILENCE: 309 case KEYWORD_TIMETOSILENCE:
306 sc->timetosilence = atol(line); 310 sc->timetosilence = atol(line);
307 printf("String %d has a timetosilence of %d\n", 1 + g_current_string, sc->timetosilence); 311 harfe_debug("String %d has a timetosilence of %d\n", 1 + g_current_string, sc->timetosilence);
308 break; 312 break;
309 case KEYWORD_TWOOCTAVESPLIT: 313 case KEYWORD_TWOOCTAVESPLIT:
310 g_midi_two_octave_split = atol(line); 314 g_midi_two_octave_split = atol(line);
311 printf("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split); 315 harfe_debug("Splitting TWO octaves at %d%%\n", g_midi_two_octave_split);
312 if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) { 316 if (g_midi_two_octave_split < 0 || g_midi_two_octave_split > 100) {
313 fprintf(stderr, "Invalid percentage in line: %s\n", _line); 317 harfe_error(stderr, "Invalid percentage in line: %s\n", _line);
314 exit(1); 318 exit(1);
315 } 319 }
316 break; 320 break;
317 case KEYWORD_THREEOCTAVESPLIT_1: 321 case KEYWORD_THREEOCTAVESPLIT_1:
318 g_midi_three_octave_split_1 = atol(line); 322 g_midi_three_octave_split_1 = atol(line);
319 printf("Splitting THREE octaves top above %d%%\n", g_midi_three_octave_split_1); 323 harfe_debug("Splitting THREE octaves top above %d%%\n", g_midi_three_octave_split_1);
320 if (g_midi_three_octave_split_1 < 0 || g_midi_three_octave_split_1 > 100) { 324 if (g_midi_three_octave_split_1 < 0 || g_midi_three_octave_split_1 > 100) {
321 fprintf(stderr, "Invalid percentage in line: %s\n", _line); 325 harfe_error(stderr, "Invalid percentage in line: %s\n", _line);
322 exit(1); 326 exit(1);
323 } 327 }
324 split_done = 1; 328 split_done = 1;
325 break; 329 break;
326 case KEYWORD_THREEOCTAVESPLIT_2: 330 case KEYWORD_THREEOCTAVESPLIT_2:
327 g_midi_three_octave_split_2 = atol(line); 331 g_midi_three_octave_split_2 = atol(line);
328 printf("Splitting THREE octaves bottom below %d%%\n", g_midi_three_octave_split_2); 332 harfe_debug("Splitting THREE octaves bottom below %d%%\n", g_midi_three_octave_split_2);
329 if (g_midi_three_octave_split_2 < 0 || g_midi_three_octave_split_2 > 100) { 333 if (g_midi_three_octave_split_2 < 0 || g_midi_three_octave_split_2 > 100) {
330 fprintf(stderr, "Invalid percentage in line: %s\n", _line); 334 harfe_error(stderr, "Invalid percentage in line: %s\n", _line);
331 return -1; 335 return -1;
332 } 336 }
333 split_done = 1; 337 split_done = 1;
334 break; 338 break;
335 case KEYWORD_MIDI_MAIN_CONTROL: 339 case KEYWORD_MIDI_MAIN_CONTROL:
336 g_midi_main_control = atol(line); 340 g_midi_main_control = atol(line);
337 printf("All Strings modify controller %d\n", g_midi_main_control); 341 harfe_debug("All Strings modify controller %d\n", g_midi_main_control);
338 if (g_midi_main_control > 127) { 342 if (g_midi_main_control > 127) {
339 fprintf(stderr, "Invalid controller number %d in line: %s\n", g_midi_main_control, _line); 343 harfe_error(stderr, "Invalid controller number %d in line: %s\n", g_midi_main_control, _line);
340 return -1; 344 return -1;
341 } 345 }
342 break; 346 break;
343 case KEYWORD_MIDI_MAIN_CHANNEL: 347 case KEYWORD_MIDI_MAIN_CHANNEL:
344 g_midi_main_channel = atol(line); 348 g_midi_main_channel = atol(line);
345 printf("All Strings modify controller %d on channel %d\n", g_midi_main_control, g_midi_main_channel); 349 harfe_debug("All Strings modify controller %d on channel %d\n", g_midi_main_control, g_midi_main_channel);
346 if (g_midi_main_channel < 1 || g_midi_main_channel > 16) { 350 if (g_midi_main_channel < 1 || g_midi_main_channel > 16) {
347 fprintf(stderr, "Invalid channel number %d in line: %s\n", g_midi_main_channel, _line); 351 harfe_error(stderr, "Invalid channel number %d in line: %s\n", g_midi_main_channel, _line);
348 return -1; 352 return -1;
349 } 353 }
350 break; 354 break;
351 case KEYWORD_SETTLED_DIST: 355 case KEYWORD_SETTLED_DIST:
352 g_settled_dist = atol(line); 356 g_settled_dist = atol(line);
353 printf("All AfterTouch events take place only after movement has slown down to %d points\n", g_settled_dist); 357 harfe_debug("All AfterTouch events take place only after movement has slown down to %d points\n", g_settled_dist);
354 break; 358 break;
355 default: 359 default:
356 fprintf(stderr, "Unhandled config line: %s\n", _line); 360 harfe_error(stderr, "Unhandled config line: %s\n", _line);
357 return -1; 361 return -1;
358 362
359 } 363 }
@@ -420,3 +424,15 @@ config_dumpstring(int string, char *out, size_t outsize)
420 off += snprintf(out + off, outsize - off, "\n" ); 424 off += snprintf(out + off, outsize - off, "\n" );
421 return off; 425 return off;
422} 426}
427
428void
429config_reverse_strings()
430{
431 int i;
432 for (i=0; i<g_string_count/2; ++i) {
433 LLine temp = g_string_conf[i].line;
434 g_string_conf[i].line = g_string_conf[g_string_count-i-1].line;
435 g_string_conf[g_string_count-i-1].line = temp;
436 }
437 g_config_source = source_edit;
438}
diff --git a/config.h b/config.h
index 64f7689..645499d 100644
--- a/config.h
+++ b/config.h
@@ -1,10 +1,11 @@
1#pragma once 1#pragma once
2 2
3#include <stdint.h> 3#include <stdint.h>
4#include <stdlib.h>
4#include "geometry.h" 5#include "geometry.h"
5 6
6#define MAX_LINECOUNT 32 7#define MAX_LINECOUNT 32
7#define CALIB_DEBUG 8//#define CALIB_DEBUG
8 9
9extern int g_min_y, g_max_y; 10extern int g_min_y, g_max_y;
10 11
@@ -76,9 +77,14 @@ typedef struct {
76} StringConfig; 77} StringConfig;
77 78
78extern StringConfig g_string_conf[MAX_LINECOUNT]; 79extern StringConfig g_string_conf[MAX_LINECOUNT];
79extern int g_string_count; 80extern int g_string_count;
81extern ConfigSource g_config_source;
82extern int g_importing_config;
83extern int g_calibration_running;
84
80void config_reset(); 85void config_reset();
81int config_handle_line( char *line); 86int config_handle_line( char *line);
82size_t config_dumpglobals(char *out, size_t outsize); 87size_t config_dumpglobals(char *out, size_t outsize);
83size_t config_dumpstring(int string, char *out, size_t outsize); 88size_t config_dumpstring(int string, char *out, size_t outsize);
84char *config_midi_note_to_string(int string); 89char *config_midi_note_to_string(int string);
90void config_reverse_strings();