Module mididi.def

mididi.def contains definition enums and types important to MIDI files.

The implementation (and some of the documentation) is based on this specification:



Name Kind Description
TrackFormat enum description
isMIDIEvent function description
isSysExEvent function description
isMetaEvent function description
isChannelMessage function description
isSystemMessage function description
getDataLength function description
ChannelMessageType enum description
isChannelVoiceMessage function description
isChannelModeMessage function description
SystemMessageType enum description
isSystemCommonMessage function description
isSystemCommonMessage function description
isSystemRealTimeMessage function description
isSystemRealTimeMessage function description
MetaEventType enum description

enum TrackFormat

TrackFormat is the MIDI data's format.

This format is given in the header chunk of a MIDI file.


If the format is single, that means the MIDI data consists of a header chunk followed by a single track chunk.


If the format is simultaneous, that means the MIDI track data consists of multiple tracks, running in parallel.


If the format is sequential, that means the MIDI track data consists of multiple tracks, running sequentially.

function bool isMIDIEvent(ubyte statusByte)

function bool isSysExEvent(ubyte statusByte)

function bool isMetaEvent(ubyte statusByte)

A track event is one of the following:

  • a MIDI event, meaning it carries around any message (channel or system), except system exclusive messages;
  • a system exclusive event, which offers an escape to transmit arbitrary bytes;
  • a meta event, meaning it carries around other meta information.

Use isMIDIEvent(), isSysExEvent() and isMetaEvent() to find which kind of event it is from its status byte.

See also: mididi.types.TrackEvent; mididi.types.MIDIEvent, mididi.types.SysExEvent and mididi.types.MetaEvent.

function bool isChannelMessage(ubyte statusByte)

function bool isSystemMessage(ubyte statusByte)

isChannelMessage() and isSystemMessage() are used to find if a MIDI event is a channel message or a system message.

In turn, a channel message can be either a channel voice message or a channel mode message. A system message can be either a system common message or a system realtime message.

function ulong getDataLength(ubyte statusByte)

Returns: how many data bytes should be read for the message with status byte statusByte Preconditions: statusByte must be from a MIDI event

enum ChannelMessageType

function bool isChannelVoiceMessage(ubyte statusByte, ubyte[2] dataBytes)

function bool isChannelModeMessage(ubyte statusByte, ubyte[2] dataBytes)

ChannelMessageType enumerates the possible types of channel messages.

The underlying value of this enumeration is the four upper bits of the status byte (and always starts with a 1 bit). After all, a channel message has the message type in the four upper bits and a channel identifier in the four lower bits of the status byte.

The functions isChannelVoiceMessage() and isChannelModeMessage() need the data bytes in addition to the status byte to identify if a channel message is a voice message or a mode message, because some status byte values overlap (see for example ChannelMessageType.controlChangeOrMode).

See also: mididi.def.isChannelMessage


NOTE: this kind of channel message can be either a Control Change message or a Channel Mode message, depending on the data bytes. Use isChannelModeMessage() to find out which it is.

enum SystemMessageType

function bool isSystemCommonMessage(mididi.def.SystemMessageType type)

function bool isSystemCommonMessage(ubyte statusByte)

function bool isSystemRealTimeMessage(mididi.def.SystemMessageType type)

function bool isSystemRealTimeMessage(ubyte statusByte)

SystemMessageType enumerates the possible types of system message. Some of these are system common messages, others are system realtime messages.

If for a ubyte x we have that isSystemMessage(x) is true, then it can be safely cast to SystemMessageType using cast(SystemMessageType) x.

A system message is either a a "system common message" or a "system real-time message". You can use isSystemCommonMessage(x) and isSystemRealTimeMessage(x) to identify which is true, or compare to the enum members to find out the exact message type.

See also: mididi.def.isSystemMessage


This event can give any type of information specific to the manufacturer.

A system exclusive message can consist of several packets, where each packet is placed in one event. Each event then starts with the byte 0xF7, and the final event is also terminated by 0xF7.

enum MetaEventType

MetaEventType enumerates the possible meta event types.

Cast to ubyte to get the underlying value.

Note: do not use a value of this type in a final switch, because it might have a value that is not identified in this enum, since values can always be added later.

See also: mididi.def.isMetaEvent
















Click here to view the source of this module.