Send values to MIDI controls to synchronize

    Note:   The midisync function will be removed from DSP System Toolbox™ in a future release. Existing instances of the function continue to run. For new code, use the midisync function from Audio System Toolbox™ instead.




midisync(h) sends the initial values specified by midicontrols. h is created by the MIDI controls associated with the midicontrols object, h. You can use midisync with bidirectional MIDI devices that can both send and receive messages, and move a control in response to a received message. For example, when a midicontrols object is first created, it is often helpful to move the MIDI control to match the initial value of the object. Many MIDI devices are not bidirectional, and calling midisync with a unidirectional device has no effect. midisync cannot tell whether a value is successfully sent to a device or even whether the device is bidirectional. Therefore, no errors or warnings are generated if sending a value fails.


midisync(h,Values) sends Values to the MIDI controls associated with the midicontrols object, h. Values must follow the same rules as InitialValue arguments of midicontrols.


collapse all

Send a Slider Change to MIDI Control

midisync(h, get(slider, 'Value'))

Create a GUI with a Single Slider, and Synchronize it with a MIDI Control

When you move either control, the other control tracks it. The resulting value appears on the command prompt.

function trivialmidigui(controlnum,DEVICENAME)
    slider = uicontrol('Style','slider');
    mc = midicontrols(controlnum,'MIDIDevice',DEVICENAME);
    midicallback(mc, @mccb);
    function slidercb(slider,~)
        val = get(slider,'Value');
        midisync(mc, val);

    function mccb(mc)
        val = midiread(mc);

Input Arguments

collapse all

h — Object that listens to the controls on a MIDI deviceobject

h is an object that listens to the controls on a MIDI device.

Values — Values sent to select MIDI controlany numeric value in range

Values must either be an array the same size as ControlNumbers from midicontrols or a scalar. If you do not specify Values, the default value is whatever the InitialValues is from midicontrols. Typically, values must normally be in the range [0 1]. However, if you specify ‘rawmidi' as OutputMode of midicontrols, the Values range is between 0 and 127.

Example: 0.3 or [0 0.3 0.6]

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Introduced in R2013b

Was this topic helpful?