Main Content

MIDI Control for Audio Plugins

MIDI and Plugins

MIDI control surfaces are commonly used in conjunction with audio plugins in digital audio workstation (DAW) environments. Synchronizing MIDI controls with plugin parameters provides a tangible interface for audio processing and is an efficient approach to parameter tuning.

In the MATLAB®environment, audio plugins are defined as any valid class that derives from theaudioPluginbase class or theaudioPluginSourcebase class. For more information about how audio plugins are defined in the MATLAB environment, seeAudio Plugins in MATLAB.

Use MIDI withMATLABPlugins

The Audio Toolbox™ product provides three functions for enabling the interface between MIDI control surfaces and audio plugins:

These functions combine the abilities of general MIDI functions into a streamlined and user-friendly interface suited to audio plugins in MATLAB. For a tutorial on the general functions and the MIDI protocol, seeMIDI Control Surface Interface.

This tutorial walks you through the MIDI functions for audio plugins in MATLAB.

1. Connect MIDI Device and Then StartMATLAB

Before starting MATLAB, connect your MIDI control surface to your computer and turn it on. For connection instructions, see the instructions for your MIDI device. If you start MATLAB before connecting your device, MATLAB might not recognize your device when you connect it. To correct the problem, restart MATLAB with the device already connected.

2. Establish MIDI Connections

UseconfigureMIDIto establish MIDI connections between your default MIDI device and an audio plugin. You can useconfigureMIDIprogrammatically, or you can open a user interface (UI) to guide you through the process. TheconfigureMIDIUI reads from your audio plugin and populates a drop-down list of tunable plugin properties. You are then prompted to move individual controls on your MIDI control surface to associate the position of each control with the normalized value of each property you select. For example, create an object ofaudiopluginexample.PitchShifterand then callconfigureMIDIwith the object as the argument:

ctrlPitch = audiopluginexample.PitchShifter; configureMIDI(ctrlPitch)

The Synchronize to MIDI controls dialog box opens with the tunable properties of your plugin automatically populated. When you operate a MIDI control, its identification is entered into theOperate MIDI control to synchronizebox. After you synchronize tunable properties with MIDI controls, clickOKto complete the configuration. If your MIDI control surface is bidirectional, it automatically shifts the position of the synchronized controls to the initial property values specified by your plugin.

To open a MATLAB function with the programmatic equivalent of your actions in the UI, select theGenerate MATLAB Codecheck box. Saving this function enables you to reuse your settings and quickly establish the configuration in future sessions.

3. Tune Plugin Parameters Using MIDI

After you establish connections between plugin properties and MIDI controls, you can tune the properties in real time using your MIDI control surface.

Audio Toolbox provides an all-in-one app for running and testing your audio plugin. The test bench mimics how a DAW interacts with plugins.

Open theAudio Test Benchfor yourctrlPitchobject.

audioTestBench(ctrlPitch)

When you adjust the controls on your MIDI surface, the corresponding plugin parameter sliders move. Clickto run the plugin. Move the controls on your MIDI surface to hear the effect of tuning the plugin parameters.

To establish MIDI connections and modify existing ones, click the Synchronize to MIDI Controlsbutton to open aconfigureMIDIUI.

Alternatively, you can use the MIDI connections you established in a script or function. For example, run the following code and move your synchronized MIDI controls to hear the pitch-shifting effect:

fileReader = dsp.AudioFileReader(...'Filename','Counting-16-44p1-mono-15secs.wav'); deviceWriter = audioDeviceWriter;% Audio stream loopwhile~结束(fileReader)输入= fileReader ();输出=ctrlPitch(input); deviceWriter(output); drawnowlimitrate;% Process callback immediatelyendrelease(fileReader); release(deviceWriter);

4. Get Current MIDI Connections

To query the MIDI connections established with your audio plugin, use thegetMIDIConnectionsfunction.getMIDIConnectionsreturns a structure with fields corresponding to the tunable properties of your plugin. The corresponding values are nested structures containing information about the mapping between your plugin property and the specified MIDI control.

connectionInfo = getMIDIConnections(ctrlPitch)
connectionInfo = struct with fields: PitchShift: [1×1 struct] Overlap: [1×1 struct]
connectionInfo.PitchShift
ans = struct with fields: Law: 'int' Min: -12 Max: 12 MIDIControl: 'control 1081 on 'BCF2000''

5. Disconnect MIDI Surface

As a best practice, release external devices such as MIDI control surfaces when you are done.

disconnectMIDI(ctrlPitch)

See Also

Apps

Classes

Functions

Related Topics

External Websites