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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Return most recent value of MIDI controls


controlValues = midiread(midicontrolsObject)



controlValues = midiread(midicontrolsObject) returns the most recent value of the MIDI controls associated with the specified midicontrolsObject. To create this object, use the midicontrols function.


collapse all

midicontrolsObject = midicontrols;
controlValue = midiread(midicontrolsObject);

Identify two MIDI controls on your MIDI device.

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

controlOne =


Move the control you wish to identify; type ^C to abort.
Waiting for control message... done

controlTwo =


Create a MIDI controls object that listens to both controls you identified.

controlNumbers = [controlOne,controlTwo];
midicontrolsObject = midicontrols(controlNumbers);

Move your specified MIDI controls and return their values. The values are returned as a vector that corresponds to your control numbers vector, controlNumbers.

while toc < 5
    controlValues = midiread(midicontrolsObject)
controlValues =

    0.0397    0.0556

Use midiid to identify the name of your MIDI device and a specified control. Move the MIDI control you want to identify.

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

Create a MIDI controls object. The value associated with your MIDI controls object cannot be determined until you move the MIDI control. Specify an initial value associated with your MIDI control. The midiread function returns the initial value until the MIDI control is moved.

initialControlValue = 1;
midicontrolsObject = midicontrols(controlNumber,initialControlValue);

Create a dsp.AudioFileReader System object™ with default settings. Create an audioDeviceWriter System object and specify the sample rate.

fileReader = dsp.AudioFileReader('RockDrums-44p1-stereo-11secs.mp3');
deviceWriter = audioDeviceWriter(...

In an audio stream loop, read an audio signal frame from the file, apply gain specified by the control on your MIDI device, and then write the frame to your audio output device. By default, the control value returned by midiread is normalized.

while ~isDone(fileReader)
    audioData = step(fileReader);
    controlValue = midiread(midicontrolsObject);
    gain = controlValue*2;
    audioDataWithGain = audioData*gain;

Close the input file and release your output device.


Input Arguments

collapse all

Object that listens to the controls on a MIDI device, specified as an object created by midicontrols.

Output Arguments

collapse all

Most recent values of MIDI controls, returned as normalized values in the range [0,1], or as integer values in the range [0,127]. The output values depend on the OutputMode specified when your midicontrols object is created.

  • If OutputMode was specified as 'normalized', then midiread returns values in the range [0,1]. The default OutputMode is 'normalized'.

  • If OutputMode was specified as 'rawmidi', then midiread returns integer values in the range [0,127], and no quantization is required.

Was this topic helpful?