Send values to MIDI controls to synchronize
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, get(slider, 'Value'))
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); midisync(mc); set(slider,'Callback',@slidercb); midicallback(mc, @mccb); function slidercb(slider,~) val = get(slider,'Value'); midisync(mc, val); disp(val); end function mccb(mc) val = midiread(mc); set(slider,'Value',val); disp(val); end end
h is an object that listens to the controls on a MIDI device.
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