midicallback
Call function handle when MIDI controls change value
Syntax
Description
sets oldFunctionHandle
= midicallback(midicontrolsObject
,functionHandle
)functionHandle
as
the function handle called when midicontrolsObject
changes
value, and returns the previous function handle, oldFunctionHandle
.
clears
the function handle.oldFunctionHandle
= midicallback(midicontrolsObject
,[])
returns
the current function handle.currentFunctionHandle
= midicallback(midicontrolsObject
)
Examples
Interactively Read MIDI Controls
Create a default MIDI controls object. Use midicallback
to
associate an anonymous function with your MIDI controls object, mc
.
mc = midicontrols; midicallback(mc,@(x)disp(midiread(x)));
Move any control on your default MIDI device to display its current normalized value on the command line.
0.5079 0.5000 0.4921 0.4841 0.4762 0.4683 0.4603 0.4683
Use midicallback
to Update Plot
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...
Create an object that responds to the control you specified.
midicontrolsObject = midicontrols(controlNumber);
Define a function that plots a sinusoid with the amplitude set by your MIDI control. Make the axis constant.
axis([0,2*pi,-1,1]); axis manual hold on sinePlotter = @(obj) plot(0:0.1:2*pi,midiread(obj).*sin(0:0.1:2*pi));
Use the midicallback
function to
associate your sinePlotter
function with the control
specified by your midicontrolsObject
. Move your
specified MIDI control. The plot updates automatically with the sinusoid
amplitude specified by your MIDI control.
midicallback(midicontrolsObject,sinePlotter)
Change Function Handle Associated with MIDI Control
Create an object that responds to any control on the default MIDI device.
midicontrolsObject = midicontrols;
Define an anonymous function to display the current value
of the MIDI control. Use midicallback
to associate
your MIDI control object with the function you created. Verify that
your object is associated with your function.
displayControlValue = @(object) disp(midiread(object)); midicallback(midicontrolsObject,displayControlValue); currentFunctionHandle = midicallback(midicontrolsObject)
currentFunctionHandle = @(object)disp(midiread(object))
Move any control on your default MIDI device to display its current normalized value on the command line.
0.3095 0.4603 0.6746 0.7381 0.8175 0.8571 0.9048
Define an anonymous function to print the current value
of the MIDI control rounded to two significant digits. Use midicallback
to
associate your MIDI controls object with the function you created.
Return the old function handle.
displayRoundedControlValue = @(object) fprintf('%.2f\n',midiread(object));
oldFunctionHandle = midicallback(midicontrolsObject,displayRoundedControlValue)
oldFunctionHandle = @(object)disp(midiread(object))
Move a control to display its current normalized value rounded to two significant digits.
0.91 0.83 0.67 0.49 0.29 0.18 0.05
Remove the association between the object and the function. Return the old function handle.
oldFunctionHandle = midicallback(midicontrolsObject,[])
oldFunctionHandle = @(object)fprintf('%.2f\n',midiread(object))
Verify that no function is associated with your MIDI controls object.
currentFunctionHandle = midicallback(midicontrolsObject)
currentFunctionHandle = []
Associate a Function with MIDI Controls
Define this function and save it to your current folder.
function plotSine(midicontrolsObject) frequency = midiread(midicontrolsObject); x = 0:0.01:10; sinusoid = sin(2*pi*frequency.*x); plot(x,sinusoid) axis([0,10,-1.1,1.1]); ylabel('Amplitude'); xlabel('Time (s)'); title('Sine Plot') legend(sprintf('Frequency = %0.2f Hz',frequency)); end
Create a midicontrols
object. Create
a function handle for your plotSine
function. Use midicallback
to
associate your midicontrolsObject
with plotSineHandle
.
Move any controller on your MIDI device to plot a sinusoid. The sinusoid frequency updates when you move MIDI controls.
midicontrolsObject = midicontrols; plotSineHandle = @plotSine; midicallback(midicontrolsObject,plotSineHandle);
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
.
functionHandle
— New function handle
function handle
New function handle, specified as a function handle that contains
one input argument. The new function handle is called when midicontrolsObject
changes
value. For information on what function handles are, see Function Handles.
Output Arguments
oldFunctionHandle
— Old function handle
function handle
Old function handle set by the previous call to midicallback
,
returned as a function handle.
currentFunctionHandle
— Current function handle
function handle
The function handle set by the most recent call to midicallback
,
returned as a function handle.
Version History
Introduced in R2016a
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)