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 --- engine.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'engine.c') 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