Neopixel and fast changes of midi-messages

Hi there, I got a project with a midi-controlled neopixel-ring.

All working so far, but It got problems with fast switches from one animation-mode to the other.

It should behave like this:
midi-note 64 on: green pixel-animation
midi-note 64 off: no pixel-animation (by setting pixelColor = 0)

midi-note 66 on: green pixel-animation
midi-note 66 off: no pixel-animation (by setting pixelColor = 0)

If there is a fast switch from note 64 to note 66, the animation stops.

I guess the messages for note64-off and note66-on come at almost the same time and somehow the message to switch off the animation is faster.

My approach to solve that problem would be an if-statement in the „void OnNoteOff“-section.
Is it possible to do something like this:

    case 64:
	if (*note 66 is also off*) {
		pixblockColor = 0; 
	} 
      break;

Here is my full code:

// AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>


#define NR_OF_LED_CIRCLE 16

Adafruit_NeoPixel pixelCircle = Adafruit_NeoPixel(NR_OF_LED_CIRCLE, 23, NEO_GRB + NEO_KHZ800);
uint8_t  offset = 0;    // StartPosition of pixelCircle
uint32_t pixblockColor  = 0;    // Default color of pixelCircle (Black)
uint8_t  pixblock = 4;  // Size of rotating pixelbar 

void setup() {
  //Serial.begin(115200);
  
  pixelCircle.begin(); 
  pixelCircle.setBrightness(40); 
  
  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn) ;
}

void loop() {
  usbMIDI.read(2); // Midi channel to read

    for(int i=0; i<NR_OF_LED_CIRCLE; i++) {
      uint32_t c = 0;
      if(((offset - i) & 7) < pixblock) c = pixblockColor;
      pixelCircle.setPixelColor( i, c); // First eye
    }
    pixelCircle.show();
    offset++;
    offset=millis()/100;
    
}

//MIDI READ
void OnNoteOn(byte channel, byte note, byte velocity) {
  if (velocity > 0) {
    switch (note) {

      case 64:
        pixblockColor = pixelCircle.Color(57, 230, 0); // animation green
        pixblock = 7;
        break;
       case 66:
        pixblockColor = pixelCircle.Color(0, 128, 255); // animation blue 
        pixblock = 7;
        break;        
        
      } 
    } 
}

void OnNoteOff(byte channel, byte note, byte velocity) {
  switch (note) {

    case 64:
      pixblockColor = 0;
      break;
    case 66:
      pixblockColor = 0;
      break;
        
  }
}

message to switch off the animation is faster.

No, they will be the same speed. Probably the on/off mesages are not coming in the order you expect.

Solution is simple. When a note pattern starts, record the note in a variable. When a note stops, check the variable. If they match, set the pixels off. If they don't match, do nothing.