even better fix

This commit is contained in:
Stefano D'Angelo 2023-08-04 15:48:46 +02:00
parent 4542235dac
commit ad115964a6

View File

@ -134,18 +134,16 @@ void bw_voice_alloc(const bw_voice_alloc_opts *BW_RESTRICT opts, bw_note_queue *
goto next_event;
}
char found = 0;
BW_SIZE_T k;
BW_SIZE_T k = n_voices;
int v = ev->note;
for (BW_SIZE_T j = 0; j < n_voices; j++) {
int n = opts->get_note(voices[j]);
if (!queue->status[n].pressed && (!found || (opts->priority == bw_voice_alloc_priority_low ? n > v : n < v))) {
if (!queue->status[n].pressed && (k == n_voices || (opts->priority == bw_voice_alloc_priority_low ? n > v : n < v))) {
v = n;
k = j;
found = 1;
}
}
if (found) {
if (k != n_voices) {
opts->note_on(voices[k], ev->note, ev->status.velocity);
continue;
}
@ -155,10 +153,9 @@ void bw_voice_alloc(const bw_voice_alloc_opts *BW_RESTRICT opts, bw_note_queue *
if (opts->priority == bw_voice_alloc_priority_low ? n > v : n < v) {
v = n;
k = j;
found = 1;
}
}
if (found)
if (k != n_voices)
opts->note_on(voices[k], ev->note, ev->status.velocity);
}