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 the audioPlugin
base
class or the audioPluginSource
base class. For more
information about how audio plugins are defined in the MATLAB environment,
see Audio Plugins in MATLAB.
Use MIDI with MATLAB Plugins
The Audio Toolbox™ product provides three functions for enabling the interface between MIDI control surfaces and audio plugins:
configureMIDI
–– Configure MIDI connections between audio plugin and MIDI controller.getMIDIConnections
–– Get MIDI connections of audio plugin.disconnectMIDI
–– Disconnect MIDI controls from audio plugin.
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, see MIDI Control Surface Interface.
This tutorial walks you through the MIDI functions for audio plugins in MATLAB.
1. Connect MIDI Device and Then Start MATLAB
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
Use configureMIDI
to establish MIDI connections
between your default MIDI device and an audio plugin. You can use configureMIDI
programmatically,
or you can open a user interface (UI) to guide you through the process.
The configureMIDI
UI 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 of audiopluginexample.PitchShifter
and
then call configureMIDI
with 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 select a property and operate a MIDI control, its identification is entered into the MIDI control column. After you synchronize tunable properties with MIDI controls, click OK to 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 the Generate MATLAB Code check 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 the Audio Test Bench for your ctrlPitch
object.
audioTestBench(ctrlPitch)
When you adjust the controls on your MIDI surface, the corresponding plugin parameter dials move. Click to 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 Controls button to open a configureMIDI
UI.
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 loop while ~isDone(fileReader) input = fileReader(); output = ctrlPitch(input); deviceWriter(output); drawnow limitrate; % Process callback immediately end release(fileReader); release(deviceWriter);
4. Get Current MIDI Connections
To query the MIDI connections established with your audio plugin,
use the getMIDIConnections
function. getMIDIConnections
returns
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
- What Are DAWs, Audio Plugins, and MIDI Controllers?
- MIDI Control Surface Interface
- Audio Plugins in MATLAB
- Host External Audio Plugins