diff options
author | Bad Diode <bd@badd10de.dev> | 2023-02-09 20:37:06 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-02-09 20:37:06 +0100 |
commit | 10513f80a94bde633922862db9ca71337889f0e5 (patch) | |
tree | d52a073193813dc8a39fb9e054e02272edf2d828 /src/app.c | |
parent | 68c082bebaac3b0412b2f373b27d8b8894f07467 (diff) | |
download | launchpad-polymaker-10513f80a94bde633922862db9ca71337889f0e5.tar.gz launchpad-polymaker-10513f80a94bde633922862db9ca71337889f0e5.zip |
Fix round robin voice stealingv1.0.0
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -435,13 +435,13 @@ app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { | |||
435 | } | 435 | } |
436 | 436 | ||
437 | // Find next free voice slot. | 437 | // Find next free voice slot. |
438 | for (u8 i = state.ch_min; i <= state.ch_max; i++) { | 438 | for (u8 i = state.ch_min; i <= state.ch_max; i++, next_voice++) { |
439 | Voice *voice = &voices[i]; | 439 | Voice *voice = &voices[(next_voice % max_voices)]; |
440 | // Register voice. | 440 | // Register voice. |
441 | if (!voice->active) { | 441 | if (!voice->active) { |
442 | voice->active = 1; | 442 | voice->active = 1; |
443 | voice->port = port; | 443 | voice->port = port; |
444 | voice->channel = state.ch_min + (next_voice++ % max_voices) ; | 444 | voice->channel = (next_voice % max_voices); |
445 | voice->d1 = d1; | 445 | voice->d1 = d1; |
446 | voice->d2 = d2; | 446 | voice->d2 = d2; |
447 | hal_send_midi(voice->port, | 447 | hal_send_midi(voice->port, |
@@ -449,17 +449,20 @@ app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { | |||
449 | voice->d1, | 449 | voice->d1, |
450 | voice->d2); | 450 | voice->d2); |
451 | voice->age = note_counter++; | 451 | voice->age = note_counter++; |
452 | next_voice++; | ||
452 | break; | 453 | break; |
453 | } | 454 | } |
454 | } | 455 | } |
455 | |||
456 | n_voices++; | 456 | n_voices++; |
457 | } else if ((status & 0xF0) == NOTEOFF) { | 457 | } else if ((status & 0xF0) == NOTEOFF) { |
458 | for (u8 i = state.ch_min; i <= state.ch_max; i++) { | 458 | for (u8 i = state.ch_min; i <= state.ch_max; i++) { |
459 | Voice *voice = &voices[i]; | 459 | Voice *voice = &voices[i]; |
460 | if (voice->active && voice->d1 == d1) { | 460 | if (voice->active && voice->d1 == d1) { |
461 | voice->active = 0; | 461 | voice->active = 0; |
462 | hal_send_midi(port, NOTEOFF | voice->channel, d1, d2); | 462 | hal_send_midi(voice->port, |
463 | NOTEOFF | voice->channel, | ||
464 | voice->d1, | ||
465 | voice->d2); | ||
463 | n_voices--; | 466 | n_voices--; |
464 | break; | 467 | break; |
465 | } | 468 | } |