BASS.NET API for the Un4seen BASS Audio LibraryMIDIOUTPROC DelegateBASS.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: 2.4.12.0
Syntax

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

Parameters

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

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.

Examples

VB
Private _midiProc As MIDIOUTPROC
Private _midiOutHandle As IntPtr
...
' Open the Midi device #2
_midiProc = New MIDIOUTPROC(AddressOf MyMidiProc)
Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 2, _midiProc, 0)
If ret = MIDIError.MIDI_OK Then
  ' output ready
End If
...
' when not needed anymore...stop the device
Midi.MIDI_OutReset(_midiOutHandle)
' and close the device
Midi.MIDI_OutClose(_midiOutHandle)
...

Private Sub Send(handle As Integer, message As Integer)
  Dim result As Integer = MIDI_OutShortMsg(handle, message)
End Sub

Private Sub SendSysExBuffer(handle As IntPtr, data() As Byte)
  Dim header As New MIDI_HEADER(data)
  header.Prepare(False, handle)
  ' If the header was perpared successfully.
  If header.HeaderPtr <> IntPtr.Zero Then
    ' send a system-exclusive message to the output device
    Midi.MIDI_OutLongMsg(handle, header.HeaderPtr)
  End If
End Sub

Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
  ' handle all Midi messages here
  If msg = MIDIMessage.MOM_OPEN Then
    ' nothing to do
  Else
    If msg = MIDIMessage.MOM_CLOSE Then
      ' handle is from now on invalid
    Else
      If msg = MIDIMessage.MOM_DONE Then
        ' process the message...
        ' param1 will contain the pointer to the MIDI_HEADER
        Dim header As New MIDI_HEADER(param1)
        Dim data As Byte() = header.Data
        header.Unprepare(False, handle)
        ...
        ' or
        Dim sysExMsg As New MidiSysExMessage(False, handle, param1)
        ...
      End If 
    End If
  End If
End Sub
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
Midi.MIDI_OutReset(_midiOutHandle);
// and close the device
Midi.MIDI_OutClose(_midiOutHandle);
...

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

Reference