BASS.NET API for the Un4seen BASS Audio LibraryMidiMIDI_OutShortMsg Method BASS.NET API for the Un4seen BASS Audio Library
Sends a short MIDI message to the specified MIDI output device.

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

public static MIDIError MIDI_OutShortMsg(
	IntPtr handle,
	int message
)

Parameters

handle
Type: SystemIntPtr
Handle to the MIDI output device.
message
Type: SystemInt32
MIDI message. The message is packed into a double word value with the first byte of the message in the low-order byte. The message is packed into this parameter as follows:

High-Word: High-order byte: Not used. Low-order byte: The second byte of MIDI data (when needed).

Low-Word: High-order byte: The first byte of MIDI data (when needed). Low-order byte: The MIDI status.

The two MIDI data bytes are optional, depending on the MIDI status byte. When a series of messages have the same status byte, the status byte can be omitted from messages after the first one in the series, creating a running status.

Return Value

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

This function is used to send any MIDI message except for system-exclusive or stream messages.

This function might not return until the message has been sent to the output device. You can send short messages while streams are playing on the same device (although you cannot use a running status in this case).

You might used the MidiShortMessage class to construct and or pack the message with it's components.

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