BASS.NET API for the Un4seen BASS Audio LibraryMidiOutputDevice ClassBASS.NET API for the Un4seen BASS Audio Library
This class handles all communication with a Midi output device.
Inheritance Hierarchy

SystemObject
  radio42.Multimedia.MidiMidiOutputDevice

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

[SerializableAttribute]
public sealed class MidiOutputDevice

The MidiOutputDevice type exposes the following members.

Constructors

  NameDescription
Public methodMidiOutputDevice
Creates a new instance of a MidiOutputDevice.
Top
Properties

  NameDescription
Public propertyDevice
Returns the device handle for this output device.
Public propertyDeviceID
Returns the device id (number) which was used to create this instance.
Public propertyIsDisposed
Returns , if this class is being disposed.
Public propertyIsOpened
Returns if the Midi output device is opened - else .
Public propertyLastErrorCode
Returns the last Midi error code (see MIDIError for possible values).
Public propertyUser
User instance data to be used when sending system-exclusive messages.
Top
Methods

  NameDescription
Public methodCode exampleClose
Closes the Midi output device using the DeviceID.
Public methodConnect
Connects this output device (must actually be a MIDI thru device) to a MIDI output device.
Public methodDisconnect
Disconnects this output device (must actually be a MIDI thru device) from a MIDI output device.
Public methodDispose
Releases all managed and unmanaged resources used by this class.
Protected methodFinalize
Destructor of the MidiOutputDevice for finalization code.
(Overrides ObjectFinalize.)
Public methodStatic memberGetDeviceCount
Returns the total number of available Midi output devices.
Public methodStatic memberGetDeviceDescription
Returns the name of the given output device ID.
Public methodStatic memberGetDeviceDescriptions
Returns all available Midi output device names.
Public methodStatic memberGetInfo
Determines the capabilities of a specified MIDI output device.
Public methodStatic memberCode exampleGetMidiPorts
Returns all available Midi output port IDs.
Public methodCode exampleOpen
Opens the Midi output device using the DeviceID.
Public methodCode exampleSend(Byte)
Sends a system-exclusive message to the output Device.
Public methodCode exampleSend(Int32)
Sends a short message to the output Device.
Public methodCode exampleSend(MidiShortMessage)
Sends a short message to the output Device.
Public methodCode exampleSend(MidiSysExMessage)
Sends a system-exclusive message to the output Device.
Public methodCode exampleSend(Byte, Byte, Byte)
Sends a short message to the output Device.
Public methodCode exampleSend(MIDIStatus, Byte, Byte, Byte)
Sends a short message to the output Device.
Top
Events

  NameDescription
Public eventMessageReceived
Event handler used to notify that the output device has processed a message or the status has changed.
Top
Remarks

Create an instance of this class and specify a DeviceID to be used. You might use the GetDeviceCount and the GetDeviceDescriptions to enumerate all available Midi output devices (use the GetInfo(Int32) method to retrieve the device capabilities).

After you have called the Open method the Device is being used.

It is a good idea to subscribe to the MessageReceived event handler before calling Open. However, this is generally not needed, since a for an output device there not many events being received (beside that the device is opened and closed and that the Midi output device has finished with a system-exclusive message). The MidiMessageEventArgs contains a MidiMessageEventType which allows you to react to all possible scenarios and to process all Midi messages and events.

To send any short or system-exclusive message use one of the Send(MidiShortMessage) overloads. You might use the MidiShortMessage resp. the MidiSysExMessage class in order to construct any message to be send.

Once you're done with the device call Close to close the device and release it.

Examples

VB
Imports radio42.Multimedia.Midi
...
Private _outDevice As MidiOutputDevice
...
' open a certain Midi output device
Private Sub OpenDevice(device As Integer)
  _outDevice = New MidiOutputDevice(device)
  If Not _outDevice.Open() Then
    MessageBox.Show(Me, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error")
  End If
End Sub

' close the Midi output device
Private Sub StopAndCloseDevice()
  If Not (_outDevice Is Nothing) AndAlso _outDevice.IsOpened Then
    _outDevice.Close()
  End If
End Sub
...
' create and send a new short message to the output device
Dim msg As New MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0)
  If _outDevice.Send(msg) Then
    Console.WriteLine("Error sending short message!")
  End If 
...
' create a new system-exclusive message for the output device
Dim sysex As New MidiSysExMessage(False, _outDevice.Device)
sysex.CreateBuffer(New Byte(7) {&HF0, &H43, &H75, &H73, &H12, &H0, &HF7})
' send it
If _outDevice.Send(sysex) Then
  Console.WriteLine("Error sending system-exclusive message!")
End If
using radio42.Multimedia.Midi;
...
private MidiOutputDevice _outDevice;
...
// open a certain Midi output device
private void OpenDevice(int device)
{
  _outDevice = new MidiOutputDevice(device);
  if (!_outDevice.Open())
    MessageBox.Show(this, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error");
  }
}

// close the Midi output device
private void StopAndCloseDevice()
{
  if (_outDevice != null && _outDevice.IsOpened)
  {
    _outDevice.Close();
  }
}
...
// create and send a new short message to the output device
MidiShortMessage msg = new MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0);
if ( _outDevice.Send(msg) )
  Console.WriteLine("Error sending short message!");
...
// create a new system-exclusive message for the output device
MidiSysExMessage sysex = new MidiSysExMessage(false, _outDevice.Device);
sysex.CreateBuffer( new byte[7] {0xF0, 0x43, 0x75, 0x73, 0x12, 0x00, 0xF7} );
// send it
if ( _outDevice.Send(sysex) )
  Console.WriteLine("Error sending system-exclusive message!");
...
See Also

Reference