diff options
author | Bad Diode <bd@badd10de.dev> | 2023-02-09 19:08:06 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-02-09 19:08:06 +0100 |
commit | 68c082bebaac3b0412b2f373b27d8b8894f07467 (patch) | |
tree | 24de7582e46897b3f1919c3f4cd2a54b84b78066 /src/app.c | |
parent | 6966396ba6d6f2569d7cf57078be7c736b39da69 (diff) | |
download | launchpad-polymaker-68c082bebaac3b0412b2f373b27d8b8894f07467.tar.gz launchpad-polymaker-68c082bebaac3b0412b2f373b27d8b8894f07467.zip |
Add round-robin to channel selection
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -209,6 +209,7 @@ State state = {0}; | |||
209 | u32 note_counter = 0; | 209 | u32 note_counter = 0; |
210 | u8 midi_in_connected = 0; | 210 | u8 midi_in_connected = 0; |
211 | u8 midi_out_connected = 0; | 211 | u8 midi_out_connected = 0; |
212 | u8 next_voice = 0; | ||
212 | 213 | ||
213 | // store ADC frame pointer | 214 | // store ADC frame pointer |
214 | static const u16 *g_ADC = 0; | 215 | static const u16 *g_ADC = 0; |
@@ -365,13 +366,14 @@ app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { | |||
365 | return; | 366 | return; |
366 | } | 367 | } |
367 | u8 channel = status & 0x0F; | 368 | u8 channel = status & 0x0F; |
369 | u8 max_voices = (state.ch_max - state.ch_min + 1); | ||
368 | // If the channel isn't set to listen, just passthrough the message. | 370 | // If the channel isn't set to listen, just passthrough the message. |
369 | if (!state.ch_listen[channel]) { | 371 | if (!state.ch_listen[channel]) { |
370 | hal_send_midi(port, status, d1, d2); | 372 | hal_send_midi(port, status, d1, d2); |
371 | return; | 373 | return; |
372 | } | 374 | } |
373 | if ((status & 0xF0) == NOTEON) { | 375 | if ((status & 0xF0) == NOTEON) { |
374 | if (n_voices == (state.ch_max - state.ch_min + 1)) { | 376 | if (n_voices == max_voices) { |
375 | u8 selected = 0; | 377 | u8 selected = 0; |
376 | switch (state.stealing) { | 378 | switch (state.stealing) { |
377 | case POLY_STEAL_OFF: { | 379 | case POLY_STEAL_OFF: { |
@@ -439,7 +441,7 @@ app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { | |||
439 | if (!voice->active) { | 441 | if (!voice->active) { |
440 | voice->active = 1; | 442 | voice->active = 1; |
441 | voice->port = port; | 443 | voice->port = port; |
442 | voice->channel = i; | 444 | voice->channel = state.ch_min + (next_voice++ % max_voices) ; |
443 | voice->d1 = d1; | 445 | voice->d1 = d1; |
444 | voice->d2 = d2; | 446 | voice->d2 = d2; |
445 | hal_send_midi(voice->port, | 447 | hal_send_midi(voice->port, |
@@ -455,10 +457,9 @@ app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { | |||
455 | } else if ((status & 0xF0) == NOTEOFF) { | 457 | } else if ((status & 0xF0) == NOTEOFF) { |
456 | for (u8 i = state.ch_min; i <= state.ch_max; i++) { | 458 | for (u8 i = state.ch_min; i <= state.ch_max; i++) { |
457 | Voice *voice = &voices[i]; | 459 | Voice *voice = &voices[i]; |
458 | // Register voice. | ||
459 | if (voice->active && voice->d1 == d1) { | 460 | if (voice->active && voice->d1 == d1) { |
460 | voice->active = 0; | 461 | voice->active = 0; |
461 | hal_send_midi(port, NOTEOFF | i, d1, d2); | 462 | hal_send_midi(port, NOTEOFF | voice->channel, d1, d2); |
462 | n_voices--; | 463 | n_voices--; |
463 | break; | 464 | break; |
464 | } | 465 | } |