summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-02-09 19:08:06 +0100
committerBad Diode <bd@badd10de.dev>2023-02-09 19:08:06 +0100
commit68c082bebaac3b0412b2f373b27d8b8894f07467 (patch)
tree24de7582e46897b3f1919c3f4cd2a54b84b78066
parent6966396ba6d6f2569d7cf57078be7c736b39da69 (diff)
downloadlaunchpad-polymaker-68c082bebaac3b0412b2f373b27d8b8894f07467.tar.gz
launchpad-polymaker-68c082bebaac3b0412b2f373b27d8b8894f07467.zip
Add round-robin to channel selection
-rw-r--r--src/app.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/app.c b/src/app.c
index aacc68f..a035022 100644
--- a/src/app.c
+++ b/src/app.c
@@ -209,6 +209,7 @@ State state = {0};
209u32 note_counter = 0; 209u32 note_counter = 0;
210u8 midi_in_connected = 0; 210u8 midi_in_connected = 0;
211u8 midi_out_connected = 0; 211u8 midi_out_connected = 0;
212u8 next_voice = 0;
212 213
213// store ADC frame pointer 214// store ADC frame pointer
214static const u16 *g_ADC = 0; 215static 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 }