BASS.NET API for the Un4seen BASS Audio LibraryMidiMIDI_OutLongMsg Method BASS.NET API for the Un4seen BASS Audio Library
Sends a system-exclusive MIDI message to the specified MIDI output device.

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

public static MIDIError MIDI_OutLongMsg(
	IntPtr handle,
	IntPtr headerPtr
)

Parameters

handle
Type: SystemIntPtr
Handle to the MIDI output device.
headerPtr
Type: SystemIntPtr
Pointer to a MIDI_HEADER structure that identifies the MIDI buffer.

Return Value

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

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

Private Sub SendSysExMessage(data() As Byte)
  Dim header As New MIDI_HEADER(data)
  header.Prepare(False, _midiOutHandle)
  ' If the header was perpared successfully.
  If header.HeaderPtr <> IntPtr.Zero Then
    ' send a system-exclusive message to the output device
    Midi.MIDI_OutLongMsg(_midiOutHandle, 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)
        ' process the header if needed
        ...
        ' and finally unprepare the header
        header.Unprepare(False, handle)
      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)
{
  // device opened and ready
}
...
// When not needed anymore...stop the device
Midi.MIDI_OutReset(_midiOutHandle);
// and close the device
Midi.MIDI_OutClose(_midiOutHandle);
...
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

Reference