Midifile View on GitHub

MidiMessage class

home   »   documentation   »   classes

The MIDI message class contains the raw MIDI bytes which are stored in a Standard MIDI File. The class is inherited from vector, so all [STL vector class functions](http://www.cplusplus.com/reference/vector/vector) can be used in this class. The MidiEvent class inherits these function from the MidiMessage class.

The first byte in the MIDI message is expected to be a command byte, which is a byte in the range from 0x80 to 0xff. Running status is not allowed in MidiMessage class data, and any missing running status byte will be inserted into the message when reading from a MIDI file. Currently MIDI files cannot be written in running status mode by the MidiFile class, but if that is needed, then the MidiFile class will be responsible for removing the running status command byte as necessary from the MidiMessage data as it is being written to a file.

The command byte of a MIDI message is in the range from 0x80 to 0xff hexadecimal (128-255 decimal). Each command converts 16 bytes, such as 0x80 to 0x8f for the note-off command. The “8” for note-offs is the *command nibble”, which are the top four bits of the byte. The bottom nibble indicates the MIDI channel of the command, and ranges from 0x0 to 0xf hex (0 to 15 decimal). Thus, 0x80 is a note-off command on the first channel, 0x81 is the note-off command on the second channel, …, and 0x8f is the note-off command on the sixteenth channel.

There are seven MIDI commands from 0x80 to 0xe0 command nibbles, plus 16 miscellaneous commands starting with a 0xf0 nibble that don’t refer to MIDI channels in the bottom nibble. Each command has an expected number of parameter bytes after it, which are in the range from 0x00 to 0x7f hexadecimal (0 to 127 decimal). Here is a table summarizing the seven main MIDI commands and their required parameter count.

Command nibble Command name Parameter count Parameter meanings
0x80 Note off 2 key, off velocity
0x90 Note on 2 key, on velocity
0xA0 Aftertouch 2 key, pressure
0xB0 Continuous controller 2 controller number, controller value
0xC0 Patch change 1 instrument number
0xD0 Channel pressure 2 key, off velocity
0xE0 Pitch-bend 2 LSB, MSB

 

Public functions

isNoteOff — Return true if MIDI message is a note off message.
isNoteOn — Returns true if MIDI message is a note-on message.
isAftertouch — Returns true if MIDI message is an aftertouch message.
isController — Returns true if MIDI message is an controller message.
isTimbre — Returns true if MIDI message is a patch change.
isPressure — Returns true if MIDI message is an channel pressure message.
isPitchbend — Returns true if MIDI message is an pitch-bend message.
getChannelNibble — Return channel number of the MIDI command byte (offset from 0).
setChannelNibble — Set the channel nibble in a MIDI message command byte.
setCommand — Set the command byte and any parameters for a message.
getCommandByte — Return the command byte of the MIDI message.
setCommandByte — Set the command byte of a MIDI message.
getCommandNibble — Return the command nibble of the MIDI message.
setCommandNibble — Set the command nibble of a command byte.
setParameters — Set the message bytes after the command byte.
setSizeToCommand — Set the number of parameters given the stored command byte.
getSize — Returns the number of bytes in the MIDI message.
setSize — Change the size of the message byte list.
operatorEQUALS — Copy the contents of another MidiMessage.

 

Meta messages are not strictly MIDI messages, but pose as such within MIDI files. A meta message start with the command byte 0xff, followed by the meta message type and then the number of data bytes to follow in the message. The following functions relate to processing meta messages.

isMeta — Returns true if MIDI message is a meta message.
setMetaTempo — Create a tempo meta message from a tempo.
isTempo — Returns true if MIDI message is a tempo meta message.
getTempoBPM — Return the tempo in terms of quarter notes per minute.
getTempoMicro — Return the number of microseconds per quarter note.
getTempoSPT — Return the tempo in terms of seconds per tick.
getTempoSeconds — Return the number of seconds per quarter note.
getTempoTPS — Return the tempo in terms of ticks per second.

 

Keyboard shortcuts for this page:

  • ctrl++/= to open all function documentation entries.
  • ctrl+ to close all documentation.
  • ctrl+eto toggle display of all code examples.
  • shft+click will open documentation for a single method and close all other entries.