Om  1.0.0
A universal framework for multimedia simulation
Public Types | Public Member Functions | Static Public Member Functions | List of all members
om::sound::base::MIDIMessage Class Reference

A class that represents a single MIDI message. More...

#include <omSoundMIDIMessage.h>

Public Types

enum  Type {
  NOTE_ON, NOTE_OFF, CONTROL_CHANGE, AFTERTOUCH,
  CHANNEL_PRESSURE, PITCH_WHEEL, PROGRAM_CHANGE, START,
  STOP, CONTINUE, UNDEFINED
}
 An enum which indicates the type of a MIDI message. More...
 

Public Member Functions

 MIDIMessage ()
 Create a default MIDI message with undefined type. More...
 
 MIDIMessage (Type newType)
 Create a MIDI message with the specified type with all other data members set to 0. More...
 
 MIDIMessage (Type newType, Index newChannel, UByte newData1)
 Create a MIDI message with the specified type, channel, and integral data member. More...
 
 MIDIMessage (Type newType, Index newChannel, Float newData2)
 Create a MIDI message with the specified type, channel, and floating point data member. More...
 
 MIDIMessage (Type newType, Index newChannel, UByte newData1, Float newData2)
 Create a MIDI message with the specified type, channel, integral data member, and floating point data member. More...
 
Type getType () const
 Return the type of this MIDI message. More...
 
Index getChannel () const
 Return the number of the channel associated with this MIDI message (if applicable). More...
 
UByte getData1 () const
 Return the integer data element for this midi message. More...
 
Float getData2 () const
 Return the floating-point data element for this midi message. More...
 
UByte getNote () const
 Return the note number associated with this MIDI message. More...
 
Float getVelocity () const
 Return the note velocity associated with this MIDI message. More...
 
UByte getControl () const
 Return the control index associated with this MIDI message. More...
 
Float getControlValue () const
 Return the control value associated with this MIDI message. More...
 
Float getPressure () const
 Return the pressure value associated with this MIDI message. More...
 
Float getPitch () const
 Return the pitch shift amount associated with this MIDI message. More...
 
UByte getProgram () const
 Return the program index associated with this MIDI message. More...
 

Static Public Member Functions

static Bool fromBytes (const UByte *bytes, MIDIMessage &message, Size &messageLengthInBytes)
 Parse a MIDI message object from a pointer to an array of bytes for the MIDI message. More...
 
static Bool toBytes (const MIDIMessage &message, UByte *bytes, Size &messageLengthInBytes)
 Convert the specified MIDIMessage object to a sequence of MIDI data stream bytes. More...
 

Detailed Description

A class that represents a single MIDI message.

This implementation does not support SysEx MIDI messages. All common MIDI message types are supported. The message contains a type, a channel index on which the message occurred, an integer data member, and a floating-point data member. The usage of the data members depends on the type of the MIDI message.

Member Enumeration Documentation

An enum which indicates the type of a MIDI message.

Enumerator
NOTE_ON 

A message type indicating that a note was turned on.

NOTE_OFF 

A message type indicating that a note was turned off.

CONTROL_CHANGE 

A message type indicating that a control parameter was changed.

AFTERTOUCH 

A message type indicating a change in a key's current pressure.

CHANNEL_PRESSURE 

A message type indicating a change in a MIDI channel's global pressure.

PITCH_WHEEL 

A message type indicating a change in the pitch wheel's position.

PROGRAM_CHANGE 

A message type indicating that the current patch should be changed.

START 

A message type indicating that a slave device should start playback from the start of a song.

STOP 

A message type indicating that a slave device should stop playback.

CONTINUE 

A message type indicating that a slave device should continue playback from its current position.

UNDEFINED 

An undefined message type.

Constructor & Destructor Documentation

om::sound::base::MIDIMessage::MIDIMessage ( )
inline

Create a default MIDI message with undefined type.

om::sound::base::MIDIMessage::MIDIMessage ( Type  newType)
inline

Create a MIDI message with the specified type with all other data members set to 0.

om::sound::base::MIDIMessage::MIDIMessage ( Type  newType,
Index  newChannel,
UByte  newData1 
)
inline

Create a MIDI message with the specified type, channel, and integral data member.

om::sound::base::MIDIMessage::MIDIMessage ( Type  newType,
Index  newChannel,
Float  newData2 
)
inline

Create a MIDI message with the specified type, channel, and floating point data member.

om::sound::base::MIDIMessage::MIDIMessage ( Type  newType,
Index  newChannel,
UByte  newData1,
Float  newData2 
)
inline

Create a MIDI message with the specified type, channel, integral data member, and floating point data member.

Member Function Documentation

Type om::sound::base::MIDIMessage::getType ( ) const
inline

Return the type of this MIDI message.

Index om::sound::base::MIDIMessage::getChannel ( ) const
inline

Return the number of the channel associated with this MIDI message (if applicable).

This value has no meaning if the message type is one with global effect, such as START, STOP, or CONTINUE.

UByte om::sound::base::MIDIMessage::getData1 ( ) const
inline

Return the integer data element for this midi message.

The information carried in this first data member is dependent on the message type:

  • NOTE_ON: The note number that is to be turned on, ranging from 0 to 127.
  • NOTE_OFF: The note number that is to be turned off, ranging from 0 to 127.
  • CONTROL_CHANGE: The index of the control, ranging from 0 to 127.
  • AFTERTOUCH: The note number which should have its pressure value updated, ranging from 0 to 127.
  • CHANNEL_PRESSURE: Unused.
  • PITCH_WHEEL: Unused.
  • PROGRAM_CHANGE: The index of the program to select, ranging from 0 to 127.
  • Otherwise: The data stored in this value has no meaning and should be ignored.
Float om::sound::base::MIDIMessage::getData2 ( ) const
inline

Return the floating-point data element for this midi message.

The information carried in this second data member is dependent on the message type:

  • NOTE_ON: The velocity of the note-on message, ranging from 0 to 1, 1 being the highest velocity.
  • NOTE_OFF: The release velocity of the note-on message, ranging from 0 to 1, 1 being the highest velocity.
  • CONTROL_CHANGE: The value that the control should be set to, ranging from 0 to 1.
  • AFTERTOUCH: The new pressure value that the aftertouch key should have, ranging from 0 to 1.
  • CHANNEL_PRESSURE: The new pressure value that the midi channel should have, ranging from 0 to 1.
  • PITCH_WHEEL: The pitch shift amount the midi channel should have, given a value from -1 to 1.
  • Otherwise: The data stored in this value has no meaning and should be ignored.
UByte om::sound::base::MIDIMessage::getNote ( ) const
inline

Return the note number associated with this MIDI message.

The returned note number is valid only if the message type is NOTE_ON, NOTE_OFF, or AFTERTOUCH.

Float om::sound::base::MIDIMessage::getVelocity ( ) const
inline

Return the note velocity associated with this MIDI message.

The returned note velocity is valid only if the message type is NOTE_ON or NOTE_OFF. The velocity is in the range [0,1], where 1 is the highest note velocity.

UByte om::sound::base::MIDIMessage::getControl ( ) const
inline

Return the control index associated with this MIDI message.

The returned control index is valid only if the message type is CONTROL_CHANGE.

Float om::sound::base::MIDIMessage::getControlValue ( ) const
inline

Return the control value associated with this MIDI message.

The returned value is valid only if the message type is CONTROL_CHANGE. The value is unitless and in the range [0,1].

Float om::sound::base::MIDIMessage::getPressure ( ) const
inline

Return the pressure value associated with this MIDI message.

The returned pressure is valid only if the message type is AFTERTOUCH or CHANNEL_PRESSURE. The pressure is in the range [0,1].

Float om::sound::base::MIDIMessage::getPitch ( ) const
inline

Return the pitch shift amount associated with this MIDI message.

The returned value is valid only if the message type is PITCH_WHEEL. The pitch shift amount is unitless and in the range [-1,1]. Users should define a mapping from this range to semitones, etc.

UByte om::sound::base::MIDIMessage::getProgram ( ) const
inline

Return the program index associated with this MIDI message.

The returned program index is valid only if the message type is PROGRAM_CHANGE.

static Bool om::sound::base::MIDIMessage::fromBytes ( const UByte bytes,
MIDIMessage message,
Size messageLengthInBytes 
)
static

Parse a MIDI message object from a pointer to an array of bytes for the MIDI message.

If the method succeeds, TRUE is returned and the output message parameter is set to be the parsed MIDI message. The length of the message in bytes is placed in the message length parameter.

If the method fails, indicating a parse error, FALSE is returned.

static Bool om::sound::base::MIDIMessage::toBytes ( const MIDIMessage message,
UByte bytes,
Size messageLengthInBytes 
)
static

Convert the specified MIDIMessage object to a sequence of MIDI data stream bytes.

If the method succeeds, TRUE is returned and the message data is written to the byte array pointer. The length of the message in bytes is placed in the message length parameter.

The output byte array must be at least 3 bytes long, the length of a standard (non-sysex) MIDI message.

If the method fails, indicating a conversion error, FALSE is returned.


The documentation for this class was generated from the following file: