The MIDI set tempo meta message sets the tempo of a MIDI sequence in terms of microseconds per quarter note.
This message belongs to the category of MIDI meta messages. Since this is a meta message the MIDI event that carries this message may exist in MIDI files, but it is never sent over MIDI ports to a MIDI device.
This message consists of six bytes of data. The first byte is the status byte and has a hexadecimal value of 0xFF, which means that this is a meta message. The second byte is the meta message type 0x51 and signifies that this is a set tempo message. The third byte has the value 0x03, which means that there are three bytes remaining. The remaining three bytes carry the number of microseconds per quarter note.
The following is an example of a MIDI set tempo meta message.
0xFF 0x51 0x03 0x07 0xA1 0x20
The status byte 0xFF shows that this is a meta message. The second byte is the meta type 0x51 and signifies that this is a set tempo meta message. The third byte is 3, which means that there are three remaining bytes. These three bytes form the hexadecimal value 0x07A120 (500000 decimal), which means that there are 500,000 microseconds per quarter note.
Since there are 60,000,000 microseconds per minute, the message above translates to: set the tempo to 60,000,000 / 500,000 = 120 quarter notes per minute (120 beats per minute).
This message would normally appear in the first track chunk. If this message does not appear, the default tempo is 120 beats per minute as in the example above. This message is important if the MIDI time division is specified in "pulses per quarter note", as such MIDI time division defines the number of ticks per quarter note, but does not itself define the length of the quarter note. The length of the quarter note is then defined with the set tempo meta message described here.
Musical Instrument Digital Interface (MIDI)