Midi library works fine with PC but poorly with MPC

Hi everybody!
We have developed a little project which understand midi message using midi library and arduino UNO and lights some power leds related with some keys. Our variables are pitch and velocity. The hardware and software work fine when we connect midi wire directly from the computer and send the midi standard. (Cubase 6.5) The problems begin using MPC (AKAI MPC1000). We realized that it uses note on == 0 instead of note off and we have fixed the code, but there are still problems.
At the beginning it works perfectly, but more midi messages are coming more differences occur. At the end leds remain switched on when they must switch off and things like that.
We discard our hardware because works ok connected through the Computer. Is it possible that messages from MPC have any difference else from the midi standard?
This is the example connected through the computer.

I hope someone could help us.

We are maintaining the note off in order to use both, Computer and MPC

#include <MIDI.h>

int Led2 = 2;
int Led3 = 3;
int Led4 = 4;
int Led5 = 5;
int Led6 = 6;
int Led7 = 7;
int Led8 = 8;
int Led9 = 9;
int Led10 = 10;
int Led11 = 11;

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here: 
// http://arduinomidilib.sourceforge.net/class_m_i_d_i___class.html

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

// Do whatever you want when you receive a Note On.

//--------------------**tecla DO central**----------------DIGITAL--------------------------
  if (pitch == 60 && velocity != 0)    
    { 
    digitalWrite(Led2, HIGH);
    }
  if (pitch == 60 && velocity == 0) 
    { 
    digitalWrite(Led2, LOW);
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla RE central**---------------PWM-------------------------------
  if (pitch == 61) 
    { 
    analogWrite(Led3, 2*velocity); 
      //delay(45); 
     }      
    
//-----------------------------------------------------------------------------------------
 
THE REST OF PITCHES....
 
}

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

//--------------------**tecla DO central**----------------DIGITAL--------------------------
  if (pitch == 60)    
    { 
    digitalWrite(Led2, LOW);
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla RE central**---------------PWM-------------------------------
  if (pitch == 61) 
    { 
     analogWrite(Led3, LOW); 
      //delay(45); 
    }
 //-----------------------------------------------------------------------------------------
 
THE REST OF PITCHES

}
void setup() {
  
  pinMode(Led2,OUTPUT);
  pinMode(Led3,OUTPUT);
  pinMode(Led4,OUTPUT);
  pinMode(Led5,OUTPUT);
  pinMode(Led6,OUTPUT);
  pinMode(Led7,OUTPUT);
  pinMode(Led8,OUTPUT);
  pinMode(Led9,OUTPUT);
  pinMode(Led10,OUTPUT);
  pinMode(Led11,OUTPUT);
  //pinMode(13, OUTPUT);
  // Initiate MIDI communications, listen to  channel 15
  MIDI.begin(14);    
  
  // Connect the HandleNoteOn function to the library, so it is called upon reception of a NoteOn.
  MIDI.setHandleNoteOn(HandleNoteOn);  // Put only the name of the function
  MIDI.setHandleNoteOff(HandleNoteOff);  // Put only the name of the function
}


void loop() {
  // Call MIDI.read the fastest you can for real-time performance.
  MIDI.read();
  /*digitalWrite(13, HIGH);   // set the LED on
  delay(400);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(400);              // wait for a second*/
  // There is no need to check if there are messages incoming if they are bound to a Callback function.
}

Get rid of the delay's in your code, they might cause losing bytes as they are blocking.

You should also post a link to the midi lib you use

Not a root cause, but please keep comments and code in sync otherwise comments make no sense

// Initiate MIDI communications, listen to  channel 15
  MIDI.begin(14);

Thanks for the reply!

The library is MIDI 3.2, we found it here --> Arduino Playground - HomePage

This is complete code running on KUBASE:

#include <MIDI.h>

int Led2 = 2;
int Led3 = 3;
int Led4 = 4;
int Led5 = 5;
int Led6 = 6;
int Led7 = 7;
int Led8 = 8;
int Led9 = 9;
int Led10 = 10;
int Led11 = 11;

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,

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

// Do whatever you want when you receive a Note On.

//--------------------**tecla DO central**----------------DIGITAL--------------------------
  if (pitch == 60)    
    { 
    digitalWrite(Led2, HIGH);
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla RE central**---------------PWM-------------------------------
  if (pitch == 61) 
    { 
    analogWrite(Led3, 2*velocity); 
      //delay(45); 
     }      
    
//-----------------------------------------------------------------------------------------
 
//--------------------**tecla MI central**----------------DIGITAL--------------------------
  if (pitch == 62)    
    { 
    digitalWrite(Led4, HIGH);
    }
     
//-----------------------------------------------------------------------------------------

//--------------------**tecla FA central**---------------PWM-------------------------------
  if (pitch == 63) 
    { 
    analogWrite(Led5, 2*velocity); 
      //delay(45); 
    }
//----------------------------------------------------------------------------------------- 

//--------------------**tecla SOL central**---------------PWM-------------------------------
  if (pitch == 64) 
    { 
      analogWrite(Led6, 2*velocity); 
      //delay(45); 
    }
//----------------------------------------------------------------------------------------- 
 
//--------------------**tecla LA central**----------------DIGITAL--------------------------
  if (pitch == 65)    
    { 
    digitalWrite(Led7, HIGH);
    }
    
//----------------------------------------------------------------------------------------- 
 
//--------------------**tecla SI central**----------------DIGITAL--------------------------
  if (pitch == 66)    
    { 
    digitalWrite(Led8, HIGH);
    }

 //-----------------------------------------------------------------------------------------
 
//--------------------**tecla DO**---------------PWM---------------------------------------
  if (pitch == 67) 
    { 
    analogWrite(Led9, 2*velocity); 
      //delay(45); 
    }
 //-----------------------------------------------------------------------------------------

//--------------------**tecla RE **---------------PWM--------------------------------------
  if (pitch == 68) 
    { 
    analogWrite(Led10, 2*velocity); 
      //delay(45); 
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla MI**---------------PWM---------------------------------------
  if (pitch == 69) 
    { 
    analogWrite(Led11, 2*velocity); 
      //delay(45); 
    }
//-----------------------------------------------------------------------------------------
 
}

void HandleNoteOff(byte channel, byte pitch, byte velocity)
{
//--------------------**tecla DO central**----------------DIGITAL--------------------------
  if (pitch == 60)    
    { 
    digitalWrite(Led2, LOW);
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla RE central**---------------PWM-------------------------------
  if (pitch == 61) 
    { 
     analogWrite(Led3, LOW); 
      //delay(45); 
    }
 //-----------------------------------------------------------------------------------------
 
//--------------------**tecla MI central**----------------DIGITAL--------------------------
  if (pitch == 62)    
    { 
    digitalWrite(Led4, LOW);
    }
 //-----------------------------------------------------------------------------------------

//--------------------**tecla FA central**---------------PWM-------------------------------
  if (pitch == 63) 
    { 
    analogWrite(Led5, LOW); 
      //delay(45); 
    }
//----------------------------------------------------------------------------------------- 

//--------------------**tecla SOL central**---------------PWM-------------------------------
  if (pitch == 64) 
    {
    analogWrite(Led6, LOW); 
      //delay(45); 
    }
//----------------------------------------------------------------------------------------- 
 
//--------------------**tecla LA central**----------------DIGITAL--------------------------
  if (pitch == 65)    
    { 
    digitalWrite(Led7, LOW);
    }
//----------------------------------------------------------------------------------------- 
 
//--------------------**tecla SI central**----------------DIGITAL--------------------------
  if (pitch == 66)    
    { 
    digitalWrite(Led8, LOW);
    }
//-----------------------------------------------------------------------------------------
 
//--------------------**tecla DO**---------------PWM---------------------------------------
  if (pitch == 67) 
    { 
    analogWrite(Led9, LOW); 
      //delay(45); 
    }
 //-----------------------------------------------------------------------------------------

//--------------------**tecla RE **---------------PWM--------------------------------------
  if (pitch == 68) 
    { 
    analogWrite(Led10, LOW); 
      //delay(45); 
    }
//-----------------------------------------------------------------------------------------

//--------------------**tecla MI**---------------PWM---------------------------------------
  if (pitch == 69) 
    { 
    analogWrite(Led11, LOW); 
      //delay(45); 
    }
//-----------------------------------------------------------------------------------------
}
void setup() {
  
  pinMode(Led2,OUTPUT);
  pinMode(Led3,OUTPUT);
  pinMode(Led4,OUTPUT);
  pinMode(Led5,OUTPUT);
  pinMode(Led6,OUTPUT);
  pinMode(Led7,OUTPUT);
  pinMode(Led8,OUTPUT);
  pinMode(Led9,OUTPUT);
  pinMode(Led10,OUTPUT);
  pinMode(Led11,OUTPUT);

  // Initiate MIDI communications, listen to  channel 14
  MIDI.begin(14);    
  
  // Connect the HandleNoteOn function to the library, so it is called upon reception of a NoteOn.
  MIDI.setHandleNoteOn(HandleNoteOn);  // Put only the name of the function
  MIDI.setHandleNoteOff(HandleNoteOff);  // Put only the name of the function
}


void loop() {
  // Call MIDI.read the fastest you can for real-time performance.
  MIDI.read();
   // There is no need to check if there are messages incoming if they are bound to a Callback function.
}

The code running on MPC is exactly the same but we comment all the references to NOTE OFF.

Thank you so much

Does anybody checked the polyphony? that's, the ability to play two or more notes simultaneously. My prototype didn't does, I must shift a little bit the timing of notes ...

one of the things I had to do recently was turn the Thru function off. That helped my project.

The only other thing I could think of would be that the MIDI buffers are getting full?

I'd use MIDI OX, plug the mpc directly to the PC and look at the data it's sending. MIDI timing messages may be eating up your buffer space.

That's just a shot in the dark, I'm not sure if that's it or not.

Thanks for replies...

There are some customized settings in the midi 3.2 library. It is configured as follow:

#define COMPILE_MIDI_IN         1           // Set this setting to 1 to use the MIDI input.
#define COMPILE_MIDI_OUT        0           // Set this setting to 1 to use the MIDI output. 
#define COMPILE_MIDI_THRU       0           // Set this setting to 1 to use the MIDI Soft Thru feature
                                            // Please note that the Thru will work only when both COMPILE_MIDI_IN and COMPILE_MIDI_OUT set to 1.


#define USE_SERIAL_PORT         Serial      // Change the number (to Serial1 for example) if you want
                                            // to use a different serial port for MIDI I/O.


#define USE_RUNNING_STATUS	0		// Running status enables short messages when sending multiple values
                                            // of the same type and channel.
                                            // Set to 0 if you have troubles with controlling you hardware.


#define USE_CALLBACKS           1           // Set this to 1 if you want to use callback handlers (to bind your functions to the library).
                                            // To use the callbacks, you need to have COMPILE_MIDI_IN set to 1

#define USE_1BYTE_PARSING       1           // Each call to MIDI.read will only parse one byte (might be faster).


// END OF CONFIGURATION AREA 
// (do not modify anything under this line unless you know what you are doing)


#define MIDI_BAUDRATE			31250

#define MIDI_CHANNEL_OMNI		0
#define MIDI_CHANNEL_OFF		17			// and over

#define MIDI_SYSEX_ARRAY_SIZE	255			// Maximum size is 65535 bytes.

We are thinking with this parameters just the MIDI IN is working. Perhaps isn't enough.
We are going to test a monophonic sequence in order to check the polyphony thing.
About the MIDI buffer space, long time ago we check a simple single sequence and it seems good (I attach the results...)