Understanding the Port Contention Issue
The core problem lies in how Linux handles MIDI hardware access. When you launch a JACK client (such as Ardour, Qtractor, or Bitwig), the JACK daemon typically requests exclusive access to the connected MIDI interfaces via the ALSA subsystem. Once JACK claims these ports, standard ALSA tools like aconnect or alsamixer will report that the device is busy or unavailable. Consequently, any attempt by a separate application to open the ALSA MIDI port directly will fail silently or throw an error.
This behavior is intentional to prevent race conditions where two programs try to write to or read from the same hardware buffer simultaneously. However, it creates confusion for users who expect their MIDI controller to be visible to all software at once. The solution is not to disable JACK, but to route the MIDI traffic through JACK’s internal patchbay so that both the host and external tools can communicate effectively.
Verifying Hardware Detection
Before diving into JACK configuration, ensure the kernel has actually detected the USB MIDI controller. You can verify this by unplugging and replugging the device while watching the system log:
dmesg | tail -n 20
You should see messages indicating a new USB device and specifically a MIDI interface. If the kernel does not recognize the device, no amount of JACK configuration will help. In such cases, check if the necessary firmware modules are loaded or if there is a power management issue suspending the USB port. For more details on diagnosing hardware recognition issues, you might find Troubleshooting System Freezes after Changing Processors or GPUs on Linux helpful, as some underlying driver conflicts share similar diagnostic patterns.
Configuring JACK MIDI Ports
Once JACK is running, it creates virtual MIDI ports named after your physical devices. Use jack_lsp to list these available inputs and outputs:
jack_lsp -i
This command lists input ports. Look for entries that match your controller’s name. If they appear here, JACK sees the device. The next step is to ensure your target application (the one that isn’t the JACK host) can receive these events. Most modern Linux MIDI applications support JACK natively. If your application only supports ALSA, you need a bridge.
Using alsa-jack Bridge
If your software does not support JACK MIDI, you can use the alsa-jack bridge. This tool creates ALSA ports that mirror the JACK ports. Start the bridge service:
systemctl --user start alsa-jack.service
After starting the service, run aconnect -l. You should now see new ALSA ports labeled with jack_ prefixes. Connect your ALSA-based application to these specific ports using aconnect. This allows your non-JACK application to send and receive MIDI data as if it were talking to the hardware directly, while JACK handles the actual hardware communication.
Routing MIDI in qjackctl Patchbay
The most common workflow involves connecting the physical input to the software output within the JACK ecosystem. Open qjackctl and navigate to the Patchbay tab. Create a new preset or edit an existing one. You will typically see two columns: Input and Output.
- Select your USB MIDI Controller’s input port from the left column.
- Select your DAW or synthesizer’s input port from the right column.
- Click "Connect" to establish the link.
This manual connection persists only until JACK restarts. To make it permanent, save the patchbay preset. Many users also enable the "Auto-connect" feature in qjackctl settings, which automatically links compatible ports upon startup. This reduces setup time and prevents missed notes due to forgotten connections.
Checking Sample Rate and Buffer Size
While sample rate primarily affects audio, extremely low buffer sizes can sometimes cause MIDI dropouts or latency issues in JACK. If your MIDI events are arriving late or inconsistently, try increasing the buffer size in the qjackctl Setup dialog. A buffer size of 512 or 1024 samples is usually sufficient for stable MIDI performance without introducing noticeable lag.
Alternative: Using PipeWire
Newer Linux distributions are migrating from JACK to PipeWire for audio handling. PipeWire supports JACK APIs, meaning many JACK clients work unchanged. If you are using PipeWire, the MIDI routing is handled by pw-link or GUI tools like PipeWire Manager. The principle remains the same: ensure the MIDI stream is routed from the source to the destination through the session manager. For general sound device configuration in Pipewire environments, refer to Setting the Default Sound Device at the Shell Prompt in Pipewire.
Frequently Asked Questions
Why does my MIDI controller work in one app but not another?
This usually happens because the first app grabbed exclusive access to the ALSA port via JACK. The second app cannot access the hardware directly. Ensure both apps are JACK clients, or use the alsa-jack bridge for the second app to expose virtual ALSA ports.
How do I make MIDI connections persistent across reboots?
In qjackctl, go to the Patchbay tab, create your connections, and then click "Save" to store the preset. You can set this preset to load automatically in the qjackctl Setup options under the "Patchbay" section.
Can I use ALSA MIDI and JACK MIDI simultaneously without bridging?
No, not directly. JACK requires exclusive control of the ALSA MIDI interfaces. Simultaneous direct access would cause data corruption. You must route all traffic through JACK or use a bridge that translates between the two systems.
What if jack_lsp shows no MIDI ports?
This indicates JACK cannot communicate with the hardware. Check if the device is plugged in and recognized by the kernel (dmesg). Also, ensure no other process is holding the MIDI port open. Restarting the JACK daemon often clears stale locks.
Does changing the audio sample rate affect MIDI timing?
MIDI itself is event-based and not tied to audio sample rates. However, very small buffer sizes required for low-latency audio can increase CPU load, potentially causing MIDI processing delays in heavy projects. Adjusting buffer size is a troubleshooting step for latency, not a fundamental change to MIDI protocol.