From fd0cea2ce5b43f04e9d2abcecc2a1e6b8bb95c73 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 16 Apr 2018 15:59:54 +0200 Subject: Rework when to play notes in attack --- config.c | 1 + config.h | 2 ++ engine.c | 11 ++++------- 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; int g_midi_three_octave_split_1 = 33; int g_midi_three_octave_split_2 = 66; int g_midi_three_octave_split_inverse = 0; +int g_settled_timedelta = 10; int g_settled_dist = 5; int g_timetosilence = 30; int 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; extern int g_midi_main_control; extern int g_midi_main_channel; extern int g_settled_dist; +extern int g_settled_timedelta; extern int g_timetosilence; extern int g_pitchbend_delay; extern int g_normalize_factor; @@ -72,6 +73,7 @@ typedef struct { /* runtime values */ uint32_t first_time_seen; uint32_t last_time_seen; + int seen_but_unchecked; StringPlaying playing; int octave; 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) // test if difference is less than g_settled_dist percent of // line segment length dt = monotime - s->first_time_seen; - if (dt > 10 && abs(s->last_off - offs) < g_settled_dist) { + if (dt > g_settled_timedelta && abs(s->last_off - offs) < g_settled_dist) { s->playing = string_is_playing; // estimated energy of hand is dv/dt from first seen to settled @@ -322,11 +322,7 @@ engine_handle_point(LPoint * p, uint32_t monotime) speed = 64 + speed / 4000; if (speed > 127) speed = 127; midi_playnote(s->channel, s->note, s->octave, speed); - - /* XXX TODO report speed as midi command */ - s->start_off = offs; } - s->octave = oct; s->last_off = offs; break; case string_is_playing: @@ -353,6 +349,7 @@ engine_handle_point(LPoint * p, uint32_t monotime) break; } s->last_time_seen = monotime; + s->seen_but_unchecked = 1; } void @@ -368,11 +365,10 @@ engine_checksilence(uint32_t monotime) continue; // Play notes in attack that are not visible anymore - if (s->playing == string_is_in_attack && (monotime - s->last_time_seen) > 5) { + if (s->playing == string_is_in_attack && !s->seen_but_unchecked ) { int speed, dv, dt = monotime - s->first_time_seen; if (!dt) ++dt; s->playing = string_is_playing; - s->current_pitch = 0; // estimated energy of hand is dv/dt from first seen to settled dv = abs(s->start_off - s->last_off); @@ -390,5 +386,6 @@ engine_checksilence(uint32_t monotime) midi_silencenote(s->channel, s->note, s->octave); s->playing = string_is_silent; } + s->seen_but_unchecked = 0; } } -- cgit v1.2.3