Main Content

mididevice

Send and receive MIDI messages

Description

Interface to a MIDI device in MATLAB® using mididevice. Package MIDI messages using midimsg. Send and receive messages using midisend and midireceive. Use mididevinfo to query your system for available MIDI devices.

For a tutorial on interfacing with MIDI devices, see MIDI Device Interface.

Creation

Description

device = mididevice(deviceNameOrID) returns an interface to the MIDI device specified by deviceNameOrID. If the MIDI device supports MIDI in and MIDI out, then device also supports MIDI in and MIDI out.

example

device = mididevice('Input',inDeviceNameOrID) returns an input interface to the MIDI input device, inDeviceNameOrID.

example

device = mididevice('Output',outDeviceNameOrID) returns an output interface to the MIDI output device, outDeviceNameOrID.

example

device = mididevice('Input',inDeviceNameOrID,'Output',outDeviceNameOrID) returns a MIDI I/O interface, where input is received from inDeviceNameOrID and output is sent to outDeviceNameOrID.

example

Properties

expand all

This property is read-only.

Input device name attached to your mididevice object, returned as a character array.

Input is set during the creation of the mididevice object and cannot be modified later.

Data Types: char

This property is read-only.

Output device name attached to your mididevice object, returned as a character array

Output is set during the creation of the mididevice object and cannot be modified later.

Data Types: char

This property is read-only.

Unique MIDI input device ID attached to your mididevice object, returned as a scalar double. If your system includes different MIDI devices with the same name, using the device ID removes ambiguity.

InputID is set during the creation of the mididevice object and cannot be modified later.

Data Types: double

This property is read-only.

Unique MIDI output device ID attached to your mididevice object, returned as a scalar double. If your system includes different MIDI devices with the same name, using the device ID removes ambiguity.

OutputID is set during the creation of the mididevice object and cannot be modified later.

Data Types: double

Object Functions

midisendSend MIDI message to MIDI device
midireceiveReceive MIDI message from MIDI device
hasdataDetermine if data is available to read from MIDI device

Examples

collapse all

Query your system for available MIDI devices.

mididevinfo
  MIDI devices available:
  ID  Direction  Interface   Name
   0   output    MMSystem   'Microsoft MIDI Mapper'
   1    input    MMSystem   'USB MIDI Interface '
   2   output    MMSystem   'Microsoft GS Wavetable Synth'
   3   output    MMSystem   'USB MIDI Interface '

Create a MIDI device object to interface with your selected device. If you specify a single MIDI device object, and it is capable of both input and output, mididevice connects to both the input and output.

device = mididevice('USB MIDI Interface ')
device = 
  mididevice connected to
     Input: 'USB MIDI Interface ' (1)
    Output: 'USB MIDI Interface ' (3)

Query your system for MIDI devices.

mididevinfo
  MIDI devices available:
  ID  Direction  Interface   Name
   0   output    MMSystem   'Microsoft MIDI Mapper'
   1    input    MMSystem   'USB MIDI Interface '
   2   output    MMSystem   'Microsoft GS Wavetable Synth'
   3   output    MMSystem   'USB MIDI Interface '

Create a MIDI device object to interface with your selected input device. As soon as you create the MIDI device object, it begins listening for MIDI messages and storing them in a buffer.

device = mididevice('Input','USB MIDI Interface ');

Query your system for available MIDI devices.

mididevinfo
  MIDI devices available:
  ID  Direction  Interface   Name
   0   output    MMSystem   'Microsoft MIDI Mapper'
   1    input    MMSystem   'USB MIDI Interface '
   2   output    MMSystem   'Microsoft GS Wavetable Synth'
   3   output    MMSystem   'USB MIDI Interface '

Create a MIDI device object to interface with your selected output device.

device = mididevice('Output','USB MIDI Interface ')
device = 
  mididevice connected to
    Output: 'USB MIDI Interface ' (3)

Query your system for available MIDI devices.

mididevinfo
  MIDI devices available:
  ID  Direction  Interface   Name
   0   output    MMSystem   'Microsoft MIDI Mapper'
   1    input    MMSystem   'USB MIDI Interface '
   2   output    MMSystem   'Microsoft GS Wavetable Synth'
   3   output    MMSystem   'USB MIDI Interface '

Create a MIDI device object that receives data from one device and sends data to another device. In this example, the MIDI device object receives MIDI messages from the 'USB MIDI Interface ' device and sends data to the 'Microsoft GS Wavetable Synth' virtual output device. To avoid ambiguity, the MIDI devices are specified by the device IDs.

device = mididevice('Input',1,'Output',2)
device = 
  mididevice connected to
     Input: 'USB MIDI Interface ' (1)
    Output: 'Microsoft GS Wavetable Synth' (2)

Version History

Introduced in R2018a