C# Class Midi.InputDevice

A MIDI input device.

Each instance of this class describes a MIDI input device installed on the system. You cannot create your own instances, but instead must go through the InstalledDevices property to find which devices are available. You may wish to examine the DeviceBase.Name property of each one and present the user with a choice of which device(s) to use.

Open an input device with Open and close it with Close. While it is open, you may arrange to start receiving messages with StartReceiving and then stop receiving them with StopReceiving. An input device can only receive messages when it is both open and started.

Incoming messages are routed to the corresponding events, such as NoteOn and ProgramChange. The event handlers are invoked on a background thread which is started in StartReceiving and stopped in StopReceiving.

As each message is received, it is assigned a timestamp in one of two ways. If StartReceiving is called with a Clock, then each message is assigned a time by querying the clock's Clock.Time property. If StartReceiving is called with null, then each message is assigned a time based on the number of seconds since StartReceiving was called.

Inheritance: Midi.DeviceBase
Mostra file Open project: iUltimateLP/launchpad-led-editor Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Closes this input device.

Open ( ) : void

Opens this input device.

Note that Open() establishes a connection to the device, but no messages will be received until StartReceiving is called.

RemoveAllEventHandlers ( ) : void

Removes all event handlers from the input events on this device.

StartReceiving ( Clock clock ) : void
StartReceiving ( Clock clock, bool handleSysEx ) : void
StopReceiving ( ) : void

Stops this input device from receiving messages.

This method waits for all in-progress input event handlers to finish, and then joins (shuts down) the background thread that was created in StartReceiving. Thus, when this function returns you can be sure that no more event handlers will be invoked.

It is illegal to call this method from an input event handler (ie, from the background thread), and doing so throws an exception. If an event handler really needs to call this method, consider using BeginInvoke to schedule it on another thread.

UpdateInstalledDevices ( ) : void

Refresh the list of input devices

Private Methods

Method Description
CheckNotOpen ( ) : void

Throws a MidiDeviceException if this device is open.

CheckNotReceiving ( ) : void

Throws a MidiDeviceException if this device is receiving.

CheckOpen ( ) : void

Throws a MidiDeviceException if this device is not open.

CheckReceiving ( ) : void

Throws a MidiDeviceException if this device is not receiving.

CheckReturnCode ( Win32API rc ) : void

Makes sure rc is MidiWin32Wrapper.MMSYSERR_NOERROR. If not, throws an exception with an appropriate error message.

CreateLongMsgBuffer ( ) : IntPtr
DestroyLongMsgBuffer ( UIntPtr ptr ) : bool

Releases the resources associated with the specified MidiHeader pointer.

InputCallback ( Win32API hMidiIn, Win32API wMsg, UIntPtr dwInstance, UIntPtr dwParam1, UIntPtr dwParam2 ) : void

The input callback for midiOutOpen.

InputDevice ( UIntPtr deviceId, Win32API caps ) : System

Private Constructor, only called by the getter for the InstalledDevices property.

MakeDeviceList ( ) : Midi.InputDevice[]

Private method for constructing the array of MidiInputDevices by calling the Win32 api.

RecycleLongMsgBuffer ( UIntPtr ptr ) : IntPtr

Method Details

Close() public method

Closes this input device.
The device is not open or is still /// receiving. The device cannot be closed.
public Close ( ) : void
return void

Open() public method

Opens this input device.
Note that Open() establishes a connection to the device, but no messages will be received until StartReceiving is called.
The device is already open. The device cannot be opened.
public Open ( ) : void
return void

RemoveAllEventHandlers() public method

Removes all event handlers from the input events on this device.
public RemoveAllEventHandlers ( ) : void
return void

StartReceiving() public method

public StartReceiving ( Clock clock ) : void
clock Clock
return void

StartReceiving() public method

public StartReceiving ( Clock clock, bool handleSysEx ) : void
clock Clock
handleSysEx bool
return void

StopReceiving() public method

Stops this input device from receiving messages.

This method waits for all in-progress input event handlers to finish, and then joins (shuts down) the background thread that was created in StartReceiving. Thus, when this function returns you can be sure that no more event handlers will be invoked.

It is illegal to call this method from an input event handler (ie, from the background thread), and doing so throws an exception. If an event handler really needs to call this method, consider using BeginInvoke to schedule it on another thread.

The device is not open; is not receiving; /// or called from within an event handler (ie, from the background thread). The device cannot start receiving.
public StopReceiving ( ) : void
return void

UpdateInstalledDevices() public static method

Refresh the list of input devices
public static UpdateInstalledDevices ( ) : void
return void