BASS.NET API for the Un4seen BASS Audio Library

MidiMIDI_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.17.5
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

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