Skip to content

Fix MIDI hot-plug device detection in separated mode - #5

Merged
sastraxi merged 2 commits into
mainfrom
fix/midi-aggregated-hotplug
Aug 21, 2026
Merged

sastraxi merged 2 commits into
mainfrom
fix/midi-aggregated-hotplug

Conversation

@sastraxi

@sastraxi sastraxi commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Observed problem

A USB-MIDI device connected during operation in separated mode. The device did not appear in the MIDI device list. The user had to change the MIDI mode from separated to aggregated and back to make the device appear.

Background

In separated mode, mod-ui reads the ALSA alias of each new hardware MIDI port in its port-registration callback. The alias is not always ready when the callback occurs. If the alias is empty, mod-ui discards the port. The device does not appear in the device list.

Changes

This pull request divides jack_port_appeared into a public entry method and a private worker method _handle_port_appeared. In separated mode, the worker reads the port alias again if the alias is not ready. The worker makes a maximum of 6 attempts, at intervals of 0.5 seconds. A device with a late alias appears in the device list.

In aggregated mode, the worker ignores new ports. This is the original upstream behavior. The mod-midi-merger JACK client makes the connection from each hardware MIDI output to mod-midi-merger:in. The graph shows only the merged ports.

Scope

The separated-mode change is necessary. The old code calls get_jack_port_alias one time only. If the ALSA alias is not ready when the port-registration callback occurs, the alias is empty and the device does not appear in the device list. The retry loop corrects this.

The merger patch does the aggregated-mode hot-plug. See TreeFallSound/pi-gen-pistomp#44. The merger connects each unconnected physical MIDI port after a port-registration event. Thus mod-ui does not need an alternative path.

Necessary version of mod-host

The aggregated-mode part of this change needs mod-host-pistomp 0.10.6-6 or a later version. Versions before 0.10.6-6 were built without HAVE_JACK2. mod-host then does not load mod-midi-merger as a JACK internal client, and aggregated mode has no merged stream.

This pull request alone does not cause a fault with an earlier mod-host. Aggregated mode keeps the original upstream behavior. But aggregated-mode hot-plug is correct only when this pull request, pi-gen-pistomp#44, and mod-host 0.10.6-6 are all installed.

Related pull requests

This pull request was divided into parts:

  • This pull request: hot-plug device detection.
  • #6: stale connection records when the MIDI mode changes.

#6 has this pull request as its base. Change the base of #6 to main when this pull request is merged.

A third part, #7, is closed. It is not tested against a known failure. The branch stays in the repository.

…as retry

Refactor into public entry + private worker (_handle_port_appeared).
- Aggregated mode: connect new hw MIDI output to mod-midi-merger:in
  (defense-in-depth; connect_jack_ports tolerates EEXIST).
- Separated mode: retry alias lookup up to 6 times with 0.5s delay
  when the alias is not ready yet.
- No add_hw_port in aggregated mode; graph shows merged ports only.
In aggregated mode the mod-midi-merger JACK client already owns the
connection of hot-plugged hardware MIDI outputs to mod-midi-merger:in
(its port-registration callback plus a bounded reconcile burst), so the
mod-ui fallback was a redundant third writer of the same edge.
_handle_port_appeared now ignores new ports in aggregated mode, the
original upstream behavior. The separated-mode alias-lookup retry is
unchanged.
@sastraxi sastraxi changed the title Fix MIDI aggregated-mode hot-plug: connect new devices to merger, retry late aliases Fix MIDI hot-plug device detection and stale connection records Aug 18, 2026
@sastraxi
sastraxi force-pushed the fix/midi-aggregated-hotplug branch from 8d924d0 to 0d3d42d Compare August 18, 2026 03:31
@sastraxi sastraxi changed the title Fix MIDI hot-plug device detection and stale connection records Fix MIDI hot-plug device detection in separated mode Aug 18, 2026

@rreichenbach rreichenbach left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

@sastraxi
sastraxi merged commit e06260a into main Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants