midiread
Return most recent value of MIDI controls
Description
returns
the most recent value of the MIDI controls associated with the specified controlValues
= midiread(midicontrolsObject
)midicontrolsObject
.
To create this object, use the midicontrols
function.
Examples
Read Control Values of MIDI Device
midicontrolsObject = midicontrols; controlValue = midiread(midicontrolsObject);
Read Multiple Control Values of MIDI Device
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 = 1081 Move the control you wish to identify; type ^C to abort. Waiting for control message... done controlTwo = 1082
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
.
tic while toc < 5 controlValues = midiread(midicontrolsObject) end
controlValues = 0.0397 0.0556
Read Control Values in an Audio Stream Loop
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(... 'SampleRate',fileReader.SampleRate);
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; play(deviceWriter,audioDataWithGain); end
Close the input file and release your output device.
release(fileReader); release(deviceWriter);
Input Arguments
midicontrolsObject
— Object that listens to the controls on a MIDI device
object
Object that listens to the controls on a MIDI device, specified
as an object created by midicontrols
.
Output Arguments
controlValues
— Most recent values of MIDI controls
[0,1]
(default) | integer values in the range [0,127]
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'
, thenmidiread
returns values in the range[0,1]
. The defaultOutputMode
is'normalized'
.If
OutputMode
was specified as'rawmidi'
, thenmidiread
returns integer values in the range[0,127]
, and no quantization is required.
Version History
Introduced in R2016a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)