A MIDI event is a piece of data sent to a MIDI device to prompt it to do something at a certain time.
According to the MIDI protocol, a MIDI event should contain two pieces of information: 1) the number of MIDI ticks, also known as the MIDI delta time, which specifies at what time something should be done; and 2) the MIDI message, which specifies what should be done. For example, one MIDI event could specify that at 1 second in the sequence of MIDI events the MIDI device should play a certain note on some channel with a certain volume. Other MIDI events carry other information. Another MIDI event, for example, could specify that the title of a MIDI track is something.
The following is an example of a MIDI event.
0x50 0x90 0x26 0x3C
The 0x50 hexadecimal value is the event delta time and translates to the decimal value 80. MIDI devices will interpret this to mean that this even should occur 80 MIDI ticks after the previous event. A MIDI tick is an amount of time the length of which varies. The length of a MIDI tick in a MIDI file is defined, for example, by the time division of the MIDI file. For purposes of this example let us say that one tick is 3,125 microseconds. Then this even should occur 80 * 3,125 = 250 milliseconds, or a quarter of a second after the previous event.
The three bytes (0x90 0x26 0x3C) that follow the MIDI delta time are the MIDI message.
The first byte of the message (0x90) is the MIDI message status byte. In this particular case, the status byte contains a high nibble of 9 and will be interpreted as a MIDI note on message. This message will prompt the MIDI device to play a note. The low nibble of the status byte is 0 and hence the note will be played on channel 0.
Since this message is the note on message, the MIDI device will expect that the status byte is followed by two bytes. The first byte (0x26) is the note to be played and in this case it is a D in one of the lower octaves. The last byte is the note velocity (strength, accent, or volume depending on the design choices for the device) and in this case it is 0x3C = 60 decimal, which is about middle (velocity values range from 0 to 127).
MIDI delta time
The number of ticks in the example above was 80 decimal = 0x50 hexadecimal and it was carried by one byte in the MIDI event. According to the MIDI protocol, this number of ticks can be carried by any number of bytes. Each of these bytes has eight bits. If the top most significant bit of the byte is 1, then a MIDI device will expect that there are more delta time bytes to follow. If the top bit is zero the MIDI device will expect that the delta time is complete and what follows is the MIDI message. In the example above, 0x50 hexadecimal translates to the bits 01010000. The top bit of this byte is zero and hence a MIDI device will know that the delta time is complete.
Since the most significant bit of each byte in the MIDI delta time is used to determine whether the MIDI delta time continues in the next byte, only the following seven bits of each byte are used to define the delta time value (see example below).
Note that the MIDI delta time is "delta" time and not "absolute" time. It specifies the time after the previous event and not the time from the beginning of the MIDI sequence.
MIDI running status
It is permitted in the MIDI protocol to omit the status byte of a MIDI message. If the status byte is omitted, it will be assumed to be the same as the status byte of the message in the previous event. Most commonly, after sending / receiving a note on message with some velocity to play a note, MIDI devices can send or receive a note on message with zero velocity to turn off that same note. The status byte of the second note on message can be omitted as it is the same as the status byte of the previous note on message (assuming there are no messages in between). The MIDI device will know that the status byte is omitted as status bytes are at least 0x80 and hence have a most significant bit of 1, whereas notes in note on messages for example are at most 0x7F and have a most significant bit of 0.
The following is another example of a MIDI event.
0x83 0x60 0x26 0x00
In this example the MIDI delta time begins with 0x83 hexadecimal = 10000011 binary. The most significant bit is 1 and hence there is at least one more byte in the MIDI delta time. The second byte of the delta time then is 0x60 hexadecimal = 01100000. The most significant bit of this byte is 0 and hence the MIDI delta time is complete. The MIDI delta time value is determined by taking the lowest seven bits of each of the two bytes and is 0000011 1100000 = 0x01E0 hexadecimal = 480 decimal (number of ticks). Assuming as in the previous example that one tick is set to 3125 microseconds, this event should occur 480 * 3,125 = 1,500,000 microseconds or 1.5 seconds after the previous event.
Since the delta time is complete with the bytes 0x83 0x60, the bytes 0x26 0x00 must represent the MIDI message. Since 0x26 is not a valid MIDI status byte, the status byte of this message is omitted. If this message is the message that follows the one from the example above, then this is also a note on message with an omitted status byte. Then the note to be played is 0x26 (same as above) and the velocity with which the note should be played is 0x00 (zero), which means that this note will effectively be turned off.