Mapping MIDI CC to LADSPA Ports in Ecasound
This article explains how Ecasound maps incoming MIDI Continuous Controller (CC) data to the input control ports of LADSPA audio plugins. By reading MIDI streams through its controller subsystem, Ecasound dynamically scales raw 7-bit MIDI control messages (0–127) to match the floating-point parameter ranges expected by LADSPA plugins, enabling real-time automation and physical hardware control inside a terminal-based audio chain.
Configuring the MIDI Input Device
Before assigning control parameters, Ecasound must be configured to
receive MIDI events from a valid interface. This is done using the
-Md option, which attaches a MIDI control device to the
current engine setup. Common drivers include ALSA sequencer ports or raw
MIDI devices:
ecasound -Md:alsaseq,default ...Once the MIDI device is declared, Ecasound listens for incoming channel events, including Continuous Controller messages.
The -km Controller
Operator
Ecasound attaches parameter automation to audio effects using
"controllers." The specific operator used for MIDI Continuous
Controllers is -km.
When defining an audio processing chain, the -km option
attaches directly to the immediately preceding chain operator (such as a
LADSPA effect loaded via -el). The syntax is structured as
follows:
-km:fx_param,midichannel,cc_number,low_value,high_value
The parameters function as follows:
fx_param: The numerical index of the target parameter on the LADSPA plugin (starting from 1). This matches the control port index of the plugin.midichannel: The MIDI channel to listen to (1 to 16).cc_number: The MIDI Continuous Controller number (0 to 127), such as CC 1 (Modulation Wheel) or CC 7 (Channel Volume).low_value: The target floating-point value assigned when the MIDI CC is at its minimum (0).high_value: The target floating-point value assigned when the MIDI CC is at its maximum (127).
Parameter Scaling and Value Translation
LADSPA control ports operate using standard single-precision
floating-point numbers, while MIDI CC messages deliver integer values
between 0 and 127.
Ecasound maps the two by performing linear interpolation between
low_value and high_value. When an incoming
MIDI message is received on the configured channel and CC number,
Ecasound computes the new port value using the following formula:
\[\text{Port Value} = \text{low\_value} + \left( \frac{\text{MIDI CC Value}}{127} \right) \times (\text{high\_value} - \text{low\_value})\]
Inverted control is also supported by defining low_value
higher than high_value, allowing maximum controller
positions to correspond to minimum plugin values.
Practical Implementation Example
The following command demonstrates routing an audio input through a LADSPA low-pass filter while mapping MIDI CC 74 (standard brightness/cutoff) on MIDI channel 1 to control the filter's cutoff frequency between 200 Hz and 8000 Hz:
ecasound -i:sound.wav -o:alsa \
-Md:alsaseq,128:0 \
-el:lowpass_iir,200,2 \
-km:1,1,74,200,8000In this command:
-el:lowpass_iir,200,2initializes the plugin with default parameters (cutoff = 200, stages = 2).-km:1,1,74,200,8000binds parameter1(cutoff frequency) of that plugin to MIDI Channel1, Controller74, scaling the output continuously across200to8000.