set one midi channel in MIDIUSB code (Midi to Neopixel)

Hi!

I am trying to set a single midi channel to this code for hours now, and I just cant get it to work, i am sure it is dead simple, but i just dont know what to do anymore…
Right now this code works on all Midi channels, but i need it to be a specific one.
Please help me :slight_smile:

#include "MIDIUSB.h"


const byte _NLED = 56;
const byte _DPIN = 6;

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel _LED = Adafruit_NeoPixel(_NLED, _DPIN, NEO_GRB + NEO_KHZ800);

const byte _R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte _G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};
const byte _PStart = 0; 

void setup() {
_LED.begin();
_LED.show();
}


void loop() {
 
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if(rx.header  == 2){
    if(rx.header == 0x9) noteOn(rx.byte1, rx.byte2,rx.byte3);
    if(rx.header == 0x8) noteOff(rx.byte1, rx.byte2,rx.byte3);
    }
  while (rx.header == 0); // hold until a MIDI message is received
}
void noteOn(byte channel, byte pitch, byte velocity){


   _LED.setPixelColor(pitch -_PStart, _R[velocity], _G[velocity], _B[velocity]);
  
  _LED.show();
}
void noteOff(byte channel, byte pitch, byte velocity) {
 
  _LED.setPixelColor(pitch - _PStart, 0, 0, 0);
  
  _LED.show();
}

Have a look at the USB MIDI spec: https://www.usb.org/sites/default/files/midi10.pdf (page 16)
Also check the MIDI Standard.

The channel is the low nibble of the first MIDI byte:

if (rx.byte1 & 0x0F == 3)
  // channel 4

Also, apart from being harder to read, starting identifiers with an underscore followed by a capital letter is undefined behavior.

Pieter

Can't you just put an "if" in the noteOn and noteOff functions? E.g.

void noteOn(byte channel, byte pitch, byte velocity){
   if (channel == 1)  // or whatever channel you want
  {
     _LED.setPixelColor(pitch -_PStart, _R[velocity], _G[velocity], _B[velocity]);
 
     _LED.show();
  }
}

Steve

slipstick:
Can’t you just put an “if” in the noteOn and noteOff functions? E.g.

void noteOn(byte channel, byte pitch, byte velocity){

if (channel == 1)  // or whatever channel you want
  {
    _LED.setPixelColor(pitch -_PStart, _R[velocity], _G[velocity], _B[velocity]);

_LED.show();
  }
}




Steve

Yes, but only if he fixes his “parser” code:

noteOn((rx.byte1 & 0x0F) + 1, rx.byte2, rx.byte3);

Thank you very much!!!

Arduino is giving me a hard time…i just dont get the programming language, altough i am
reading books and trying to find stuff online…but i couldnt find anything real helpful about this.
(or i guess i just dont know where and how to look)
THANK YOU for your help!!!

So if you could/want to help me further…how could i trigger more than one led with one midi note?
so lets say, i want to trigger 10 leds with C1…

here is the now working code…every midi note triggers one led.
Btw this is not my code…

#include "MIDIUSB.h"


const byte NLED = 56;
const byte DPIN = 6;

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel LED = Adafruit_NeoPixel(NLED, DPIN, NEO_GRB + NEO_KHZ800);

const byte R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};



const byte PStart = 0;  // First note in array
bool update = false;


void setup() {
LED.begin();
LED.show();
}


void loop() {
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if(rx.header == 0x9) noteOn((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);
    if(rx.header == 0x8) noteOff((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);

  }
  while (rx.header == 0); // hold until a MIDI message is received
}

void noteOn(byte channel, byte pitch, byte velocity) {
  if (channel == 1)
  LED.setPixelColor(pitch -PStart, R[velocity], G[velocity], B[velocity]);
  update = true;
  LED.show();
}

void noteOff(byte channel, byte pitch, byte velocity) {
  if (channel == 1)
  LED.setPixelColor(pitch - PStart, 0, 0, 0);
  update = true;
  LED.show();
}

What relationship between the LEDs and pitch do you want?
The line

LED.setPixelColor(pitch -PStart,      ..........

Sets the led number to pitch, so if you want say three LEDs to turn on then just do

LED.setPixelColor(pitch -PStart,
LED.setPixelColor(pitch -PStart + 1,
LED.setPixelColor(pitch -PStart +2,

If you want 10 LEDs on then you are better using a loop

for(int j =0; j< 10; j++) {
LED.setPixelColor(pitch -PStart + j, ....
}

Note I have only put part of the command LED.setPixelColor(pitch -PStart, as I am on an iPad and it makes things difficulty to copy while writing a reply.

Also note that when MIDI comes in fast some notes will be dropped because of that type of LED strips requires precise timing and so the interrupts are turned off, and this cause some MIDI messages to be lost.

Thanks Mike!!!

It works like a charm!

I built a drum robot, and on its face is a led panel. The whole robot is controlled via midi (midi to servo)
so i want the face leds flash with different patterns.
So till now i just put every midi note into my sequencer, but it would be a lot easier if one midi note (lets say c1 on channel 3) triggers a pattern, the next midi note triggers another pattern. there are 56 leds on the face panel, 7x8.
So with your help i can now tell the arduino to trigger as many leds as i want with one midi note, which makes it way easier!
Can you maybe give me a hint where to look in the code if i want to trigger a certain pattern with one midi note?
I guess a loop would be the right way?

here is the working code with your suggestions:

#include "MIDIUSB.h"


const byte NUMPIXELS = 56;
const byte LED_PIN = 6;

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel LED = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);


const byte R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};



const byte PStart = 0;  

bool update = false;


void setup() {
LED.begin();
LED.show();
}


void loop() {
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if(rx.header == 0x9) noteOn((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);
    if(rx.header == 0x8) noteOff((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);

  }
  while (rx.header == 0); // hold until a MIDI message is received
}

Well it is a step up in programming complexity but it is not too big a jump.

First of all you should learn about writing you animation code as a state machine. This thread and others show you technique to use.

Also look at doing multiple things at the same time and the blink without delay example.

Then in your note on function you should check what note you have and kick off the animations you want to match to the note. This will then keep on going until you kick off another.

If you use a different animation for each MIDI note then you have a lot of work so I would restrict it to just 12 animations. By successive subtracting 12 from the note number until you have a number less than 12 then use that number to trigger an animation then each note of any octave will trigger the same animation.

Thank you Mike!
I will have a look at the thread you linked and learn about state machines :slight_smile:
Thinking mainly about non animated stuff, rather static patterns ( like eyes and stuff) which are on as long as the midi note is held.

I really appreciate your help so far!

Thinking mainly about non animated stuff, rather static pattern

In which case you don’t need the state machine, just fixed patterns.
I would suggest you use an array containing the LED number and colours You want to set it to. The same function could be used to go through the array setting the LEDs up.

To stop you running out of data memory look at how to store arrays in program memory.

ok! I will have a look at arrays!!! thx for the suggestion.

ok, so i tried to get an array working for quite some time. the best i could get was that it compiled, but didnt trigger any leds…
This was my not working attempt (just examples of the code where i changed it)

#include "MIDIUSB.h"


const byte NUMPIXELS = 56;
const byte LED_PIN = 6;

int Pattern1[]int = {2, 4, 8, 3, 6};

and then:

void noteOn(byte channel, byte pitch, byte velocity) {
  if (channel == 4,pitch == 0) {
LED.setPixelColor(Pattern1,R[velocity], G[velocity], B[velocity]);

it compiles, but doesnt work.

This code works, but it just looks clunky…

#include "MIDIUSB.h"


const byte NUMPIXELS = 56;
const byte LED_PIN = 6;


#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel LED = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);


const byte R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};


bool update = false;


void setup() {
LED.begin();
LED.show();

}


void loop() {
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if(rx.header == 0x9) noteOn((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);
    if(rx.header == 0x8) noteOff((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);

  }
  while (rx.header == 0); // hold until a MIDI message is received
}

void noteOn(byte channel, byte pitch, byte velocity) {
  if (channel == 4,pitch == 0) {
LED.setPixelColor(1,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(3,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(5,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(8,R[velocity], G[velocity], B[velocity]);
}
LED.show();
}

void noteOff(byte channel, byte pitch, byte velocity) {
  if (channel == 4, pitch == 0){
  LED.setPixelColor(1, 0, 0, 0);
  LED.setPixelColor(3, 0, 0, 0);
  LED.setPixelColor(5, 0, 0, 0);
  LED.setPixelColor(8, 0, 0, 0);
   }
  update = true;
  LED.show();
}

Where is my mistake? Thanks in advance!

if (channel == 4,pitch == 0) {
  1. that is not how to do an if statement. If you want that to go when channel is 4 and the pitch is 0 then you have to use:-
if (channel == 4 && pitch == 0) {

using a comma will compile but will not do what you think this is what it does.

but
2. Why will the pitch ever be 0? I thought you wanted to trigger off specific notes, so you would need to compare the pitch to the one you are after.

Replace

LED.setPixelColor(1,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(3,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(5,R[velocity], G[velocity], B[velocity]);
LED.setPixelColor(8,R[velocity], G[velocity], B[velocity]);

with

for(int i = 1; i<9 ; i +=2){ // start at 1 and go in steps of 2
LED.setPixelColor(i,R[velocity], G[velocity], B[velocity]);
}

But do you not want to use pitch instead of velocity as your array index?

LED.setPixelColor(Pattern1,R[velocity], G[velocity], B[velocity]);

When ever you use an array like Pattern1 you must use an index to it, Pattern1[some constant or variable ]

I want that one midi note (here it is C0) triggers one pattern...
so i want to start with C0 on channel 4 (channel is always the same)
so lets say: C0 triggers some kind of eye pattern, C#0 triggers a triangle...and so forth.

My goal is to trigger specific leds (pattern) with one midi note....
so maybe 12 different patterns, with C0 to C1

Array:
I thought the 8 in

(8,R[velocity], G[velocity], B[velocity])

defines the led,
so i tried to put an array here to trigger a pattern....

I thought the 8 in
(8,R[velocity], G[velocity], B[velocity])
defines the led,

Yes it does.

so i tried to put an array here to trigger a pattern

No, an array is a list of numbers, just like the house number on a street. Behind each door number is a value. In an array you use the form variable[ 5 ] which is like saying street variable door number 5. Behind the door is a number, it is that number that you get back from variable[ 5 ].

If you want to see all the numbers then you have to run down the street opening all the doors and getting the numbers behind the door one at a time.

I want that one midi note (here it is C0) triggers one pattern.

So you use:-

if (channel == 4 && pitch == 60) {

because C0 has the note number 60.

if (channel == 4 && pitch == 0) {

Thanks!
No that is an explanation i understand! :slight_smile:
I will work on it!

So i am step further…the array works…somehow.
there is always the first led blinking, regardles of the pattern.
And if i play other midinotes, some leds blink and get stuck.
this is my code:

#include "MIDIUSB.h"


const byte NUMPIXELS = 56;
const byte LED_PIN = 6;
int Pattern1[] = {  2, 3, 5, 7, 9 };

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel LED = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);


const byte R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};


bool update = false;


void setup() {
LED.begin();
LED.show();

}


void loop() {
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if(rx.header == 0x9) noteOn((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);
    if(rx.header == 0x8) noteOff((rx.byte1 & 0x0F) + 1, rx.byte2,rx.byte3);

  }
  while (rx.header == 0); // hold until a MIDI message is received
}
void noteOn(byte channel, byte pitch, byte velocity) {
  if (channel == 4&& pitch == 60)
  for(int j = 0; j< 56; j++){
LED.setPixelColor(Pattern1[j],R[velocity], G[velocity], B[velocity]);

}
LED.show();
}
void noteOff(byte channel, byte pitch, byte velocity) {
  if (channel == 4 && pitch == 60)
  for(int j = 0; j< 56; j++){
  LED.setPixelColor(Pattern1[j], 0, 0, 0);
  
   }
  update = true;
  LED.show();
}

The array Pattern1 has five elements , the for loop addresses 57 elements, far more than you actually have, so the code just picks up rubbish or other numbers in the memory at random, so while LEDs might light up your code is not working.

I can’t get a clear idea from your code about what the Pattern1 array is doing. If it is just defining what LEDs are on, you need to restrict the for loop to only use the numbers you have defined.
So your

for(int j = 0; j< 56; j++)

Should be

for(int j = 0; j< 5; j++)

To address only the LEDs you have defined in your array.

Note all the LEDs in the list given by the Pattern array set all those LEDs to the same colour. Is that what you want?

Oh awesome!! now the pattern works.
Regarding the one colour:
Yeah, thats fine, because i can change it with the velocity. One color per Pattern is absolutely fine!

So if i want to add another pattern, i have to initialize it at the beginning like this:

const byte NUMPIXELS = 56;
const byte LED_PIN = 6;
int Pattern1 = { 2, 3, 5, 7, 9 };
int Pattern2 = { 3, 4, 6, 8, 10 };

and then in the loop, have i to duplicate the whole void part for the new pattern, or is there a more elegant way?

So if i want to add another pattern, i have to initialize it at the beginning like this:

Yes.

and then in the loop, have i to duplicate the whole void part for the new pattern,

I don't understand what that is.

is there a more elegant way?

Yes, it is called a two dimensional array. A bit like a U.S. city road plan, with streets and avenues. It has two indexes one for X and the other for Y.

So you would use Pattern[ x ] [ y ] that is Pattern[ the pattern number] [ the LED in that pattern ]

You can initilise it like this:-

byte Pattern[6][6] = {
                    // pattern 0
                   42, 49, 55, 41, 48, 40,
                   // pattern 1
                   57, 58, 59, 52, 53, 46,
                   // pattern 2
                   35, 43, 50, 36, 44, 37,
                   // pattern 3
                   5, 11, 18, 12, 19, 20,
                  // pattern 4
                   1, 2, 3, 7, 8, 14,
                   // pattern 5
                   10, 17, 25, 16, 24, 23,
                   };