This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

midimsg

Create MIDI message

Description

Create a MIDI message in MATLAB® using midimsg. Create a MIDI device interface using mididevice. Send and receive messages using midisend and midireceive. When you create a MIDI message, you specify it as a MIDI message type.

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

Creation

Syntax

msg = midimsg('Note',channel,note,velocity,duration,timestamp)
msg = midimsg('NoteOn',channel,note,velocity,timestamp)
msg = midimsg('NoteOff',channel,note,velocity,timestamp)
msg = midimsg('ControlChange',channel,ccnumber,ccvalue,timestamp)
msg = midimsg('ProgramChange',channel,program,timestamp)
msg = midimsg('SystemExclusive',bytes,timestamp)
msg = midimsg('SystemExclusive',timestamp)
msg = midimsg('Data',bytes,timestamp)
msg = midimsg('EOX',timestamp)
msg = midimsg('TimingClock',timestamp)
msg = midimsg('Start',timestamp)
msg = midimsg('Continue',timestamp)
msg = midimsg('Stop',timestamp)
msg = midimsg('ActiveSensing',timestamp)
msg = midimsg('SystemReset',timestamp)
msg = midimsg('TuneRequest',timestamp)
msg = midimsg('MIDITimeCodeQuarterFrame',seq,value,timestamp)
msg = midimsg('SongPositionPointer',position,timestamp)
msg = midimsg('SongSelect',song,timestamp)
msg = midimsg('AllSoundOff',channel,timestamp)
msg = midimsg('ResetAllControllers',channel,timestamp)
msg = midimsg('LocalControl',channel,localcontrol,timestamp)
msg = midimsg('PolyOn',channel,timestamp)
msg = midimsg('MonoOn',channel,monoChannels,timestamp)
msg = midimsg('OmniOn',channel,timestamp)
msg = midimsg('OmniOff',channel,timestamp)
msg = midimsg('AllNotesOff',channel,timestamp)
msg = midimsg('PolyKeyPressure',channel,note,pressure,timestamp)
msg = midimsg('ChannelPressure',channel,pressure,timestamp)
msg = midimsg('PitchBend',channel,change,timestamp)
msg = midimsg
msg = midimsg(size)
msg = midimsg(0)

Description

example

msg = midimsg('Note',channel,note,velocity,duration,timestamp) returns two MIDI messages: NoteOn and NoteOff, with specified Channel, Note, Velocity, and Timestamp properties. The Timestamp property of the NoteOff message is determined as the Timestamp property of the NoteOn message plus the duration.

example

msg = midimsg('NoteOn',channel,note,velocity,timestamp) returns a NoteOn midimsg, with specified Channel, Note, Velocity, and Timestamp properties.

example

msg = midimsg('NoteOff',channel,note,velocity,timestamp) returns a NoteOff midimsg, with specified Channel, Note, Velocity, and Timestamp properties.

example

msg = midimsg('ControlChange',channel,ccnumber,ccvalue,timestamp) returns a ControlChange midimsg, with specified Channel, CCNumber, CCValue, and Timestamp properties.

example

msg = midimsg('ProgramChange',channel,program,timestamp) returns a ProgramChange midimsg, with specified Channel, Program, and Timestamp properties.

example

msg = midimsg('SystemExclusive',bytes,timestamp) returns a complete SystemExclusive message sequence, with specified Timestamp property.

example

msg = midimsg('SystemExclusive',timestamp) returns a SystemExclusive midimsg, with specified Timestamp property.

example

msg = midimsg('Data',bytes,timestamp) returns a Data midimsg for use in a System Exclusive message, with specified MsgBytes and Timestamp properties. bytes is specified as a scalar, vector, or multi-dimensional array of elements. Each element of bytes must be in the range [0,127].

example

msg = midimsg('EOX',timestamp) returns an EOX midimsg, with specified Timestamp property.

msg = midimsg('TimingClock',timestamp) returns a TimingClock midimsg, with specified Timestamp property.

msg = midimsg('Start',timestamp) returns a Start midimsg, with specified Timestamp property.

msg = midimsg('Continue',timestamp) returns a Continue midimsg, with specified Timestamp property.

msg = midimsg('Stop',timestamp) returns a Stop midimsg, with specified Timestamp property.

msg = midimsg('ActiveSensing',timestamp) returns a ActiveSensing midimsg, with specified Timestamp property.

msg = midimsg('SystemReset',timestamp) returns a SystemReset midimsg, with specified Timestamp property.

msg = midimsg('TuneRequest',timestamp) returns a TuneRequest midimsg, with specified Timestamp property.

msg = midimsg('MIDITimeCodeQuarterFrame',seq,value,timestamp) returns a MIDITimeCodeQuarterFrame midimsg, with specified TimeCodeSequence, TimeCodeValue, and Timestamp properties.

msg = midimsg('SongPositionPointer',position,timestamp) returns a SongPositionPointer midimsg, with specified SongPosition and Timestamp properties.

msg = midimsg('SongSelect',song,timestamp) returns a SongSelect midimsg, with specified Song and Timestamp properties.

msg = midimsg('AllSoundOff',channel,timestamp) returns a AllSoundOff midimsg, with specified Channel and Timestamp properties.

msg = midimsg('ResetAllControllers',channel,timestamp) returns a ResetAllControllers midimsg, with specified Channel and Timestamp properties.

msg = midimsg('LocalControl',channel,localcontrol,timestamp) returns a LocalControl midimsg, with specified Channel, LocalControl, and Timestamp properties.

msg = midimsg('PolyOn',channel,timestamp) returns a PolyOn midimsg, with specified Channel and Timestamp properties.

msg = midimsg('MonoOn',channel,monoChannels,timestamp) returns a MonoOn midimsg, with specified Channel, MonoChannels, and Timestamp properties.

msg = midimsg('OmniOn',channel,timestamp) returns an OmniOn midimsg, with specified Channel and Timestamp properties.

msg = midimsg('OmniOff',channel,timestamp) returns an OmniOff midimsg, with specified Channel and Timestamp properties.

msg = midimsg('AllNotesOff',channel,timestamp) returns an AllNotesOff midimsg, with specified Channel and Timestamp properties.

msg = midimsg('PolyKeyPressure',channel,note,pressure,timestamp) returns a PolyKeyPressure midimsg, with specified Channel, Note, Pressure, and Timestamp properties.

msg = midimsg('ChannelPressure',channel,pressure,timestamp) returns a ChannelPressure midimsg, with specified Channel, Pressure, and Timestamp properties.

msg = midimsg('PitchBend',channel,change,timestamp) returns a PitchBend midimsg, with specified Channel, PitchChange, and Timestamp properties.

example

msg = midimsg returns a scalar midimsg with all zero bytes. All zero bytes indicates a MIDI message with Type set to Data.

example

msg = midimsg(size) returns a midimsg array of size with all zero bytes.

example

msg = midimsg(0) returns an empty midimsg.

Note

If timestamp is listed as an argument, it is optional and defaults to zero. The exception is the 'SystemExclusive',bytes,timestamp syntax, in which case the timestamp argument is required.

Properties

expand all

This property is read-only.

Type of MIDI message, returned as one of the following midimsgtype enumeration values:

NoteOnDataStopSongPositionPointerPolyOnPolyKeyPressure
NoteOffEOXActiveSensingSongSelectMonoOnChannelPressure
ControlChangeTimingClockSystemResetAllSoundOffOmniOnPitchBendChange
ProgramChangeStartTuneRequestResetAllControllersOmniOffUndefined
SystemExclusiveContinueMIDITimeCodeQuarterFrameLocalControlAllNotesOff 

You can specify the type of MIDI message during creation as a character vector, string, or member of the midimsgtype enumeration.

For example, the following create equivalent MIDI messages:

  • midimsg('SongPositionPointer',1)

  • midimsg("SongPositionPointer",1)

  • midimsg(midimsgtype.SongPositionPointer,1)

This property is read-only.

Number of bytes in the MIDI message, returned as a scalar, vector, or array the same size as msg.

Data Types: double

This property is read-only.

Actual bytes of the constructed MIDI message in decimal, returned as a scalar, vector, or array the same size as msg.

Data Types: uint8

Location in time for the MIDI message, specified as a scalar, vector, or array the same size as msg.

You can specify the timestamp as any numeric value. However, the timestamp is always stored and returned as type double.

For more on how MIDI timestamps are implemented in Audio System Toolbox™, see MIDI Message Timing.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

MIDI channel to which message is addressed, specified as an integer in the range [1,16].

Dependencies

This property is valid only for NoteOn, NoteOff, PolyKeyPressure, AllSoundOff, ResetAllControllers, LocalControl, AllNotesOff, OmniOn, OmniOff, MonoOn, PolyOn, ControlChange, ProgramChange, ChannelPressure, and PitchBend midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

MIDI note number, specified as an integer in the range [0,127]. The MIDI specification defines note number 60 as Middle C, and all other notes are relative. MIDI devices and software define the mapping between a note and a MIDI note number. If Middle C is arbitrarily assumed to be C5 for the target MIDI hardware or software, the following table maps between MIDI note numbers and notes:

Dependencies

This property is valid only for NoteOn, NoteOff, and PolyKeyPressure midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Velocity of MIDI message, specified as a scalar integer in the range [0,127]. Velocity describes how fast, or "hard," a note is played. A higher number corresponds to faster velocity.

Dependencies

This property is valid only for NoteOn and NoteOff midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Key pressure, specified as a scalar integer in the range [0,127]. Key pressure applies aftertouch to an individual note. For example, on a keyboard, key pressure describes the pressure applied to a key after that key has been struck (after a NoteOn message is sent). You can use KeyPressure to add expression to held notes.

Dependencies

This property is valid only for PolyKeyPressure midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Enable local control, specified as true or false. When local control is set to false, all devices on a given channel respond only to data received over MIDI.

Dependencies

This property is valid only for LocalControl midimsg objects.

Data Types: logical

Channels for MonoOn messages, specified as a scalar integer in the range [0,16].

Dependencies

This property is valid only for MonoOn midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Control change number, specified as an integer in the range [0,119].

Dependencies

This property is valid only for ControlChange midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Control change value, specified as an integer in the range [0,127].

Dependencies

This property is valid only for ControlChange midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Program number to switch to, specified as an integer in the range [0,127].

Dependencies

This property is valid only for ProgramChange midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Channel pressure, specified as an integer in the range [0,127]. Key pressure applies aftertouch to all notes in a channel.

Dependencies

This property is valid only for ChannelPressure midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Amount of pitch change to apply, specified as an integer in the range [0,16383]. The center position (no effect) is 8192. Sensitivity is a function of the receiver.

Dependencies

This property is valid only for PitchBend midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Sequence number, specified as an integer in the range [0,7].

Dependencies

This property is valid only for MIDITimeCodeQuarterFrame midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Time code value, specified as an integer in the range [0,15].

Dependencies

This property is valid only for MIDITimeCodeQuarterFrame midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Position in song to go to, specified as an integer in the range [0,16383].

Dependencies

This property is valid only for SongPositionPointer midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Song number to switch to, specified as an integer in the range [0,127].

Dependencies

This property is valid only for SongSelect midimsg objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Examples

collapse all

You can create MIDI note messages using the NoteOn and NoteOff midimsg objects. A NoteOn message indicates that a note should begin playing. A NoteOff message indicates that a note should stop playing. Alternatively, you can send a second NoteOn message with velocity set to zero to indicate that the note should stop playing. The Audio System Toolbox® provides a convenience syntax to create pairs of note on and note off messages.

Create a pair of MIDI messages to indicate a Note On and Note Off sequence using the Note convenience syntax. Specify that the note starts after one second, and has a duration of two seconds.

channel = 1;
note = 60;
velocity = 64;
duration = 2;
timestamp = 1;
msgs = midimsg('Note',channel,note,velocity,duration,timestamp)
msgs = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 64  Timestamp: 1  [ 90 3C 40 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 3  [ 90 3C 00 ]

Two midimsg objects are created and returned as an array. The Note syntax returns the note off message as a NoteOn midimsg object with Velocity set to zero.

To create Note On and Note Off messages separately, create two NoteOn messages and concatenate them.

msgs = [midimsg('NoteOn',channel,note,velocity,timestamp), ...
        midimsg('NoteOn',channel,note,0,3)]
msgs = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 64  Timestamp: 1  [ 90 3C 40 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 3  [ 90 3C 00 ]

You can also specify the Note Off using a NoteOff midimsg object. Using the NoteOff syntax enables you to specify a release velocity.

    msgs = [midimsg('NoteOn',channel,note,velocity,timestamp), ...
            midimsg('NoteOff',channel,note,velocity,3)]
msgs = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 64  Timestamp: 1  [ 90 3C 40 ]
    NoteOff         Channel: 1  Note: 60  Velocity: 64  Timestamp: 3  [ 80 3C 40 ]

To create a control change message, specify the midimsg Type as ControlChange and set the required parameters: Channel, CCNumber, and CCValue. To determine the channel and control number assigned to your MIDI control surface, use midiid. Enter midiid at the Command Prompt and then move the control you want to identify.

[ccInfo,deviceName] = midiid;
Move the control you wish to identify; type ^C to abort.
Waiting for control message... done

midiid returns the control change number and channel as a single number according to the following formula: ccInfo = (Channel*1000 + CCNumber). Define a MIDI Control Change message to move the identified controller. Your MIDI Control Surface must be bidirectional to receive Control Change messages.

channel = floor(ccInfo/1000);
ccnumber = ccInfo - channel*1000;
ccvalue = 1;
msg = midimsg('ControlChange',channel,ccnumber,ccvalue)
msg = 
  MIDI message:
    ControlChange   Channel: 1  CCNumber: 16  CCValue: 1   Timestamp: 0  [ B0 10 01 ]

Create a mididevice object using the deviceName identified using midiid. Send the MIDI message to your device.

device = mididevice(deviceName);
midisend(device,msg);

Program Change messages, sometimes called "patch change" messages, specify how notes are interpreted. For example, a Program Change message can specify the instrument being played. To create a ProgramChange midimsg object, specify the midimsg type as ProgramChange, and the required property values: Channel and Program.

channel = 4;
program = 7;
msg = midimsg('ProgramChange',channel,program)
msg = 
  MIDI message:
    ProgramChange   Channel: 4  Program: 7   Timestamp: 0  [ C3 07 ]

System Exclusive messages are defined by a sequence of midimsg objects: SystemExclusive, Data, and EOX. To create a System Exclusive sequence, specify the SystemExclusive midimsg type during creation and then specify the bytes of the message. This syntax requires a timestamp.

bytes = [0 1 2];
timestamp = 0;
msg = midimsg('SystemExclusive',bytes,timestamp)
msg = 
  MIDI message:
    SystemExclusive Timestamp: 0  [ F0 ]
    Data            Timestamp: 0  [ 00 01 02 ]
    EOX             Timestamp: 0  [ F7 ]

You can also create the SystemExclusive, Data, and EOX midimsg objects individually. For example, the following midimsg array is the same as the preceding.

msg = [midimsg('SystemExclusive',timestamp), ...
       midimsg('Data',bytes,timestamp), ...
       midimsg('EOX',timestamp)]
msg = 
  MIDI message:
    SystemExclusive Timestamp: 0  [ F0 ]
    Data            Timestamp: 0  [ 00 01 02 ]
    EOX             Timestamp: 0  [ F7 ]

The default MIDI message is a scalar with all zero bytes, and Type is Data.

msg = midimsg
msg = 
  MIDI message:
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]

You can create a MIDI message array by specifying the size by a scalar or row vector.

If you specify the size as a scalar M, midimsg returns an M-by-M array with all zero bytes.

msg = midimsg(2)
msg = 
  MIDI message:
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]

An array of MIDI messages is always displayed vertically in order of their linear indexing. You can refer to individual elements of the array by specifying its position in each dimension, or by its linear index. For example, change the Timestamp of the third element from 0 to 2 using linear indexing, and then from 2 to 3 using first dimensional indexing.

msg(3).Timestamp = 2
msg = 
  MIDI message:
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 2  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
msg(1,2).Timestamp = 3
msg = 
  MIDI message:
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 3  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]

You can also specify nonsymmetric arrays. If you specify the size as a row vector of two or more elements, midimsg returns an M-by-N-by-...-X multidimensional array. For example, to specify a three dimensional array with each dimension having a different number of elements, specify the size as a row vector of three elements.

msg = midimsg([2,1,3])
msg = 
  MIDI message:
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
    Data            Timestamp: 0  [ 00 00 00 00 00 00 00 00 ]
size(msg)
ans = 1×3

     2     1     3

msg = midimsg(0)
msg = 

  empty MIDI message array

In this example, you create an array of MIDI messages, and then index into the array in a loop to define a melody.

Create a 22-by-1 array of MIDI messages with all zero data.

msgArray = midimsg([22,1]);

To create a melody, create MIDI NoteOn and NoteOff messages by indexing in a loop. Display the result.

melody = [60,65,60,57,55,53,60,65,60,67,60];
for i = 1:numel(melody)
    idx = (2*i-1):(2*i);
    msgArray(idx) = midimsg('Note',1,melody(i),50,0.5,i);
end
msgArray
msgArray = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 1  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 1.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 2  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 2.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 3  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 3.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 50  Timestamp: 4  [ 90 39 32 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 0   Timestamp: 4.5  [ 90 39 00 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 50  Timestamp: 5  [ 90 37 32 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 0   Timestamp: 5.5  [ 90 37 00 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 50  Timestamp: 6  [ 90 35 32 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 0   Timestamp: 6.5  [ 90 35 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 7  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 7.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 8  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 8.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 9  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 9.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 50  Timestamp: 10  [ 90 43 32 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 0   Timestamp: 10.5  [ 90 43 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 11  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 11.5  [ 90 3C 00 ]

The order of the MIDI messages in the array is only important for readability. When you send MIDI messages using a mididevice object, the mididevice object reorders your MIDI messages according to their timestamps and sends them in chronological order. Create a PitchBend MIDI message to bend the fourth note downward and add it to the MIDI message array. For readability, sort the MIDI message array by Timestamp.

msg = midimsg('PitchBend',1,7192,4.01);
msgArray = [msgArray;msg]
msgArray = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 1  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 1.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 2  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 2.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 3  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 3.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 50  Timestamp: 4  [ 90 39 32 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 0   Timestamp: 4.5  [ 90 39 00 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 50  Timestamp: 5  [ 90 37 32 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 0   Timestamp: 5.5  [ 90 37 00 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 50  Timestamp: 6  [ 90 35 32 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 0   Timestamp: 6.5  [ 90 35 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 7  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 7.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 8  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 8.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 9  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 9.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 50  Timestamp: 10  [ 90 43 32 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 0   Timestamp: 10.5  [ 90 43 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 11  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 11.5  [ 90 3C 00 ]
    PitchBend       Channel: 1  PitchChange: 7192 Timestamp: 4.01  [ E0 18 38 ]
timeStamps = [msgArray.Timestamp];
[~,idx] = sort(timeStamps);

msgArray = msgArray(idx)
msgArray = 
  MIDI message:
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 1  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 1.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 2  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 2.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 3  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 3.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 50  Timestamp: 4  [ 90 39 32 ]
    PitchBend       Channel: 1  PitchChange: 7192 Timestamp: 4.01  [ E0 18 38 ]
    NoteOn          Channel: 1  Note: 57  Velocity: 0   Timestamp: 4.5  [ 90 39 00 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 50  Timestamp: 5  [ 90 37 32 ]
    NoteOn          Channel: 1  Note: 55  Velocity: 0   Timestamp: 5.5  [ 90 37 00 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 50  Timestamp: 6  [ 90 35 32 ]
    NoteOn          Channel: 1  Note: 53  Velocity: 0   Timestamp: 6.5  [ 90 35 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 7  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 7.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 50  Timestamp: 8  [ 90 41 32 ]
    NoteOn          Channel: 1  Note: 65  Velocity: 0   Timestamp: 8.5  [ 90 41 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 9  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 9.5  [ 90 3C 00 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 50  Timestamp: 10  [ 90 43 32 ]
    NoteOn          Channel: 1  Note: 67  Velocity: 0   Timestamp: 10.5  [ 90 43 00 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 50  Timestamp: 11  [ 90 3C 32 ]
    NoteOn          Channel: 1  Note: 60  Velocity: 0   Timestamp: 11.5  [ 90 3C 00 ]

Introduced in R2018a