BASS.NET API for the Un4seen BASS Audio LibraryMidiShortMessage ClassBASS.NET API for the Un4seen BASS Audio Library
This class represents a Midi short (data) message as for example received in a MIM_DATA message of a MIDIINPROC.
Inheritance Hierarchy

SystemObject
  radio42.Multimedia.MidiMidiShortMessage

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

[SerializableAttribute]
public sealed class MidiShortMessage

The MidiShortMessage type exposes the following members.

Constructors

  NameDescription
Public methodMidiShortMessage
Default constructor.
Public methodMidiShortMessage(IntPtr, IntPtr)
Creates a new instance of the MidiShortMessage.
Public methodMidiShortMessage(Byte, Int32, Int64)
Creates a new instance of the MidiShortMessage.
Public methodMidiShortMessage(IntPtr, IntPtr, MidiShortMessage)
Creates a new instance of the MidiShortMessage and also evaluates a previous short message..
Public methodMidiShortMessage(MIDIStatus, Byte, Int32, Int64)
Creates a new instance of the MidiShortMessage.
Public methodMidiShortMessage(Byte, Byte, Byte, Byte, Int64)
Creates a new instance of the MidiShortMessage.
Public methodMidiShortMessage(MIDIStatus, Byte, Byte, Byte, Int64)
Creates a new instance of the MidiShortMessage.
Top
Properties

  NameDescription
Public propertyAftertouch
Gets or Sets the polyphonic aftertouch (polyphonic key pressure) from/to the Data2 byte.
Public propertyChannel
Gets or Sets the channel number from/to the Status byte.
Public propertyChannelPressure
Gets or Sets the channel pressure (channel aftertouch) from/to the Data1 byte.
Public propertyController
Gets or Sets the controller number from/to the Data1 byte.
Public propertyControllerType
Gets or Sets the controller type (one of the MIDIControllerType values) from/to the Data1 byte.
Public propertyControllerValue
Gets or Sets the controller value from/to the Data2 byte (and optionally from the PreviousShortMessage).
Public propertyData
Gets or Sets the combined Data1, Data2 and possibly Data3 values as an integer.
Public propertyData1
Gets or Sets the MIDI data byte 1.
Public propertyData2
Gets or Sets the MIDI data byte 2.
Public propertyData3
Gets or Sets the MIDI data byte 3.
Public propertyID
Gets a unique overall short message ID.
Public propertyIsSetAsContinuousController
Gets, if this message was manually set to be a continuous controller message.
Public propertyCode exampleMessage
Gets or Sets the constructed Midi message value.
Public propertyMessageAsIntPtr
Gets or Sets the constructed Midi message value (typically the param1 of a Midi message).
Public propertyMessageType
Gets or Sets the Midi message type (one of the MIDIMessageType values) from/to the Status byte.
Public propertyNote
Gets or Sets the Midi note number from/to the Data1 byte.
Public propertyNoteString
Gets the Midi note from the Data1 byte as a string representation.
Public propertyPairedData2
Gets the paired Data2 value (from an optional PreviousShortMessage).
Public propertyPitchBend
Gets or Sets the pitch bend value from/to Data1 and Data2 as a combined value.
Public propertyPreviousIsMSB
Returns , if the PreviousShortMessage contains the MSB (coarse) ControllerValue and this message the LSB (fine) value - only in case the IsSetAsContinuousController value is set to .
Public propertyPreviousShortMessage
Gets or Sets the previous short message (preceding this short message) if set (or if not set).
Public propertyProgram
Gets or Sets the changed program number from/to the Data1 byte.
Public propertySong
Gets or Sets the song number from/to the Data1 byte.
Public propertySongPosition
Gets or Sets the song position value from/to Data1 and Data2 as a combined value.
Public propertyStatus
Gets or Sets the MIDI status byte.
Public propertyStatusType
Gets or Sets the Midi status type (one of the MIDIStatus values) from/to the Status byte.
Public propertyThisIsMSB
Returns , if this short-message contains the MSB (coarse) ControllerValue and the PreviousShortMessage the LSB (fine) value - only in case the IsSetAsContinuousController value is set to .
Public propertyTimeCodeType
Gets or Sets the Midi Time Code type (one of the MIDIMTCType values) from/to the Data1 byte.
Public propertyTimeCodeValue
Gets or Sets the Midi Time Code value (partial) from/to the Data1 byte.
Public propertyTimespan
Gets or Sets the time that the message was received by the input device driver. The time stamp is specified as milliseconds, beginning at zero when the MIDI_InStart(IntPtr) function was called.
Public propertyTimestamp
Gets or Sets the time that the message was received by the input device driver. The time stamp is specified in milliseconds, beginning at zero when the MIDI_InStart(IntPtr) function was called.
Public propertyTimestampAsIntPtr
Gets or Sets the time span value (typically the param2 of a Midi message).
Public propertyVelocity
Gets or Sets the velocity (key pressure speed) from/to the Data2 byte.
Top
Methods

  NameDescription
Public methodBuildMessage(Int32, Int64)
Constructs a new Midi data message.
Public methodBuildMessage(Int64, Int64)
Constructs a new Midi data message.
Public methodBuildMessage(Byte, Int32, Int64)
Constructs a new Midi data message.
Public methodBuildMessage(MIDIStatus, Byte, Int32, Int64)
Constructs a new Midi data message.
Public methodBuildMessage(Byte, Byte, Byte, Byte, Int64)
Constructs a new Midi data message.
Public methodBuildMessage(MIDIStatus, Byte, Byte, Byte, Int64)
Constructs a new Midi data message.
Public methodStatic memberGetPairedData
Returns a combined paired value from a MSB and a LSB data byte.
Public methodStatic memberGetPairedData1
Returns a combined paired Data1 value from a MSB and a LSB MidiShortMessage.
Public methodStatic memberGetPairedData2
Returns a combined paired Data2 value from a MSB and a LSB MidiShortMessage.
Public methodSetContinuousController
Defines that this message is related to a continuous controller.
Public methodToString
Returns the string representation of the Midi short message.
(Overrides ObjectToString.)
Public methodCode exampleToString(String)
Returns the string representation of the Midi short message.
Public methodCode exampleToString(String, IFormatProvider)
Returns the string representation of the Midi short message.
Top
Remarks

You might use the class to pack (encode, construct) or unpack (decode) any Midi short message.

Use this class with the MIDI_OutShortMsg(IntPtr, Int32) method to send a message to an output device. Use the Message property in that case to get the constructed message value.

Use this class with the MIM_DATA message of a MIDIINPROC to decode the received message.

Examples

Using the MidiShortMessage with an MIDIINPROC:
VB
Private _midiInProc As MIDIINPROC
Private _midiInHandle As IntPtr
...
' Open the Midi device #2
_midiProc = New MIDIINPROC(AddressOf MyMidiProc)
Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
If ret = MIDIError.MIDI_OK Then
  ' supply the device with 2 buffers
  AddSysExBuffer(_midiInHandle, 1024)
  AddSysExBuffer(_midiInHandle, 1024)
  ' 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)
...
Private _shortMsg As MidiShortMessage = Nothing
Private _sysExMsg As MidiSysExMessage = Nothing
...
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...
        _shortMsg = New MidiShortMessage(param1, param2, _shortMsg)
        Console.WriteLine(_shortMsg.ToString())
      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...
            ' param1 will contain the pointer to the MIDI_HEADER
            _sysExMsg = New MidiSysExMessage(True, handle, param1, _sysExMsg)
            If _sysExMsg.IsDone Then
              Console.WriteLine(_sysExMsg.ToString())
            End If
            ' add a new buffer
            ' since we must constantly provide new buffers until we finished recording
            AddSysExBuffer(handle, 1024)
          Else
            If msg = MIDIMessage.MIM_ERROR Then
              ' process the invalid message...
              ...
            Else
              If msg = MIDIMessage.MIM_LONGERROR Then
                ' process the invalid message...
                ' param1 will contain the pointer to the MIDI_HEADER
                Dim header As New MIDI_HEADER(param1)
                header.Unprepare(True, handle)
                ' add a new buffer
                ' since we should constantly provide new buffers until we finished recording
                AddSysExBuffer(handle, 1024)
              End If
            End If
          End If
        End If
      End If
    End If
  End If
End Sub
private MIDIINPROC _midiProc;
private int _midiInHandle;
...
// Open the Midi device #2
_midiProc = new MIDIINPROC(MyMidiProc);
MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
if (ret == MIDIError.MIDI_OK)
{
  // supply the device with 2 buffers
  AddSysExBuffer(_midiInHandle, 1024);
  AddSysExBuffer(_midiInHandle, 1024);
  // 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);
...
// 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 MidiShortMessage _shortMsg  = null;
private MidiSysExMessage _sysExMsg  = null;

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...
    _shortMsg = new MidiShortMessage(param1, param2, _shortMsg);
    Console.WriteLine(_shortMsg.ToString());
  }
  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...
    // param1 will contain the pointer to the MIDI_HEADER
    _sysExMsg  = new MidiSysExMessage(true, handle, param1, _sysExMsg);
    if (_sysExMsg.IsDone)
    {
      Console.WriteLine(_sysExMsg.ToString());
    }
    // add a new buffer
    // since we must constantly provide new buffers until we finished recording
    AddSysExBuffer(handle, 1024);
  }
  else if(msg == MIDIMessage.MIM_ERROR)
  {
    // process the invalid message...
    ...
  }
  else if(msg == MIDIMessage.MIM_LONGERROR)
  {
    // process the invalid message...
    // param1 will contain the pointer to the MIDI_HEADER
    MIDI_HEADER header = new MIDI_HEADER(param1);
    header.Unprepare(true, handle);
    // add a new buffer
    // since we should constantly provide new buffers until we finished recording
    AddSysExBuffer(handle, 1024);
  }
}
See Also

Reference