BASS.NET API for the Un4seen BASS Audio Library


BASS.NET API for the Un4seen BASS Audio Library
Represents the general callback delegate for handling Midi Output messages.

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

public delegate void MIDIOUTPROC(
	IntPtr handle,
	MIDIMessage msg,
	IntPtr instance,
	IntPtr param1,
	IntPtr param2


Type: SystemIntPtr
Handle to the MIDI output device.
Type: radio42.Multimedia.MidiMIDIMessage
MIDI output message (one of the MIDIMessage).
Type: SystemIntPtr
Instance data supplied with the MIDI_OutOpen(IntPtr, Int32, MIDIOUTPROC, IntPtr) method.
Type: SystemIntPtr
Message parameter 1.
Type: SystemIntPtr
Message parameter 2.

NOTE: instance, param1 and param2 are implemented here as IntPtr values for maximum Win32 and Win64 compatibility. If the parameters are actually numerial values you might use the ToInt32() resp. ToInt64() members to convert to these values.

The meaning of the param1 and param2 parameters is specific to the message type. The MOM_DONE message might be used with the MidiSysExMessage class to construct and unpack the message into it's components.

If param1 contains a pointer to a MIDI_HEADER structure you might use the MIDI_HEADER constructor overload taking a headerPtr in order to create an instance of a MIDI_HEADER in such case.

Applications should not call any system-defined functions from inside a callback function, except for MIDI_OutLongMsg(IntPtr, IntPtr), MIDI_OutShortMsg(IntPtr, Int32). Calling other wave functions will cause deadlock.

Also note, that you should not make any GUI control changes within this procedure. If needed use an Invoke to make sure to execute GUI changes in the related GUI thread.


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)
  // output ready
// when not needed anymore...stop the device
// and close the device

private void Send(int handle, int message)
  int result = MIDI_OutShortMsg(handle, message);

private void SendSysExBuffer(IntPtr handle, byte[] data)
  MIDI_HEADER header = new MIDI_HEADER(data);
  header.Prepare(false, handle);
  // If the header was perpared successfully.
  if (header.HeaderPtr != IntPtr.Zero)
    // send a system-exclusive message to the output device
    Midi.MIDI_OutLongMsg(handle, 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);
    byte[] data = header.Data;
    header.Unprepare(false, handle);
    // or
    MidiSysExMessage sysExMsg = new MidiSysExMessage(false, handle, param1);
See Also