%% Create Note Messages
% 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 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)

% 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)]

% 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)]

% Copyright 2012 The MathWorks, Inc.