MIDI multiple notes

int const button[] = {2, 3, 4};
int const note[] = {36, 37, 38};
int xOuld = 0;
int x = 0;

void setup() {
 Serial.begin(312500);
   for(int z=0;z<3;z++){
 pinMode(button[z], INPUT);}
}

void loop(){
  for(int z=0;z<3;z++){
    int xx = digitalRead(button[z]);    //read button[0] than button[1] .....
    xOld = xx;                          //old value = xx       
    delay(10);                          //wait 10 ms
    x = digitalRead(button[z]);         //x is equal to  the digitalRead(button[z] so if the x is not equal to xOld before the 10ms than -->
 if (x == HIGH && xOud == LOW) {        //if x is pressed and before the 10 ms it was not -->
      Serial.write(144);                       // 1001 0000 = Note On Kanal 1
      Serial.write(noot[z]);                   //36 = Noot C2
      Serial.write(127);}
 if (x == LOW && xOud == HIGH) {        //if x is released and before the 10 ms it was -->
      Serial.write(144);                       // 1001 0000 = Note On Kanal 1
      Serial.write(noot[z]);                   //Note C2
      Serial.write(0);}}
 delay(1);
}

so anybody any ideas how to fix the code, I just want it to read the buttons and if they are HIGH send a MIDI signal and if they are LOW write the MIDI signal low and do nothing if the button is not pressed, if anybody could tell me what is wrong or write a good verrsion the code feel free to answer,

thanks alot

How are the switches wired? You do have external, pulldown resistors, right? Why? Using the internal pullup resistors is so much simpler.

I am using Pull-down resistors because in the future I am adding multiplexers, but how would you suggest the code then

I just want it to read the buttons and if they are HIGH send a MIDI signal and if they are LOW write the MIDI signal low and do nothing if the button is not pressed,

What state will the button pins be in if they are not pressed ? You seem to be describing 3 states.

Do you mean that you want to detect when the buttons become pressed or released rather than when the are pressed ? If so the look at the StateChangeDetection example in the IDE. If not, then please explain in more detail what you want to do.

yes, exactly that, but how do you do the ChangeStateDetection with multiple buttons.

how do you do the ChangeStateDetection with multiple buttons.

Keep separate values for the previous state of each button using an array. Then, as you iterate through them using the for loop you can tell whether any of them have changed and if so whether they are now HIGH or LOW and take appropriate action.