summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@bauklotz.fritz.box>2018-04-16 15:59:54 +0200
committererdgeist <erdgeist@bauklotz.fritz.box>2018-04-16 15:59:54 +0200
commitfd0cea2ce5b43f04e9d2abcecc2a1e6b8bb95c73 (patch)
treebddd8fa40736eca31a72dfe3cb30a5804997bb6d
parented5ec5c193630c230e4a4d3a1a8b0f218381511b (diff)
Rework when to play notes in attack
-rw-r--r--config.c1
-rw-r--r--config.h2
-rw-r--r--engine.c11
3 files changed, 7 insertions, 7 deletions
diff --git a/config.c b/config.c
index 9e47044..7fa938d 100644
--- a/config.c
+++ b/config.c
@@ -12,6 +12,7 @@ int g_midi_two_octave_split = 50;
12int g_midi_three_octave_split_1 = 33; 12int g_midi_three_octave_split_1 = 33;
13int g_midi_three_octave_split_2 = 66; 13int g_midi_three_octave_split_2 = 66;
14int g_midi_three_octave_split_inverse = 0; 14int g_midi_three_octave_split_inverse = 0;
15int g_settled_timedelta = 10;
15int g_settled_dist = 5; 16int g_settled_dist = 5;
16int g_timetosilence = 30; 17int g_timetosilence = 30;
17int g_pitchbend_delay = 500; 18int g_pitchbend_delay = 500;
diff --git a/config.h b/config.h
index 25b9e0d..80e7f78 100644
--- a/config.h
+++ b/config.h
@@ -16,6 +16,7 @@ extern int g_midi_three_octave_split_inverse;
16extern int g_midi_main_control; 16extern int g_midi_main_control;
17extern int g_midi_main_channel; 17extern int g_midi_main_channel;
18extern int g_settled_dist; 18extern int g_settled_dist;
19extern int g_settled_timedelta;
19extern int g_timetosilence; 20extern int g_timetosilence;
20extern int g_pitchbend_delay; 21extern int g_pitchbend_delay;
21extern int g_normalize_factor; 22extern 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;
diff --git a/engine.c b/engine.c
index 82f1355..4114b0f 100644
--- a/engine.c
+++ b/engine.c
@@ -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
358void 355void
@@ -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}