This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 Design an Audio Plugin.

Use MIDI with MATLAB Plugins

The Audio System 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, see Musical Instrument Digital Interface (MIDI).

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;

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 the Operate MIDI control to synchronize box. 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 System 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.


When you adjust the controls on your MIDI surface, the corresponding plugin parameter sliders 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(...
deviceWriter = audioDeviceWriter;

% Audio stream loop
while ~isDone(fileReader)
    input = fileReader();
    output = ctrlPitch(input);
    drawnow limitrate; % Process callback immediately


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]
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.


See Also




Related Topics

External Websites

Was this topic helpful?