Help for a sketch

I'm trying to switch on some leds with midi note coming from a software named vmix.
The sketch is this:

 // Data received from the serial port
 int val; 
 //LEDs are connected to the following pins
 int pins[] = {4,5,6,7,8}; 
 
 void setup() {
   for(int i=0; i<5; i++){
   pinMode(pins[i], OUTPUT); // Set pins as OUTPUTs
   }
   Serial.begin(9600); // Start serial communication at 9600 bps
 }
 
 void loop() {
 if (Serial.available()) { // If data is available to read,
 val = Serial.read(); // read it and store it in val
 // Turn on LEDs, depending on pitches received
  if (val == 60) { digitalWrite(pins[0],HIGH); } else
  if (val == 62) { digitalWrite(pins[1],HIGH); } else
  if (val == 64) { digitalWrite(pins[2],HIGH); } else
  if (val == 65) { digitalWrite(pins[3],HIGH); } else
  if (val == 67) { digitalWrite(pins[4],HIGH); } else
  if (val==0) { resetLEDs(); }
 }
 }
 //Function that turns all the LEDs off
 void resetLEDs(){
  for(int i=0; i<5; i++){
   digitalWrite(pins[i],LOW);
  } 
 }

When vmix sends "note 60 on", the led on pin 4 is switched on (correct).

When vmix sends "note 60 off" "note 62 on", the led on pin 4 is switched off and the led on pin 5 is switched on (correct)

Now is what I don't understand:
When Vmix sends note "60 on" "note 62 off" I expected led on pin 4 switched on and led on pin 5 switched off but what happens is led on pin 4 has an "inpulse" and then is immediately switched off and led on pin 5 is switched off.

Where I am wrong? Can you help me to understand?

Read Serial Input Basics - updated to get an idea how to reliably receive serial data.

You compare val with the number 60; that is the character '<' (see http://www.asciitable.com/. Same for 62 and so on.

If vmix sends a c-style string (nul terminated) including the nul, you will receive the nul character (literally a 0) and you will react on that.

Thank you for your answer sterretje. I forgot to say that before all I open a processing with this code:

//Import libraries
import processing.serial.*;
import promidi.*;

Serial myPort;
MidiIO midiIO;
//Message to be sent
int message=0;

void setup() {  
  myPort = new Serial(this, "COM11", 9600);
  midiIO = MidiIO.getInstance(this);
  //Line that prints I/O devices in console
  midiIO.printDevices();
  //Receive input from Virtual MIDI Ports
  midiIO.openInput(0,0);
}

void draw() {}
void noteOn(Note note, int deviceNum, int midiChan){
  int vel = note.getVelocity();
  int pitch = note.getPitch();
  if(vel>0){ // If velocity > 0 set message value to note's pitch
   if(pitch==60){ message=60; } else 
   if(pitch==62){ message=62; } else 
   if(pitch==64){ message=64; } else 
   if(pitch==65){ message=65; } else 
   if(pitch==67){ message=67; } else message=0;
    } else { message=0;}
  //Send message to Arduino
  myPort.write(message);
}

So, what Arduino receives are just midi notes.