How Ecasound Routes MIDI Between ALSA Sequencer Ports

This article explains how the multitrack audio processing tool Ecasound captures, manages, and routes MIDI data across Linux ALSA (Advanced Linux Sound Architecture) sequencer ports. By functioning as a dedicated ALSA sequencer client, Ecasound can accept incoming MIDI event streams from hardware interfaces or software synthesizers and dispatch them in real time to designated output ports using standard command-line parameters and internal chainsetups.

ALSA Sequencer Client Registration

When Ecasound initializes with MIDI support enabled, it registers itself as a client within the ALSA sequencer subsystem. ALSA assigns Ecasound a unique client ID, creating internal input and output subscription ports. This registration allows Ecasound to interact with any other active ALSA sequencer port visible in the system, whether that port belongs to a physical MIDI keyboard, an external interface, a software synthesizer like FluidSynth, or a sequencing application.

Defining Inputs and Outputs

Ecasound treats MIDI streams analogously to audio streams within its chain architecture. Routing requires defining an input source (-i) and an output destination (-o) using the alsaseq device specifier.

The syntax follows this format:

You can specify ports by their numerical client and port identifiers (such as 24:0 or 128:0) or by their registered system names (such as nanoKEY2 or FluidSynth). If you specify only -i:alsaseq or -o:alsaseq without targeting a specific client, Ecasound creates open, uncommitted sequencer ports that wait for manual connections.

Connection and Event Dispatching

Ecasound establishes routes through ALSA in one of two ways:

  1. Direct Connection via Arguments: If you provide target client and port numbers directly in the command line, Ecasound automatically requests a subscription from the ALSA sequencer core upon startup. The ALSA sequencer connects the requested external sender to Ecasound’s input port and connects Ecasound’s output port to the designated receiver.
  2. Manual Patching via External Utilities: If you omit specific port addresses, Ecasound exposes generic ALSA MIDI in/out ports. You can then route MIDI streams into and out of Ecasound dynamically using tools like aconnect or graphical patchbays such as QjackCtl.

Once the connection is active, incoming MIDI events enter the ALSA sequencer kernel queue. Ecasound polls this queue, retrieves the structured sequencer events (such as Note On, Note Off, Control Change, and Pitch Bend), and passes them through its internal processing engine.

Basic Routing Execution

A minimal command to route MIDI directly from an input port (16:0) to an output port (128:0) looks like this:

ecasound -f:16,1,44100 -i:alsaseq,16:0 -o:alsaseq,128:0

During execution, Ecasound maintains the event timestamps to ensure low-jitter transmission. Events read from 16:0 travel through the designated chain and are immediately scheduled and written back to the ALSA sequencer queue targeting destination 128:0, successfully bridging the two endpoints.