Managing MIDI Thru

You can connect a MIDI input device directly to a MIDI output device so that
when the input device receives an MIM_DATA message, the system sends a message with the same MIDI event data to the
output device driver. To connect a MIDI output device to a MIDI input device, use
the midiConnectfunction.

To achieve the best possible performance with multiple outputs, an application
can choose to supply a special form of MIDI output driver, called a thru driver. Although the system allows only one MIDI output device to be connected to a
MIDI input device, multiple MIDI output devices can be connected to a thru
driver. An application on such a system could connect the MIDI input device to this
thru device and connect the MIDI thru device to as many MIDI output devices as
needed. For more information about thru drivers, see the Windows device-driver
documentation.

Using Messages to Manage MIDI Recording

The following messages can be sent to a window or thread callback procedure
for managing MIDI recording:

Sent when a MIDI input device is opened by using the midiInOpen function.

A wParam parameter and an lParam parameter are associated with each of these messages. The wParam parameter always specifies the handle of an open MIDI device. The lParam parameter is unused for the MM_MIM_CLOSE and MM_MIM_OPEN messages.

For the MM_MIM_LONGDATA message, lpMidiHdr specifies an address of a MIDIHDR structure that identifies the buffer for system-exclusive messages. The
buffer may not be completely filled, because the size of the system-exclusive
messages is usually not known before being recorded and because buffers whose total
size can contain the largest expected message must be allocated. To determine
the amount of valid data present in the buffer, use the dwBytesRecorded member of the MIDIHDR structure.

Using a Callback Function to Manage MIDI Recording

You can define your own callback function to manage recording for MIDI input
devices. The callback function is documented as MidiInProc.

The following messages can be sent to the wMsg parameter of the MidiInProc callback function:

Sent when the MIDI input device is opened by using the midiInOpen function.

These messages are similar to those sent to window procedure functions, but
the parameters are different. A handle of the open MIDI device is passed as a
parameter to the callback function, along with the doubleword of instance data
that was passed by using midiInOpen.

For the MIM_LONGDATA message, lpMidiHdr specifies an address of a MIDIHDR structure that identifies the buffer for system-exclusive messages. The
buffer might not be completely filled. To determine the amount of valid data present
in the buffer, use the dwBytesRecorded member of the MIDIHDR structure.

After the device driver is finished with a data block, you can clean up and
free the data block.