80.5.4 Sending MIDI Messages

Once you open a MIDI output device, you can begin sending it MIDI messages using the following functions:

Function Description

midiOutLongMsg Sends a buffer of MIDI data to the specified MIDI output device. Use this function to send multiple MIDI events, including system exclusive messages, to a MIDI device.
midiOutShortMsg Sends a MIDI message to a specified MIDI output device.
midiOutReset Turns off all notes on all channels for a specified MIDI output device. Any pending system-exclusive buffers are marked as done and returned to the application.

Use midiOutShortMsg to send any MIDI message (except for system-exclusive messages). This function takes an HMIDIOUT parameter specifying the MIDI output device to send the message to, and a DWORD for the MIDI message. The message is packed into the DWORD, as shown in the following illustration:

This illustration is not available for this release

The two MIDI data bytes are optional, depending on the MIDI status byte. The following code fragment uses midiOutShortMsg to send a given MIDI event to a given MIDI output device:

/* Sends a given MIDI event to the given output device

*/

UINT sendMIDIEvent(hMidiOut, bStatus, bData1, bData2)

HMIDIOUT hMidiOut; // handle to the output device

BYTE bStatus; // MIDI status byte

BYTE bData1; // first MIDI data byte

BYTE bData2; // second MIDI data byte

{

union {

DWORD dwData;

BYTE bData[4];

} u;

/* Construct the MIDI message */

u.bData[0] = bStatus;

u.bData[1] = bData1;

u.bData[2] = bData2;

u.bData[3] = 0;

/* Send the message */

return midiOutShortMsg(hMidiOut, u.dwData);

}

Note:

MIDI output drivers are not required to verify data before sending it to an output port. It is up to applications to ensure only valid data is sent using midiOutShortMsg.