% IMPORTANT 
% - Include midi_interface.m (download from Matlab) in the path
% - Configure Digitizer with I-CubeX Editor to output MIDI Control Change messages 
%   for the desired sensor inputs
% - Each time this routine is run the MIDI messages sent by the Digitizer have to
%   be different (not sure why .. maybe a bug in Matlab midi_interface.m routine ?)

% Use this method if you know the MIDI port name to which the Digitizer is attached
% success = midi_interface('open', 'MIDISPORT 2x2 In B'); % open MIDI port
                                                          % change 'MIDISPORT 2x2 In B' to name of MIDI port
                                                          % lookup name in Devices and Printers in Control Panel
                                                        
% Use this method to obtain the MIDI port name to which the Digitizer is attached if you can't find it
% setpref('midi', 'DefaultDevice', 'MIDISPORT 2x2'); % set a default MIDI port
% [ctlnum devicename] = midiid % obtain and display MIDI port name  
                               % by providing sensor input (stimulate the sensor)
% success = midi_interface('open', devicename); % open MIDI port

midi_interface('open') % select and open the MIDI port to which the Digitizer is attached
for i=1:10
    [messages, times] = midi_interface() % retrieve and display received MIDI messages with timestamps
    pause(1); % wait a second before retrieving more MIDI messages
end
midi_interface('close'); % close MIDI port