BASS.NET API for the Un4seen BASS Audio Library

MidiMIDI_OutShortMsg Method

BASS.NET API for the Un4seen BASS Audio Library
Sends a short MIDI message to the specified MIDI output device.

Namespace:  radio42.Multimedia.Midi
Assembly:  Bass.Net (in Bass.Net.dll) Version:

public static MIDIError MIDI_OutShortMsg(
	IntPtr handle,
	int message


Type: SystemIntPtr
Handle to the MIDI output device.
Type: SystemInt32
MIDI message. The message is packed into a double word value with the first byte of the message in the low-order byte. The message is packed into this parameter as follows:

High-Word: High-order byte: Not used. Low-order byte: The second byte of MIDI data (when needed).

Low-Word: High-order byte: The first byte of MIDI data (when needed). Low-order byte: The MIDI status.

The two MIDI data bytes are optional, depending on the MIDI status byte. When a series of messages have the same status byte, the status byte can be omitted from messages after the first one in the series, creating a running status.

Return Value

Type: MIDIError
Returns 0 if successful or an error code otherwise. For possible error values see MIDIError.

This function is used to send any MIDI message except for system-exclusive or stream messages.

This function might not return until the message has been sent to the output device. You can send short messages while streams are playing on the same device (although you cannot use a running status in this case).

You might used the MidiShortMessage class to construct and or pack the message with it's components.


private MIDIOUTPROC _midiProc;
private IntPtr _midiOutHandle;
// Open the Midi device #2
_midiProc = new MIDIOUTPROC(MyMidiProc);
MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0);
if (ret == MIDIError.MIDI_OK)
  // device opened and ready
// When not needed anymore...stop the device
// and close the device
private void SendShortMessage(int message)
  MIDI_OutShortMsg(_midiOutHandle, message);

private void SendSysExMessage(byte[] data)
  MIDI_HEADER header = new MIDI_HEADER(data);
  header.Prepare(false, _midiOutHandle);
  // If the header was perpared successfully.
  if (header.HeaderPtr != IntPtr.Zero)
    // send a system-exclusive message to the output device
    Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr);

public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
  // handle all Midi messages here
  if (msg == MIDIMessage.MOM_OPEN)
    // nothing to do
  else if (msg == MIDIMessage.MOM_CLOSE)
    // handle is from now on invalid
  else if (msg == MIDIMessage.MOM_DONE)
    // process the message...
    // param1 will contain the pointer to the MIDI_HEADER
    MIDI_HEADER header = new MIDI_HEADER(param1);
    // process the header if needed
    // and finally unprepare the header
    header.Unprepare(false, handle);
See Also