MIDI Note Messages Disappearing/Dropping when MIDI CC is sent

I'm designing custom MIDI controllers. I made a pressure sensitive 16 button drumpad kind of thing. Note on/off functionality works, but I'd also like each pad to send pressure data over MIDI CC, so I can do fun things with that :slight_smile:

The problem is, when I enable all the MIDI CC data to be sent, the notes don't send (or barely do). Every so often, a note will get through, but sometimes the note off won't. I suspect it's some kind of MIDI rate issue. I've found delaying the signal by 1ms slightly helps the notes get through this MIDI CC spam, but anything higher than 16ms (total) latency and it'll be perceivable, which I don't want.

Any help here appreciated

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

int DrumPadData[15];

void setup() 
{
  MIDI.begin(MIDI_CHANNEL_OFF);
}

void loop() 
{
  CalculateDrumPadData();
    for (int i=0; i<16; i++)
    {
      if (DrumPadData[i] > 350)
      {
        MIDI.sendNoteOn(i, 127, 1);
      }
      if (DrumPadData[i] < 350)
      {
        MIDI.sendNoteOn(i, 0, 1);
      }
    }
    
    for (int i=0; i<16; i++)
    {
      MIDI.sendControlChange(i, DrumPadData[i] / 7, 1);
      //delay(1);?
    }
}

void CalculateDrumPadData()
{
  //Very long and not relevant to this problem 
}

Oops?

Don't you want to detect changes rather than continuously sending note messages as long as the value is above the threshold?

Definitely relevant if the rate is an issue. Sending one CC message takes around a millisecond, so continuously sending messages it will slow down your code significantly.

Use a blink without delay technique to limit the rate, and only send a message if the value actually changed.

Something like this will only report changes

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

const int maxDrumPads = 16;
int DrumPadData[maxDrumPads];
int prevDrumPadData[maxDrumPads];

byte lastPadState[maxDrumPads];

void setup()
{
  MIDI.begin(MIDI_CHANNEL_OFF);
}

void loop()
{
  CalculateDrumPadData();
  for (int i = 0; i < maxDrumPads; i++) {
    byte currentState;
    if (DrumPadData[i] > 350) {
      currentState = 127;
    }
    else {
      currentState = 0;
    }

    if ( currentState != lastPadState[i] ) {
      MIDI.sendNoteOn(i, currentState, 1);
    }
    lastPadState[i] = currentState;

    if ( DrumPadData[i] / 7 != prevDrumPadData[i] / 7 ) {
      MIDI.sendControlChange(i, DrumPadData[i] / 7, 1);
      prevDrumPadData[i] = DrumPadData[i];
    }
  }
}

void CalculateDrumPadData()
{
  //Very long and not relevant to this problem
}

Thank you! So I rewrote the code (very poorly as you can tell lol) to simplify it to it's core problem. The issue of MIDI notes being lost in a stream of CC data is to use the blink with delay technique to limit the CC being sent to once every 10ms, and also to only report changes