From 899949b07619c05c4bdaa72fd2d146b6ec725ed0 Mon Sep 17 00:00:00 2001 From: Cam Gorrie Date: Sun, 16 Aug 2026 21:31:24 -0400 Subject: [PATCH 1/2] =?UTF-8?q?M1:=20jack=5Fport=5Fappeared=20refactor=20?= =?UTF-8?q?=E2=80=94=20aggregated=20fallback=20+=20separated=20alias=20ret?= =?UTF-8?q?ry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- mod/host.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mod/host.py b/mod/host.py index e69b42383..d36479b30 100644 --- a/mod/host.py +++ b/mod/host.py @@ -543,9 +543,10 @@ def jack_bufsize_changed(self, bufSize): self.msg_callback("bufsize %i" % bufSize) def jack_port_appeared(self, name, isOutput): - name = charPtrToString(name) - isOutput = bool(isOutput) + # Public entry from the JACK port scan. + self._handle_port_appeared(charPtrToString(name), bool(isOutput), retries=6) + def _handle_port_appeared(self, name, isOutput, retries): if name.startswith(self.jack_slave_prefix+":"): name = name.replace(self.jack_slave_prefix+":","") if name.startswith("midi_"): @@ -569,11 +570,20 @@ def jack_port_appeared(self, name, isOutput): return if self.midi_aggregated_mode: - # new ports are ignored under midi aggregated mode + # Connect the new hardware MIDI output to the merger input. + # The merger also does this in its own callback. connect_jack_ports + # is safe to repeat (EEXIST is not an error). Do not add the port + # to the graph; the graph shows only the merged ports. + if isOutput and name != "mod-midi-merger:in": + connect_jack_ports(name, "mod-midi-merger:in") return alias = get_jack_port_alias(name) if not alias: + # The alias is not ready. Try again after a short delay. + if retries > 0: + IOLoop.instance().call_later( + 0.5, self._handle_port_appeared, name, isOutput, retries - 1) return alias = midi_port_alias_to_name(alias, True) From 0d3d42d2be2332ab5eb6f17ba0b7a05ecfdad2f0 Mon Sep 17 00:00:00 2001 From: Cam Gorrie Date: Mon, 17 Aug 2026 00:06:47 -0400 Subject: [PATCH 2/2] Drop aggregated-mode connect; merger owns the merged-stream wiring 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. --- mod/host.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mod/host.py b/mod/host.py index d36479b30..1273935e0 100644 --- a/mod/host.py +++ b/mod/host.py @@ -570,12 +570,10 @@ def _handle_port_appeared(self, name, isOutput, retries): return if self.midi_aggregated_mode: - # Connect the new hardware MIDI output to the merger input. - # The merger also does this in its own callback. connect_jack_ports - # is safe to repeat (EEXIST is not an error). Do not add the port - # to the graph; the graph shows only the merged ports. - if isOutput and name != "mod-midi-merger:in": - connect_jack_ports(name, "mod-midi-merger:in") + # New ports are ignored in aggregated mode. The merger JACK client + # owns the connection to mod-midi-merger:in (its port-registration + # callback plus a bounded reconcile burst). The graph shows only + # the merged ports. return alias = get_jack_port_alias(name)