MIDI Controls
Output values from controls on MIDI control surface
Note
In a future release, the MIDI Controls block will require Audio Toolbox™.
Library
Sources
dspsrcs4
Description
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:
Default
Specify other
If you choose Default
, the block looks for a
MATLAB® preference with a group named midi
and
preference named DefaultDevice
. You can set this
preference using the MATLAB
setpref
function. For example, if the desired device is
named BCF2000
, 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, (for example, 'BCF2000'
).
You can determine the name of your MIDI device using midiid
(Audio Toolbox), 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
(Simulink Coder) for more
information.
Output Port
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 sample time.
Identifying MIDI Device Names and Control Numbers
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, midiid
(Audio Toolbox). To use
midiid
, note that you will need to have
the Audio Toolbox installed. 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.
midiid
detects 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.
Parameters
- MIDI device
Specify whether to use a default MIDI device, or specify a particular device by name.
- MIDI device name
Specify the name of a particular MIDI control surface device from which to receive control values.
- MIDI controls
Specify whether to respond to any control on the MIDI device or respond to particular specified controls.
- MIDI control numbers
Specify particular controls to which the block should respond.
- Initial values
Specify initial values to output when simulation starts.
- Send initial values to device at start
Select this check box to attempt to synchronize a bidirectional MIDI device with block initial values when simulation starts.
- Output mode
Specify the mode in which the control values are generated. When you set Output mode to
Normalized (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 toRAW MIDI (0-127)
, the block generates byte-oriented MIDI control values in the range [0 127
]. By default, this parameter is set toNormalized (0-1)
.
Supported Data Types
Port | Supported Data Types |
---|---|
Output |
|
Extended Capabilities
Version History
Introduced in R2012a