MidiMessage class overview
MidiMessage is a class for handling MIDI messages and their
associated time stamps, primarily for use with the MIDI input classes,
such as MidiInPort and MidiInput. There are two public
data fields which can be accessed:
- unsigned long time -- which can store a
timestamp associated with the MIDI message.
- unsigned long data -- which can store a
MIDI command message with up to 3 additional parameters.
The MidiMessage class was designed for the
requirements/abilities of the Microsoft MIDI driver for Windows 95.
The data storage field is broken down into four bytes of MIDI
data, as shown in figure 1 below. Depending on the value of the
command byte, the various parameters are either pertinent or ignored
in the MIDI message. For example, a note on message will use two
parameters: (1) key number and (2) attack velocity, while other
message such as active sensing (used by Yamaha) are commands which
do not have any additional parameters. The getParameterCount
function will return how many parameters are valid for the given
command. The function will return -1 if the MIDI command
is invalid or if the function is unsure of the correct count.
MidiMessage Figure 1: MidiMessage data fields and their components
|
|
|
System exclusive messages are handled separately although the
MidiInput uses a special convention to handle system exclusive
messages based on the MIDIMessage class.
MidiMessage Example 1: creating a note-on command. |
|
|
MidiMessage message;
// create a note-on command on MIDI channel 1.
message.p0() = 0x90; // 9 digit = note-on, 0 digit = chan 1
// set the MIDI key number to middle C (=60)
message.p1() = 60;
// set the attack velocity of the note to 127
message.p2() = 127;
// weird way of doing the previous three instructions:
message.data = 0x903c7f00; // 0x3c = 60; 0x7f = 127
|
|