BASS.NET API for the Un4seen BASS Audio Library

MidiMIDI_InPrepareHeader Method

BASS.NET API for the Un4seen BASS Audio Library
Prepares a buffer for MIDI input.

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

public static MIDIError MIDI_InPrepareHeader(
	IntPtr handle,
	IntPtr headerPtr
)

Parameters

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

Return Value

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

Preparing a header that has already been prepared has no effect, and the function returns zero.

After the header has been prepared, do not modify the buffer. To free the buffer, use the MIDI_InUnprepareHeader(IntPtr, IntPtr) function.

Before using this function, you must set the data, bufferLength, and flags members of the MIDI_HEADER structure. The flags member must be set to zero.

For convenience the Prepare(Boolean, IntPtr) might also be used, which calls the method internally and returns the header pointer in the HeaderPtr member.

Examples

private MIDIINPROC _midiInProc;
private IntPtr _midiInHandle;
...
private void StartRecording()
{
  _midiInProc = new MIDIINPROC(MyMidiInProc);
  MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiInProc, 0, MIDIFlags.MIDI_IO_STATUS);
  if (ret == MIDIError.MIDI_OK)
  {
    // supply the device with 2 buffers
    AddSysExBuffer(_midiInHandle, 1024);
    AddSysExBuffer(_midiInHandle, 1024);
    ret = Midi.MIDI_InStart(_midiInHandle);
  }
}

// prepare receiving system-exclusive messages
private void AddSysExBuffer(IntPtr handle, int size)
{
  // prepare a empty midi header
  MIDI_HEADER header = new MIDI_HEADER(size);
  header.Prepare(true, handle);
  // If the header was perpared successfully.
  if (header.HeaderPtr != IntPtr.Zero)
  {
    // Add the buffer to the InputDevice.
    Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
  }
}

private void MyMidiInProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
{
  // handle all Midi messages here
  if (msg == MIDIMessage.MIM_DATA)
  {
    // process the short message...
    int p1 = param1.ToInt32();
    int p2 = param2.ToInt32();
    ...
    Console.WriteLine("Msg={0}\r\nParam1={1}\r\nParam2={2}" , msg, p1, p2);
  }
  else if (msg == MIDIMessage.MIM_LONGDATA)
  {
    // process the system-exclusive message...
    MIDI_HEADER header = new MIDI_HEADER(param1);
    if (header.IsDone)
    {
      byte[] data = header.Data;
      ...
      Console.WriteLine(header.ToString());
    }
    // must unprepare the processed header
    header.Unprepare(true, handle);
    // add a new buffer
    // we must constantly provide new buffers until we finished recording
    AddSysExBuffer(handle, 1024);
  }
  ...
}
See Also

Reference