summaryrefslogtreecommitdiff
path: root/engine.c
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 /engine.c
parented5ec5c193630c230e4a4d3a1a8b0f218381511b (diff)
Rework when to play notes in attack
Diffstat (limited to 'engine.c')
-rw-r--r--engine.c11
1 files changed, 4 insertions, 7 deletions
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}