BASS.NET API for the Un4seen BASS Audio LibraryMidiMIDI_InOpen Method BASS.NET API for the Un4seen BASS Audio Library
Opens a MIDI input device.

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

public static MIDIError MIDI_InOpen(
	ref IntPtr handle,
	int deviceID,
	MIDIINPROC proc,
	IntPtr user,
	MIDIFlags flags
)

Parameters

handle
Type: SystemIntPtr
Returns the MIDI input handle. The handle is used to identify the device in calls to other MIDI input functions.
deviceID
Type: SystemInt32
Identifier of the MIDI input device to be opened (see MIDI_InGetDevCaps(Int32, MIDI_INCAPS) for details).
proc
Type: radio42.Multimedia.MidiMIDIINPROC
The MIDIINPROC callback delegate to use (which will receive all messages). For more information on the callback function, see MIDIINPROC.
user
Type: SystemIntPtr
User instance data passed to the callback function.
flags
Type: radio42.Multimedia.MidiMIDIFlags
A combination of the following (see MIDIFlags):
MIDI_IO_STATUSWhen this parameter is also specified with MIDI_CALLBACK_FUNCTION, then MIM_MOREDATA messages are sent to the callback function as well as MIM_DATA messages.
MIDI_CALLBACK_FUNCTIONThe proc parameter is a callback procedure address.
MIDI_CALLBACK_NULLThere is no callback mechanism (proc must be ).

Return Value

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

You only need to set the MIDI_IO_STATUS flag if needed, since the other flags are automatically set according to the given proc.

To determine the number of MIDI input devices present in the system, use the MIDI_InGetNumDevs function. The device identifier specified by deviceID varies from zero to one less than the number of devices present.

If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of MIDI input (see MIDIMessage): MIM_OPEN, MIM_CLOSE, MIM_DATA, MIM_LONGDATA, MIM_ERROR, MIM_LONGERROR, and MIM_MOREDATA.

If you use the MIDI_IO_STATUS flag with this method, the system uses the MIM_MOREDATA message to alert your application's callback function when it is not processing MIDI data fast enough to keep up with the input device driver. If your application processes MIDI data in a separate thread, boosting the thread's priority can have a significant impact on the application's ability to keep up with the data flow.

Examples

VB
Private _midiProc As MIDIINPROC
Private _midiInHandle As IntPtr
...
' Open the Midi device #1
_midiProc = New MIDIINPROC(AddressOf MyMidiProc)
Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 1, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
If ret = MIDIError.MIDI_OK Then
  ' Start the device
  ret = Midi.MIDI_InStart(_midiInHandle)
End If
...
' when not needed anymore...stop the device
Midi.MIDI_InReset(_midiInHandle)
' and close the device
Midi.MIDI_InClose(_midiInHandle)
...
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.MIM_OPEN Then
    ' nothing to do
  Else
    If msg = MIDIMessage.MIM_CLOSE Then
      ' handle is from now on invalid
    Else
      If msg = MIDIMessage.MIM_DATA Then
        ' process the message...
        Dim p1 As Integer = param1.ToInt32()
        Dim p2 As Integer = param2.ToInt32()
        ...
      Else
        If msg = MIDIMessage.MIM_MOREDATA Then
          ' we are not fast enough in this callback to keep up...
          ' the input device is sending messages to fast
          ...
        Else
          If msg = MIDIMessage.MIM_LONGDATA Then
            ' process the message...
            ...
          Else
            If msg = MIDIMessage.MIM_ERROR Then
              ' process the invalid message...
              ...
            Else
              If msg = MIDIMessage.MIM_LONGERROR Then
                ' process the invalid message...
                ...
              End If
            End If 
          End If
        End If
      End If
    End If
  End If
End Sub
private MIDIINPROC _midiProc;
private IntPtr _midiInHandle;
...
// Open the Midi device #1
_midiProc = new MIDIINPROC(MyMidiProc);
MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
if (ret == MIDIError.MIDI_OK)
{
  // Start the device
  ret = Midi.MIDI_InStart(_midiInHandle);
}
...
// when not needed anymore...stop the device
Midi.MIDI_InReset(_midiInHandle);
// and close the device
Midi.MIDI_InClose(_midiInHandle);
...
public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
{
  // handle all Midi messages here
  if (msg == MIDIMessage.MIM_OPEN)
  {
    // nothing to do
  }
  else if (msg == MIDIMessage.MIM_CLOSE)
  {
    // handle is from now on invalid
  }
  else if (msg == MIDIMessage.MIM_DATA)
  {
    // process the message...
    int p1 = param1.ToInt32();
    int p2 = param2.ToInt32();
    ...
  }
  else if (msg == MIDIMessage.MIM_MOREDATA)
  {
    // we are not fast enough in this callback to keep up...
    // the input device is sending messages to fast
    ...
  }
  else if (msg == MIDIMessage.MIM_LONGDATA)
  {
    // process the message...
    ...
  }
  else if (msg == MIDIMessage.MIM_ERROR)
  {
    // process the invalid message...
    ...
  }
  else if (msg == MIDIMessage.MIM_LONGERROR)
  {
    // process the invalid message...
    ...
  }
}
See Also

Reference