Read MIDI file from sd card and play - code ?

Umm, I meant, it should not generate tones, it should only read midi file and then send midi data to servo movings and leds.

I am sure, arduino can play complex midi files. Because reprap printers also use atmega 2560 and gcode files are very big, above megabytes.

I think there is a problem with loading file from sd card.

When I play midi file which is 225 bytes big, it works well
x-y-a.com/simple.jpg

When I play midi file which is 3,21 Kbytes big, it works very slow
http://x-y-a.com/complex.jpg

So that mean, when I play mozard midi file, so it is absoluty impossible to play it.

I think this

int MD_MIDIFile::load ( void )

tries to load the entire midi file, but the arduino memory is too small. So it should not load the entire midi file, it should read only in chunks. Am I right ?

I am not c++ expert, but this is the code from MD_MIDIFile::load and I am not sure, what exactly this code do.

int MD_MIDIFile::load() 
// Load the MIDI file into memory ready for processing
{
  uint32_t  dat32;
  uint16_t  dat16;
  
  if (_fileName[0] == '\0')  
    return(0);

  // open the file for reading:
  if (!_fd.open(_fileName, O_READ)) 
    return(2);

  // Read the MIDI header
  // header chunk = "MThd" + <header_length:4> + <format:2> + <num_tracks:2> + <time_division:2>
  {
    char    h[MTHD_HDR_SIZE+1]; // Header characters + nul
  
    _fd.fgets(h, MTHD_HDR_SIZE+1);
    h[MTHD_HDR_SIZE] = '\0';
    
    if (strcmp(h, MTHD_HDR) != 0)
  {
    _fd.close();
      return(3);
  }
  }