Output values from controls on MIDI control surface
Note: The MIDI Controls block will be removed from DSP System Toolbox™ in a future release. Existing instances of the block continue to run. For new code, use the MIDI Controls block from Audio System Toolbox™ instead.
The MIDI Controls block outputs values from controls on a MIDI control surface in real time.
Use the MIDI device parameter to specify the name of the MIDI control surface device from which to receive control values. You can choose:
If you choose
Default, the block
looks for a MATLAB® preference with a group named
DefaultDevice. You can set this
preference using the MATLAB
For example, if the desired device is named
you can type the following command at the MATLAB command line:
>> setpref('midi', 'DefaultDevice', 'BCF2000');
If the block does not find this preference, it then attempts to choose a device using an algorithm that is unspecified and platform dependent.
If you choose
Specify other, then
a MIDI device name edit box appears for you to
enter a MATLAB expression for the device name. Enter any MATLAB expression
that can evaluate to a string. Literal names must be enclosed in quotes,
You can determine the name of your MIDI device using the MATLAB function
discussed in Identifying MIDI Device Names and Control Numbers.
Use the MIDI controls parameter to specify the controls on the MIDI device to which the block should respond. This parameter also determines the size of the block output port. You can choose:
Respond to any control
Respond to specified controls
If you choose
Respond to any control,
then the block output will be a scalar. This scalar outputs the value
from any and all controls that are manipulated on the MIDI device.
Use this option in simple cases when you need only a single control
value and the control to which it responds is unimportant.
If you choose
Respond to specified controls,
then a MIDI control numbers edit box opens. In
this box, enter a MATLAB expression for the device control numbers.
Enter any MATLAB expression that can evaluate to a row vector
of real double-precision values. The block outputs a 1-D vector with
one element corresponding to the output of each specified control.
Use the Initial values parameter to specify the value of the block output when simulation starts. The MIDI protocol transmits control values only when a control changes. This protocol provides no means for the block to query the current value of a control. Thus, the block must have some initial value to output until it receives a control change from the device.
Use the Send initial values to device at start check box to synchronize the device controls with the block outputs when simulation starts. Some MIDI control surfaces are bidirectional, meaning that they not only send control values but can also receive them. For example, some devices have motorized controls that move to the appropriate position when they receive a control value. If you have such a bidirectional device, select this check box. The block attempts to send the initial values to the device when the simulation starts. No diagnostic message appears if the attempt fails.
The generated code for this block relies on prebuilt .dll files.
You can run this code outside the MATLAB environment, or redeploy.
However you must account for these extra .dll files when doing so.
The packNGo function creates a single .zip file containing all of
the pieces required to run or rebuild this code. See
packNGo for more information.
The MIDI Controls block output is a vector whose width is determined
by the MIDI controls and MIDI control
numbers parameters previously described. The output data
type can be either real double-precision floating point, or uint8
integer if the output mode is
'Raw MIDI'. The output
values range from 0.0 to 1.0, inclusively, and in the raw mode, they
range from 0 to 127, inclusively. The output port back inherits its
To specify a particular control on a particular MIDI device,
you must know the name assigned to the device by the operating system.
In addition, a number is always associated with the control. You can
interactively discover this information using the MATLAB function,
Follow these steps to identify device names and control numbers:
Verify that MIDI control surface device is correctly connected to the host computer running MATLAB.
Note: For the most consistent behavior, MathWorks recommends that you connect your MIDI control surface device to your computer before starting MATLAB. In some circumstances MATLAB may not be able to find your device if you connect it after starting your MATLAB session. Also, it may not find your device if you disconnect it and reconnect it during your MATLAB session.
Type the following command at the MATLAB command line.
>> [ctlnum devname] = midiid
You are prompted to move the control in which you are interested.
>> [ctlnum devname] = midiid Move the control you wish to identify; type ^C to abort. Waiting for control message ...
Move the control.
the movement and returns the device name and control number.
>> [ctlnum devname] = midiid Move the control you wish to identify; type ^C to abort. Waiting for control message ... done ctlnum = 1081 devname = BCF2000 >>
Use the device name in the block dialog, or set it
as the default device using
setpref. Then, enter
the control number in the block dialog. Concatenate the number with
other control numbers as needed.
Use this example to familiarize yourself with how to set controls in the MIDI Controls block as it interacts with the MIDI control surface.
Open the ex_simplemidi model, and follow these steps:
Connect a MIDI device to the computer.
midiid to determine the name of
the device, and set it on the MIDI Controls block.
Verify that any control changes the display value.
midiid to determine the number
of a particular control, and set that on the MIDI Controls block.
Verify that a particular control changes the display value and that other controls do not.
midiid to determine the number
of a few more controls, and set those on the MIDI Controls block.
Verify that the display block shows the correct number of values. Also verify that the controls you specified change the appropriate display values and that the other controls do not change the values.
Set each control to have a unique initial value.
Verify that the correct initial values appear on the display when the model starts.
If your MIDI device is bidirectional, on the MIDI Controls block, select the Send initial values to device at start check box.
Verify that the controls are set to the correct initial values when the model starts.
Specify whether to use a default MIDI device, or specify a particular device by name.
Specify the name of a particular MIDI control surface device from which to receive control values.
Specify whether to respond to any control on the MIDI device or respond to particular specified controls.
Specify particular controls to which the block should respond.
Specify initial values to output when simulation starts.
Select this check box to attempt to synchronize a bidirectional MIDI device with block initial values when simulation starts.
Specify the mode in which the control values are generated.
When you set Output mode to
(0-1), the block generates control values in the range
0 1]. In this mode, control values are represented
as a fraction of a full-scale. Hence, you can easily scale this range
to your particular application. When you set Output mode to
MIDI (0-127), the block generates byte-oriented MIDI
control values in the range [
0 127]. By default,
this parameter is set to
|Port||Supported Data Types|