diff options
author | erdgeist <erdgeist@bauklotz.fritz.box> | 2018-04-16 15:59:54 +0200 |
---|---|---|
committer | erdgeist <erdgeist@bauklotz.fritz.box> | 2018-04-16 15:59:54 +0200 |
commit | fd0cea2ce5b43f04e9d2abcecc2a1e6b8bb95c73 (patch) | |
tree | bddd8fa40736eca31a72dfe3cb30a5804997bb6d | |
parent | ed5ec5c193630c230e4a4d3a1a8b0f218381511b (diff) |
Rework when to play notes in attack
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | engine.c | 11 |
3 files changed, 7 insertions, 7 deletions
@@ -12,6 +12,7 @@ int g_midi_two_octave_split = 50; | |||
12 | int g_midi_three_octave_split_1 = 33; | 12 | int g_midi_three_octave_split_1 = 33; |
13 | int g_midi_three_octave_split_2 = 66; | 13 | int g_midi_three_octave_split_2 = 66; |
14 | int g_midi_three_octave_split_inverse = 0; | 14 | int g_midi_three_octave_split_inverse = 0; |
15 | int g_settled_timedelta = 10; | ||
15 | int g_settled_dist = 5; | 16 | int g_settled_dist = 5; |
16 | int g_timetosilence = 30; | 17 | int g_timetosilence = 30; |
17 | int g_pitchbend_delay = 500; | 18 | int g_pitchbend_delay = 500; |
@@ -16,6 +16,7 @@ extern int g_midi_three_octave_split_inverse; | |||
16 | extern int g_midi_main_control; | 16 | extern int g_midi_main_control; |
17 | extern int g_midi_main_channel; | 17 | extern int g_midi_main_channel; |
18 | extern int g_settled_dist; | 18 | extern int g_settled_dist; |
19 | extern int g_settled_timedelta; | ||
19 | extern int g_timetosilence; | 20 | extern int g_timetosilence; |
20 | extern int g_pitchbend_delay; | 21 | extern int g_pitchbend_delay; |
21 | extern int g_normalize_factor; | 22 | extern int g_normalize_factor; |
@@ -72,6 +73,7 @@ typedef struct { | |||
72 | /* runtime values */ | 73 | /* runtime values */ |
73 | uint32_t first_time_seen; | 74 | uint32_t first_time_seen; |
74 | uint32_t last_time_seen; | 75 | uint32_t last_time_seen; |
76 | int seen_but_unchecked; | ||
75 | StringPlaying playing; | 77 | StringPlaying playing; |
76 | int octave; | 78 | int octave; |
77 | int start_off; | 79 | int start_off; |
@@ -311,7 +311,7 @@ engine_handle_point(LPoint * p, uint32_t monotime) | |||
311 | // test if difference is less than g_settled_dist percent of | 311 | // test if difference is less than g_settled_dist percent of |
312 | // line segment length | 312 | // line segment length |
313 | dt = monotime - s->first_time_seen; | 313 | dt = monotime - s->first_time_seen; |
314 | if (dt > 10 && abs(s->last_off - offs) < g_settled_dist) { | 314 | if (dt > g_settled_timedelta && abs(s->last_off - offs) < g_settled_dist) { |
315 | s->playing = string_is_playing; | 315 | s->playing = string_is_playing; |
316 | 316 | ||
317 | // estimated energy of hand is dv/dt from first seen to settled | 317 | // estimated energy of hand is dv/dt from first seen to settled |
@@ -322,11 +322,7 @@ engine_handle_point(LPoint * p, uint32_t monotime) | |||
322 | speed = 64 + speed / 4000; | 322 | speed = 64 + speed / 4000; |
323 | if (speed > 127) speed = 127; | 323 | if (speed > 127) speed = 127; |
324 | midi_playnote(s->channel, s->note, s->octave, speed); | 324 | midi_playnote(s->channel, s->note, s->octave, speed); |
325 | |||
326 | /* XXX TODO report speed as midi command */ | ||
327 | s->start_off = offs; | ||
328 | } | 325 | } |
329 | s->octave = oct; | ||
330 | s->last_off = offs; | 326 | s->last_off = offs; |
331 | break; | 327 | break; |
332 | case string_is_playing: | 328 | case string_is_playing: |
@@ -353,6 +349,7 @@ engine_handle_point(LPoint * p, uint32_t monotime) | |||
353 | break; | 349 | break; |
354 | } | 350 | } |
355 | s->last_time_seen = monotime; | 351 | s->last_time_seen = monotime; |
352 | s->seen_but_unchecked = 1; | ||
356 | } | 353 | } |
357 | 354 | ||
358 | void | 355 | void |
@@ -368,11 +365,10 @@ engine_checksilence(uint32_t monotime) | |||
368 | continue; | 365 | continue; |
369 | 366 | ||
370 | // Play notes in attack that are not visible anymore | 367 | // Play notes in attack that are not visible anymore |
371 | if (s->playing == string_is_in_attack && (monotime - s->last_time_seen) > 5) { | 368 | if (s->playing == string_is_in_attack && !s->seen_but_unchecked ) { |
372 | int speed, dv, dt = monotime - s->first_time_seen; | 369 | int speed, dv, dt = monotime - s->first_time_seen; |
373 | if (!dt) ++dt; | 370 | if (!dt) ++dt; |
374 | s->playing = string_is_playing; | 371 | s->playing = string_is_playing; |
375 | s->current_pitch = 0; | ||
376 | 372 | ||
377 | // estimated energy of hand is dv/dt from first seen to settled | 373 | // estimated energy of hand is dv/dt from first seen to settled |
378 | dv = abs(s->start_off - s->last_off); | 374 | dv = abs(s->start_off - s->last_off); |
@@ -390,5 +386,6 @@ engine_checksilence(uint32_t monotime) | |||
390 | midi_silencenote(s->channel, s->note, s->octave); | 386 | midi_silencenote(s->channel, s->note, s->octave); |
391 | s->playing = string_is_silent; | 387 | s->playing = string_is_silent; |
392 | } | 388 | } |
389 | s->seen_but_unchecked = 0; | ||
393 | } | 390 | } |
394 | } | 391 | } |