Przeglądaj źródła

recompile mod ui for reverb

Johan Le Baut 5 dni temu
rodzic
commit
a0619e8d46

+ 1 - 0
artifacts/mod-ui/arm64/current/app/.gitignore

@@ -4,6 +4,7 @@ package-lock.json
 *~
 *.dll
 *.o
+*.so
 *.pyc
 *.swp
 *.tar.xz

+ 59 - 61
artifacts/mod-ui/arm64/current/app/mod/host.py

@@ -31,12 +31,7 @@ try:
 except ImportError:
     pass
 
-from mod.rigforge_pipewire import (
-    boundary_connection,
-    connect_link,
-    disconnect_link,
-    pedalboard_connection,
-)
+from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection
 from mod import (
     TextFileFlusher,
     get_hardware_descriptor, get_nearest_valid_scalepoint_value, get_unique_name,
@@ -3711,23 +3706,18 @@ class Host(object):
         instance_id = self.mapper.get_id_without_creating(instance)
         return "effect_%d:%s" % (instance_id, portsymbol)
 
-    def _rigforge_pipewire_boundary(self, port_from, port_to):
-        return boundary_connection(
-            port_from,
-            port_to,
-            self.rigforge_capture_ports,
-            self.rigforge_playback_ports,
-            self._fix_host_connection_port,
-        )
-
     def connect(self, port_from, port_to, callback):
         if (port_from, port_to) in self.connections:
             logging.info("[host] NOTE: Requested connection already exists")
             callback(True)
             return
 
-        pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-        if pipewire_link is not None:
+        resolved = pedalboard_connection(
+            port_from, port_to, self.rigforge_capture_ports,
+            self.rigforge_playback_ports, self._fix_host_connection_port
+        )
+        if resolved is not None and resolved[0] == "pipewire":
+            pipewire_link = resolved[1]
             ok = connect_link(*pipewire_link)
             callback(ok)
             if ok:
@@ -3749,13 +3739,24 @@ class Host(object):
             else:
                 logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
 
-        self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
-                                              self._fix_host_connection_port(port_to)),
-                           host_callback, datatype='boolean')
+        if resolved is not None:
+            port_from_2, port_to_2 = resolved[1]
+        else:
+            port_from_2 = self._fix_host_connection_port(port_from)
+            port_to_2 = self._fix_host_connection_port(port_to)
+        self.send_modified(
+            "connect %s %s" % (port_from_2, port_to_2),
+            host_callback,
+            datatype='boolean'
+        )
 
     def disconnect(self, port_from, port_to, callback):
-        pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-        if pipewire_link is not None:
+        resolved = pedalboard_connection(
+            port_from, port_to, self.rigforge_capture_ports,
+            self.rigforge_playback_ports, self._fix_host_connection_port
+        )
+        if resolved is not None and resolved[0] == "pipewire":
+            pipewire_link = resolved[1]
             ok = disconnect_link(*pipewire_link)
             callback(ok)
             if ok:
@@ -3776,40 +3777,41 @@ class Host(object):
             return
 
         def host_callback(ok):
-            # always return true. disconnect failures are not fatal, but still print error for debugging
+            # Upstream disconnect failures are not fatal to the UI state.
             callback(True)
             self.msg_callback("disconnect %s %s" % (port_from, port_to))
-
             if not ok:
                 logging.error("[host] disconnect '%s' => '%s' failed", port_from, port_to)
-
             self.pedalboard_modified = True
-
             try:
                 self.connections.remove((port_from, port_to))
-            except:
-                logging.info("[host] NOTE: Requested '%s' => '%s' connection doesn't exist", port_from, port_to)
+            except ValueError:
+                logging.info(
+                    "[host] NOTE: Requested '%s' => '%s' connection doesn't exist",
+                    port_from, port_to
+                )
+
+        if resolved is not None:
+            port_from_2, port_to_2 = resolved[1]
+        else:
+            try:
+                port_from_2 = self._fix_host_connection_port(port_from)
+            except Exception:
+                logging.info("[host] NOTE: Requested '%s' source port doesn't exist, assume disconnected", port_from)
+                return host_callback(True)
+            try:
+                port_to_2 = self._fix_host_connection_port(port_to)
+            except Exception:
+                logging.info("[host] NOTE: Requested '%s' target port doesn't exist, assume disconnected", port_to)
+                return host_callback(True)
 
         if len(self.connections) == 0:
             return host_callback(False)
-
-        # If the plugin or port don't exist, assume disconnected
-        try:
-            port_from_2 = self._fix_host_connection_port(port_from)
-        except:
-            logging.info("[host] NOTE: Requested '%s' source port doesn't exist, assume disconnected", port_from)
-            return host_callback(True)
-
-        try:
-            port_to_2 = self._fix_host_connection_port(port_to)
-        except:
-            logging.info("[host] NOTE: Requested '%s' target port doesn't exist, assume disconnected", port_to)
-            return host_callback(True)
-
-        self.send_modified("disconnect %s %s" % (port_from_2, port_to_2), host_callback, datatype='boolean')
-
-    # -----------------------------------------------------------------------------------------------------------------
-    # Host stuff - load & save
+        self.send_modified(
+            "disconnect %s %s" % (port_from_2, port_to_2),
+            host_callback,
+            datatype='boolean'
+        )
 
     def load(self, bundlepath, isDefault=False, abort_catcher=None, modified=False):
         first_pedalboard = self.first_pedalboard
@@ -4431,34 +4433,30 @@ class Host(object):
             port_to   = "/graph/%s" % c['target']
 
             if doConnectionNow:
-                try:
-                    port_from_2 = self._fix_host_connection_port(port_from)
-                    port_to_2   = self._fix_host_connection_port(port_to)
-                except:
-                    continue
                 resolved = pedalboard_connection(
-                    port_from,
-                    port_to,
-                    self.rigforge_capture_ports,
-                    self.rigforge_playback_ports,
-                    self._fix_host_connection_port,
+                    port_from, port_to, self.rigforge_capture_ports,
+                    self.rigforge_playback_ports, self._fix_host_connection_port
                 )
                 if resolved is not None and resolved[0] == "pipewire":
-                    pipewire_link = resolved[1]
                     self._rigforge_restore_pipewire_boundary(
-                        pipewire_link,
+                        resolved[1],
                         port_from,
                         port_to,
                         self.connections,
                         attempts_left=60
                     )
                     continue
-                if resolved is not None:
-                    port_from_2, port_to_2 = resolved[1]
+                try:
+                    if resolved is not None:
+                        port_from_2, port_to_2 = resolved[1]
+                    else:
+                        port_from_2 = self._fix_host_connection_port(port_from)
+                        port_to_2 = self._fix_host_connection_port(port_to)
+                except Exception:
+                    continue
                 self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
                 self.connections.append((port_from, port_to))
                 self.msg_callback("connect %s %s" % (port_from, port_to))
-
             elif aliasname1 is not None or aliasname2 is not None:
                 for port_symbol, port_alias, port_conns in self.midiports:
                     port_alias = port_alias.split(";",1) if ";" in port_alias else [port_alias]

+ 3 - 3
artifacts/mod-ui/arm64/current/provenance.json

@@ -9,8 +9,8 @@
   "additional_python_requirement": "backports.ssl_match_hostname==3.7.0.1",
   "python_compatibility_patch": "Tornado 4.3 collections.MutableMapping to collections.abc.MutableMapping",
   "rigforge_integration_patch": "build/arm64/patch_mod_ui_rigforge.py",
-  "rigforge_integration_patch_sha256": "c3260a0fb11589cfd0153c99fcb413810c184b6f90f13d56fe4b3aeb6b2bbf74",
-  "license": "AGPL-3.0-or-later",
+  "rigforge_integration_patch_sha256": "9dcb5c0e3e66697ee0d3aef0ff817008a86f3aaba3b0cdcc724e213f668746cc",
   "rigforge_pipewire_helper": "build/arm64/mod_ui_pipewire.py",
-  "rigforge_pipewire_helper_sha256": "326d79b8fbfaf740cd4eb99d24d6daceaffcac019f40a768913c58a74db16719"
+  "rigforge_pipewire_helper_sha256": "326d79b8fbfaf740cd4eb99d24d6daceaffcac019f40a768913c58a74db16719",
+  "license": "AGPL-3.0-or-later"
 }

+ 14 - 14
artifacts/mod-ui/arm64/current/runtime-dependencies.txt

@@ -1,14 +1,14 @@
-	linux-vdso.so.1 (0x00007e72bba65000)
-	libasound.so.2 => /lib/aarch64-linux-gnu/libasound.so.2 (0x00007e72b3070000)
-	libjack.so.0 => /lib/aarch64-linux-gnu/libjack.so.0 (0x00007e72b2ff0000)
-	liblilv-0.so.0 => /lib/aarch64-linux-gnu/liblilv-0.so.0 (0x00007e72b2fb0000)
-	libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x00007e72b2d40000)
-	libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x00007e72b2d00000)
-	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x00007e72b2b40000)
-	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x00007e72b2a90000)
-	/lib/ld-linux-aarch64.so.1 (0x00007e72bba10000)
-	libdb-5.3.so => /lib/aarch64-linux-gnu/libdb-5.3.so (0x00007e72b28c0000)
-	libserd-0.so.0 => /lib/aarch64-linux-gnu/libserd-0.so.0 (0x00007e72b2880000)
-	libsord-0.so.0 => /lib/aarch64-linux-gnu/libsord-0.so.0 (0x00007e72b2850000)
-	libsratom-0.so.0 => /lib/aarch64-linux-gnu/libsratom-0.so.0 (0x00007e72b2820000)
-	libzix-0.so.0 => /lib/aarch64-linux-gnu/libzix-0.so.0 (0x00007e72b27f0000)
+	linux-vdso.so.1 (0x000071f43f20d000)
+	libasound.so.2 => /lib/aarch64-linux-gnu/libasound.so.2 (0x000071f436820000)
+	libjack.so.0 => /lib/aarch64-linux-gnu/libjack.so.0 (0x000071f4367a0000)
+	liblilv-0.so.0 => /lib/aarch64-linux-gnu/liblilv-0.so.0 (0x000071f436760000)
+	libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x000071f4364f0000)
+	libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x000071f4364b0000)
+	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x000071f4362f0000)
+	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x000071f436240000)
+	/lib/ld-linux-aarch64.so.1 (0x000071f4371b0000)
+	libdb-5.3.so => /lib/aarch64-linux-gnu/libdb-5.3.so (0x000071f436070000)
+	libserd-0.so.0 => /lib/aarch64-linux-gnu/libserd-0.so.0 (0x000071f436030000)
+	libsord-0.so.0 => /lib/aarch64-linux-gnu/libsord-0.so.0 (0x000071f436000000)
+	libsratom-0.so.0 => /lib/aarch64-linux-gnu/libsratom-0.so.0 (0x000071f435fd0000)
+	libzix-0.so.0 => /lib/aarch64-linux-gnu/libzix-0.so.0 (0x000071f435fa0000)

+ 1 - 1
artifacts/mod-ui/arm64/current/vendor/aggdraw-1.3.11.dist-info/RECORD

@@ -5,4 +5,4 @@ aggdraw-1.3.11.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
 aggdraw-1.3.11.dist-info/WHEEL,sha256=80Ut1xxBsf_d7iQ-DAbI2W6P3TnBQJqgNk4n6C11j-Q,105
 aggdraw-1.3.11.dist-info/licenses/LICENSE.txt,sha256=TrY_nTojr1jKH0ljlJmkOMGitgPstA_MmFN2HYnmYIU,1858
 aggdraw-1.3.11.dist-info/top_level.txt,sha256=gUN2bwtostWRk8u3AWqOkMrAa6kZowAc2VNpROk3YGk,8
-aggdraw.cpython-313-aarch64-linux-gnu.so,sha256=lj_8194xEKEDhX4R9hePUeSN3pRPP0Oh9dBkIf5dbD8,702104
+aggdraw.cpython-313-aarch64-linux-gnu.so,sha256=YTXoLruXXpRzZxg5uCAE3ub9ApyyJUcLdW2DvMM2SU8,702104

BIN
artifacts/mod-ui/arm64/current/vendor/aggdraw.cpython-313-aarch64-linux-gnu.so


+ 1 - 1
artifacts/mod-ui/arm64/current/vendor/tornado-4.3.dist-info/RECORD

@@ -38,7 +38,7 @@ tornado/platform/windows.py,sha256=xonLtnGj7ZSo5q1_try4hkE6rWEmVRU-EbCEmWhgPog,6
 tornado/process.py,sha256=9Dh0oAik9PUFGSnSR4aXaq_4h6pxpkrNjwJTqS9b0_A,12300
 tornado/queues.py,sha256=TOxKUoxhsR16dP9VllUnNoAdd-w1ZtEe1DLJNX0BEXo,10013
 tornado/simple_httpclient.py,sha256=o5SDq6EHkAVp7Wfk9fnZKJQ4Zs25gHFcQXlzIDcZLOE,23983
-tornado/speedups.cpython-313-aarch64-linux-gnu.so,sha256=l64-6kHSG3Lvp4qq5hmUAtdyhvJ0-xeoMi2_x_sKtHU,79072
+tornado/speedups.cpython-313-aarch64-linux-gnu.so,sha256=yhbSk_JNvsle-xic4VtpCVNepbPeAf8zSnYzX7251eM,79072
 tornado/stack_context.py,sha256=RJ2E4-UKbXPzvd0Yw4b9H9C2YUWK2vyKPf7NeB7F_zQ,13174
 tornado/tcpclient.py,sha256=BsGu5ZKUw3zRbiDB9NSgUS3j1HBr1GWjobiMMsUudU0,6802
 tornado/tcpserver.py,sha256=CYpGxMUb8XleB3zU-v_GfC00y3wUY-QyyJjbNvDsdG8,11530

BIN
artifacts/mod-ui/arm64/current/vendor/tornado/speedups.cpython-313-aarch64-linux-gnu.so


+ 235 - 273
build/arm64/patch_mod_ui_rigforge.py

@@ -23,6 +23,238 @@ def replace_if_present(path, original, replacement):
     path.write_text(text.replace(original, replacement), encoding="utf-8")
 
 
+def replace_host_method(path, method_name, replacement):
+    """Replace a complete Host method, independent of its upstream body variant."""
+    text = path.read_text(encoding="utf-8")
+    marker = f"    def {method_name}("
+    start = text.find(marker)
+    if start < 0:
+        raise RuntimeError(f"could not find Host.{method_name} in {path}")
+    next_method = text.find("\n    def ", start + len(marker))
+    end = len(text) if next_method < 0 else next_method + 1
+    replacement = replacement.rstrip() + "\n\n"
+    updated = text[:start] + replacement + text[end:]
+    if updated != text:
+        path.write_text(updated, encoding="utf-8")
+
+
+def patch_host_connection_methods(host):
+    """Normalize manual connection handling across old Rigforge patch variants."""
+    replace_host_method(
+        host,
+        "connect",
+        '''    def connect(self, port_from, port_to, callback):
+        if (port_from, port_to) in self.connections:
+            logging.info("[host] NOTE: Requested connection already exists")
+            callback(True)
+            return
+
+        resolved = pedalboard_connection(
+            port_from, port_to, self.rigforge_capture_ports,
+            self.rigforge_playback_ports, self._fix_host_connection_port
+        )
+        if resolved is not None and resolved[0] == "pipewire":
+            pipewire_link = resolved[1]
+            ok = connect_link(*pipewire_link)
+            callback(ok)
+            if ok:
+                self.connections.append((port_from, port_to))
+                self.pedalboard_modified = True
+                self.msg_callback("connect %s %s" % (port_from, port_to))
+            else:
+                logging.error(
+                    "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
+                    pipewire_link[0], pipewire_link[1]
+                )
+            return
+
+        def host_callback(ok):
+            callback(ok)
+            if ok:
+                self.connections.append((port_from, port_to))
+                self.msg_callback("connect %s %s" % (port_from, port_to))
+            else:
+                logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
+
+        if resolved is not None:
+            port_from_2, port_to_2 = resolved[1]
+        else:
+            port_from_2 = self._fix_host_connection_port(port_from)
+            port_to_2 = self._fix_host_connection_port(port_to)
+        self.send_modified(
+            "connect %s %s" % (port_from_2, port_to_2),
+            host_callback,
+            datatype='boolean'
+        )''',
+    )
+    text = host.read_text(encoding="utf-8")
+    if "    def _rigforge_pipewire_boundary(" in text:
+        replace_host_method(
+            host,
+            "_rigforge_pipewire_boundary",
+            '''    def _rigforge_pipewire_boundary(self, port_from, port_to):
+        resolved = pedalboard_connection(
+            port_from, port_to, self.rigforge_capture_ports,
+            self.rigforge_playback_ports, self._fix_host_connection_port
+        )
+        if resolved is not None and resolved[0] == "pipewire":
+            return resolved[1]
+        return None''',
+        )
+    replace_host_method(
+        host,
+        "disconnect",
+        '''    def disconnect(self, port_from, port_to, callback):
+        resolved = pedalboard_connection(
+            port_from, port_to, self.rigforge_capture_ports,
+            self.rigforge_playback_ports, self._fix_host_connection_port
+        )
+        if resolved is not None and resolved[0] == "pipewire":
+            pipewire_link = resolved[1]
+            ok = disconnect_link(*pipewire_link)
+            callback(ok)
+            if ok:
+                self.msg_callback("disconnect %s %s" % (port_from, port_to))
+                self.pedalboard_modified = True
+                try:
+                    self.connections.remove((port_from, port_to))
+                except ValueError:
+                    logging.info(
+                        "[host] Requested '%s' => '%s' connection was not in the UI state",
+                        port_from, port_to
+                    )
+            else:
+                logging.error(
+                    "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
+                    pipewire_link[0], pipewire_link[1]
+                )
+            return
+
+        def host_callback(ok):
+            # Upstream disconnect failures are not fatal to the UI state.
+            callback(True)
+            self.msg_callback("disconnect %s %s" % (port_from, port_to))
+            if not ok:
+                logging.error("[host] disconnect '%s' => '%s' failed", port_from, port_to)
+            self.pedalboard_modified = True
+            try:
+                self.connections.remove((port_from, port_to))
+            except ValueError:
+                logging.info(
+                    "[host] NOTE: Requested '%s' => '%s' connection doesn't exist",
+                    port_from, port_to
+                )
+
+        if resolved is not None:
+            port_from_2, port_to_2 = resolved[1]
+        else:
+            try:
+                port_from_2 = self._fix_host_connection_port(port_from)
+            except Exception:
+                logging.info("[host] NOTE: Requested '%s' source port doesn't exist, assume disconnected", port_from)
+                return host_callback(True)
+            try:
+                port_to_2 = self._fix_host_connection_port(port_to)
+            except Exception:
+                logging.info("[host] NOTE: Requested '%s' target port doesn't exist, assume disconnected", port_to)
+                return host_callback(True)
+
+        if len(self.connections) == 0:
+            return host_callback(False)
+        self.send_modified(
+            "disconnect %s %s" % (port_from_2, port_to_2),
+            host_callback,
+            datatype='boolean'
+        )''',
+    )
+
+
+def patch_load_connections(host):
+    """Make pedalboard restore use the same resolution as manual UI actions."""
+    text = host.read_text(encoding="utf-8")
+    method_marker = "    def load_pb_connections("
+    method_start = text.find(method_marker)
+    if method_start < 0:
+        raise RuntimeError(f"could not find Host.load_pb_connections in {host}")
+    block_start = text.find("            if doConnectionNow:", method_start)
+    block_end = text.find(
+        "\n            elif aliasname1 is not None or aliasname2 is not None:",
+        block_start,
+    )
+    if block_start < 0 or block_end < 0:
+        raise RuntimeError(
+            f"could not identify mod-ui pedalboard connection restoration block in {host}"
+        )
+
+    replacement = '''            if doConnectionNow:
+                resolved = pedalboard_connection(
+                    port_from, port_to, self.rigforge_capture_ports,
+                    self.rigforge_playback_ports, self._fix_host_connection_port
+                )
+                if resolved is not None and resolved[0] == "pipewire":
+                    self._rigforge_restore_pipewire_boundary(
+                        resolved[1],
+                        port_from,
+                        port_to,
+                        self.connections,
+                        attempts_left=60
+                    )
+                    continue
+                try:
+                    if resolved is not None:
+                        port_from_2, port_to_2 = resolved[1]
+                    else:
+                        port_from_2 = self._fix_host_connection_port(port_from)
+                        port_to_2 = self._fix_host_connection_port(port_to)
+                except Exception:
+                    continue
+                self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
+                self.connections.append((port_from, port_to))
+                self.msg_callback("connect %s %s" % (port_from, port_to))'''
+    updated = text[:block_start] + replacement + text[block_end:]
+
+    if "    def _rigforge_restore_pipewire_boundary(" not in updated:
+        marker = "    def load_pb_connections("
+        position = updated.find(marker)
+        restore_method = '''    def _rigforge_restore_pipewire_boundary(
+        self, pipewire_link, port_from, port_to, connection_list, attempts_left
+    ):
+        if self.connections is not connection_list:
+            return
+
+        if connect_link(*pipewire_link):
+            edge = (port_from, port_to)
+            if edge not in connection_list:
+                connection_list.append(edge)
+                self.msg_callback("connect %s %s" % (port_from, port_to))
+            return
+
+        if attempts_left <= 1:
+            logging.error(
+                "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
+                pipewire_link[0], pipewire_link[1]
+            )
+            return
+
+        IOLoop.instance().call_later(
+            0.5,
+            self._rigforge_restore_pipewire_boundary,
+            pipewire_link,
+            port_from,
+            port_to,
+            connection_list,
+            attempts_left - 1
+        )
+
+'''
+        if position < 0:
+            raise RuntimeError(f"could not insert PipeWire restore method in {host}")
+        updated = updated[:position] + restore_method + updated[position:]
+
+    if updated != text:
+        host.write_text(updated, encoding="utf-8")
+
+
 def apply(source_root):
     app = Path(source_root)
     helper = Path(__file__).with_name("mod_ui_pipewire.py")
@@ -155,209 +387,6 @@ def apply(source_root):
             if data[2] == "serial_midi_in":
 ''',
     )
-    replace_if_present(
-        app / "mod" / "host.py",
-        '''    def connect(self, port_from, port_to, callback):
-        if (port_from, port_to) in self.connections:
-''',
-        '''    def _rigforge_pipewire_boundary(self, port_from, port_to):
-        return boundary_connection(
-            port_from,
-            port_to,
-            self.rigforge_capture_ports,
-            self.rigforge_playback_ports,
-            self._fix_host_connection_port,
-        )
-
-    def connect(self, port_from, port_to, callback):
-        if (port_from, port_to) in self.connections:
-''',
-    )
-    replace_if_present(
-        app / "mod" / "host.py",
-        '''        def host_callback(ok):
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
-
-        self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
-            self._fix_host_connection_port(port_to)), host_callback)
-''',
-        '''        resolved = pedalboard_connection(
-            port_from, port_to, self.rigforge_capture_ports,
-            self.rigforge_playback_ports, self._fix_host_connection_port
-        )
-        if resolved is not None and resolved[0] == "pipewire":
-            pipewire_link = resolved[1]
-            ok = connect_link(*pipewire_link)
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.pedalboard_modified = True
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error(
-                    "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
-                    pipewire_link[0], pipewire_link[1]
-                )
-            return
-
-        def host_callback(ok):
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
-
-        if resolved is not None:
-            port_from_2, port_to_2 = resolved[1]
-        else:
-            port_from_2 = self._fix_host_connection_port(port_from)
-            port_to_2 = self._fix_host_connection_port(port_to)
-        self.send_modified("connect %s %s" % (port_from_2, port_to_2), host_callback)
-''',
-    )
-    replace_once(
-        app / "mod" / "host.py",
-        '''    def disconnect(self, port_from, port_to, callback):
-        def host_callback(ok):
-''',
-        '''    def disconnect(self, port_from, port_to, callback):
-        pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-        if pipewire_link is not None:
-            ok = disconnect_link(*pipewire_link)
-            callback(ok)
-            if ok:
-                self.msg_callback("disconnect %s %s" % (port_from, port_to))
-                self.pedalboard_modified = True
-                try:
-                    self.connections.remove((port_from, port_to))
-                except ValueError:
-                    logging.info(
-                        "[host] Requested '%s' => '%s' connection was not in the UI state",
-                        port_from, port_to
-                    )
-            else:
-                logging.error(
-                    "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
-                    pipewire_link[0], pipewire_link[1]
-                )
-            return
-
-        def host_callback(ok):
-        ''',
-    )
-    replace_if_present(
-        app / "mod" / "host.py",
-        '''    def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts,
-                                               mappedNewMidiIns, mappedNewMidiOuts):
-''',
-        '''    def _rigforge_restore_pipewire_boundary(
-        self, pipewire_link, port_from, port_to, connection_list, attempts_left
-    ):
-        if self.connections is not connection_list:
-            return
-
-        if connect_link(*pipewire_link):
-            edge = (port_from, port_to)
-            if edge not in connection_list:
-                connection_list.append(edge)
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            return
-
-        if attempts_left <= 1:
-            logging.error(
-                "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
-                pipewire_link[0], pipewire_link[1]
-            )
-            return
-
-        IOLoop.instance().call_later(
-            0.5,
-            self._rigforge_restore_pipewire_boundary,
-            pipewire_link,
-            port_from,
-            port_to,
-            connection_list,
-            attempts_left - 1
-        )
-
-    def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts,
-                                               mappedNewMidiIns, mappedNewMidiOuts):
-''',
-    )
-    load_connections_original = '''                pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-                if pipewire_link is not None:
-                    self._rigforge_restore_pipewire_boundary(
-                        pipewire_link,
-                        port_from,
-                        port_to,
-                        self.connections,
-                        attempts_left=60
-                    )
-                    continue
-                self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-'''
-    load_connections_patched = '''                resolved = pedalboard_connection(
-                    port_from, port_to, self.rigforge_capture_ports,
-                    self.rigforge_playback_ports, self._fix_host_connection_port
-                )
-                if resolved is not None and resolved[0] == "pipewire":
-                    pipewire_link = resolved[1]
-                    self._rigforge_restore_pipewire_boundary(
-                        pipewire_link,
-                        port_from,
-                        port_to,
-                        self.connections,
-                        attempts_left=60
-                    )
-                    continue
-                if resolved is not None:
-                    port_from_2, port_to_2 = resolved[1]
-                self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-'''
-    load_connections_old = '''                pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-                if pipewire_link is not None:
-                    self._rigforge_restore_pipewire_boundary(
-                        pipewire_link,
-                        port_from,
-                        port_to,
-                        self.connections,
-                        attempts_left=60
-                    )
-                    continue
-                self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
-                self.connections.append((port_from, port_to))
-'''
-    text = (app / "mod" / "host.py").read_text(encoding="utf-8")
-    if load_connections_patched not in text:
-        if text.count(load_connections_original) == 1:
-            original = load_connections_original
-        elif text.count(load_connections_old) == 1:
-            original = load_connections_old
-        else:
-            marker = "    def load_pb_connections(self, connections, mappedOldMidiIns"
-            start = text.find(marker)
-            body = text.find("                pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)", start)
-            if start < 0 or body < 0:
-                raise RuntimeError("could not identify mod-ui pedalboard connection restoration block")
-            end = text.find("\n\n            elif aliasname1", body)
-            if end < 0:
-                raise RuntimeError("could not find end of mod-ui pedalboard connection restoration block")
-            original = text[body:end]
-        replace_once(
-            app / "mod" / "host.py",
-            original,
-            load_connections_patched.rstrip("\n"),
-        )
     replace_if_present(
         app / "mod" / "host.py",
         '''        if len(data) == 3:
@@ -373,77 +402,10 @@ def apply(source_root):
             if data[2] == "serial_midi_in":
 ''',
     )
+    host_file = app / "mod" / "host.py"
+    patch_load_connections(host_file)
+    patch_host_connection_methods(host_file)
 
-    replace_if_present(
-        app / "mod" / "host.py",
-        '''        def host_callback(ok):
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
-
-        self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
-            self._fix_host_connection_port(port_to)), host_callback)
-''',
-        '''        pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-        if pipewire_link is not None:
-            ok = connect_link(*pipewire_link)
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.pedalboard_modified = True
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error(
-                    "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
-                    pipewire_link[0], pipewire_link[1]
-                )
-            return
-
-        def host_callback(ok):
-            callback(ok)
-            if ok:
-                self.connections.append((port_from, port_to))
-                self.msg_callback("connect %s %s" % (port_from, port_to))
-            else:
-                logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
-
-        self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
-            self._fix_host_connection_port(port_to)), host_callback)
-''',
-    )
-    replace_once(
-        app / "mod" / "host.py",
-        '''    def disconnect(self, port_from, port_to, callback):
-        def host_callback(ok):
-''',
-        '''    def disconnect(self, port_from, port_to, callback):
-        pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-        if pipewire_link is not None:
-            ok = disconnect_link(*pipewire_link)
-            callback(ok)
-            if ok:
-                self.msg_callback("disconnect %s %s" % (port_from, port_to))
-                self.pedalboard_modified = True
-                try:
-                    self.connections.remove((port_from, port_to))
-                except ValueError:
-                    logging.info(
-                        "[host] Requested '%s' => '%s' connection was not in the UI state",
-                        port_from, port_to
-                    )
-            else:
-                logging.error(
-                    "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
-                    pipewire_link[0], pipewire_link[1]
-                )
-            return
-
-        def host_callback(ok):
-''',
-    )
     replace_if_present(
         app / "mod" / "session.py",
         '''    # Set a plugin block position within the canvas

+ 73 - 13
tests/test_mod_ui_pipewire.py

@@ -1,6 +1,9 @@
+import ast
 import hashlib
 import json
+import shutil
 import sys
+import tempfile
 import unittest
 from pathlib import Path
 from types import SimpleNamespace
@@ -8,6 +11,7 @@ from types import SimpleNamespace
 ROOT = Path(__file__).resolve().parents[1]
 sys.path.insert(0, str(ROOT / "build" / "arm64"))
 
+import patch_mod_ui_rigforge
 from mod_ui_pipewire import (
     boundary_connection,
     connect_link,
@@ -201,29 +205,85 @@ class ModUiPipeWireTests(unittest.TestCase):
         self.assertIn(edge, runner.links)
         self.assertEqual(runner.transient_failures, 0)
 
-    def test_tracked_mod_ui_artifact_matches_its_rebuild_patch_and_provenance(self):
+    def test_tracked_artifact_helper_matches_its_provenance(self):
         artifact = ROOT / "artifacts/mod-ui/arm64/current"
         helper_source = (ROOT / "build/arm64/mod_ui_pipewire.py").read_bytes()
         helper_artifact = artifact / "app/mod/rigforge_pipewire.py"
-        host_source = (artifact / "app/mod/host.py").read_text(encoding="utf-8")
         provenance = json.loads((artifact / "provenance.json").read_text(encoding="utf-8"))
 
         self.assertEqual(helper_artifact.read_bytes(), helper_source)
-        self.assertIn("from mod.rigforge_pipewire import", host_source)
-        self.assertIn("def _rigforge_restore_pipewire_boundary(", host_source)
-        self.assertIn("IOLoop.instance().call_later(", host_source)
-        self.assertIn("attempts_left=60", host_source)
-        self.assertNotIn("retries=60, retry_interval=0.1", host_source)
-        self.assertEqual(host_source.count("PipeWire backend failed to restore ports"), 1)
-        self.assertIn("disconnect_link(*pipewire_link)", host_source)
-        self.assertEqual(
-            provenance["rigforge_integration_patch_sha256"],
-            hashlib.sha256((ROOT / "build/arm64/patch_mod_ui_rigforge.py").read_bytes()).hexdigest(),
-        )
         self.assertEqual(
             provenance["rigforge_pipewire_helper_sha256"],
             hashlib.sha256(helper_source).hexdigest(),
         )
+        patch_source = (ROOT / "build/arm64/patch_mod_ui_rigforge.py").read_bytes()
+        self.assertEqual(
+            provenance["rigforge_integration_patch_sha256"],
+            hashlib.sha256(patch_source).hexdigest(),
+        )
+        build_script = (ROOT / "build/arm64/build-mod-ui.sh").read_text(encoding="utf-8")
+        self.assertIn(
+            'sha256sum "$repository_root/build/arm64/patch_mod_ui_rigforge.py"',
+            build_script,
+        )
+        self.assertIn(
+            'sha256sum "$repository_root/build/arm64/mod_ui_pipewire.py"',
+            build_script,
+        )
+
+    def test_repatches_artifact_connection_paths_idempotently(self):
+        artifact = ROOT / "artifacts/mod-ui/arm64/current/app"
+        with tempfile.TemporaryDirectory() as temporary:
+            app = Path(temporary) / "app"
+            for relative in (
+                "mod/host.py",
+                "mod/session.py",
+                "mod/webserver.py",
+                "server.py",
+                "html/js/pedalboard.js",
+            ):
+                destination = app / relative
+                destination.parent.mkdir(parents=True, exist_ok=True)
+                shutil.copy2(artifact / relative, destination)
+
+            host = app / "mod/host.py"
+            contents = host.read_text(encoding="utf-8")
+            # Exercise the upstream variant with an extra UI callback in the
+            # connection-restoration block.
+            old_callback = '                self.msg_callback("connect %s %s" % (port_from, port_to))'
+            self.assertIn(old_callback, contents)
+            contents = contents.replace(
+                old_callback,
+                old_callback + '\n                self.msg_callback("upstream restore notice")',
+                1,
+            )
+            host.write_text(contents, encoding="utf-8")
+
+            patch_mod_ui_rigforge.apply(app)
+            once = host.read_bytes()
+            patched_text = once.decode("utf-8")
+            self.assertIn("def _rigforge_restore_pipewire_boundary(", patched_text)
+            self.assertNotIn(
+                "pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)",
+                patched_text,
+            )
+            for method_name, next_method in (
+                ("connect", "disconnect"),
+                ("disconnect", "load"),
+            ):
+                start = patched_text.index(f"    def {method_name}(")
+                end = patched_text.index(f"\n    def {next_method}(", start)
+                self.assertIn("resolved = pedalboard_connection(", patched_text[start:end])
+            load_start = patched_text.index("    def load_pb_connections(")
+            load_end = patched_text.find("\n    def ", load_start + 1)
+            self.assertIn(
+                "resolved = pedalboard_connection(",
+                patched_text[load_start:load_end],
+            )
+            ast.parse(patched_text)
+
+            patch_mod_ui_rigforge.apply(app)
+            self.assertEqual(host.read_bytes(), once)
 
 
 if __name__ == "__main__":