Nick's Binary MIDI Arduino Format

Back to MIDI manipulation tool

All words are Little Endian

PrpertyDesc
Length - Time [UInt4] in miliseconds
Length - Events [UInt4] Number of events to follow in file
Events Consisting of 4 bytes:
[UInt1] Type (0x00=note_off, 0x01=note_on)
[UInt1] Note (Will only ever be 0-127)
[UInt2] Delta time to next event measured in milliseconds (Max 65 seconds)

Example Arduino Code to Read the output of MIDI Surgeon from an SD Card:

#include 
/* SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 */

File the_file;
void setup() {
  SD.begin(4);
  my_file = SD.open("sailors_hornpipe.nmid");
  byte[] the_buffer;

  unsigned long song_duration; //UInt4
  unsigned long song_events; //UInt4
  if(my_file){
    // Read song duration in milliseconds using little endian byte ordering.
    the_file.read(the_buffer,4);
    song_duration |= the_buffer[0]
    song_duration |= the_buffer[1] << 8
    song_duration |= the_buffer[2] << 16
    song_duration |= the_buffer[3] << 24
    
    // Read number of notes little endian byte ordering.
    the_file.read(the_buffer,4);
    song_events |= the_buffer[0]
    song_events |= the_buffer[1] << 8
    song_events |= the_buffer[2] << 16
    song_events |= the_buffer[3] << 24
  }
}

void loop() {
  
}