Quellcode durchsuchen

mod host reverb fixing

Johan Le Baut vor 5 Tagen
Ursprung
Commit
c415f43409

+ 17 - 3
artifacts/mod-ui/arm64/current/app/mod/host.py

@@ -31,7 +31,12 @@ try:
 except ImportError:
     pass
 
-from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link
+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,
@@ -4431,8 +4436,15 @@ class Host(object):
                     port_to_2   = self._fix_host_connection_port(port_to)
                 except:
                     continue
-                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]
                     self._rigforge_restore_pipewire_boundary(
                         pipewire_link,
                         port_from,
@@ -4441,6 +4453,8 @@ class Host(object):
                         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))

+ 37 - 1
artifacts/mod-ui/arm64/current/app/mod/rigforge_pipewire.py

@@ -49,12 +49,48 @@ def resolve_pedalboard_port(port, resolve_host_port):
         "rigforge_voice_high_pass": {"in": "in", "out": "out"},
         "rigforge_voice_compressor": {"in": "in", "out": "out"},
         "rigforge_voice_de_esser": {"in": "in", "out": "out"},
-        "rigforge_voice_reverb": {"input_l": "input_l", "output_l": "output_l"},
+        "rigforge_voice_reverb": {
+            "input_l": "lv2_audio_in_1",
+            "output_l": "lv2_audio_out_1",
+        },
     }
     resolved_symbol = effect_ports.get(instance, {}).get(symbol)
     return f"effect_{effect_index}:{resolved_symbol}" if resolved_symbol else None
 
 
+def pedalboard_connection(
+    port_from,
+    port_to,
+    capture_ports,
+    playback_ports,
+    resolve_host_port,
+):
+    """Resolve a pedalboard edge to a JACK or concrete PipeWire link."""
+    source_path = port_from.removeprefix("/graph/")
+    destination_path = port_to.removeprefix("/graph/")
+    captures = dict(capture_ports)
+    playbacks = dict(playback_ports)
+    if "/" in source_path:
+        captures = {}
+    if "/" in destination_path:
+        playbacks = {}
+    pipewire_link = boundary_connection(
+        port_from,
+        port_to,
+        captures,
+        playbacks,
+        lambda port: resolve_pedalboard_port(port, resolve_host_port),
+    )
+    if pipewire_link is not None:
+        return "pipewire", pipewire_link
+
+    source = resolve_pedalboard_port(port_from, resolve_host_port)
+    destination = resolve_pedalboard_port(port_to, resolve_host_port)
+    if source is None or destination is None:
+        return None
+    return "jack", (source, destination)
+
+
 def _link_status(source, destination, runner):
     try:
         result = runner(

+ 2 - 2
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": "662124563f591460607a9c76a9f5d8afc39ddb85cf1a44d9d469fc73bf35fac3",
+  "rigforge_integration_patch_sha256": "c3260a0fb11589cfd0153c99fcb413810c184b6f90f13d56fe4b3aeb6b2bbf74",
   "license": "AGPL-3.0-or-later",
   "rigforge_pipewire_helper": "build/arm64/mod_ui_pipewire.py",
-  "rigforge_pipewire_helper_sha256": "749ba23c5f8417e4fc449786c15db5a72562d0cc739c54c25816252c627dd78e"
+  "rigforge_pipewire_helper_sha256": "326d79b8fbfaf740cd4eb99d24d6daceaffcac019f40a768913c58a74db16719"
 }

+ 37 - 1
build/arm64/mod_ui_pipewire.py

@@ -49,12 +49,48 @@ def resolve_pedalboard_port(port, resolve_host_port):
         "rigforge_voice_high_pass": {"in": "in", "out": "out"},
         "rigforge_voice_compressor": {"in": "in", "out": "out"},
         "rigforge_voice_de_esser": {"in": "in", "out": "out"},
-        "rigforge_voice_reverb": {"input_l": "input_l", "output_l": "output_l"},
+        "rigforge_voice_reverb": {
+            "input_l": "lv2_audio_in_1",
+            "output_l": "lv2_audio_out_1",
+        },
     }
     resolved_symbol = effect_ports.get(instance, {}).get(symbol)
     return f"effect_{effect_index}:{resolved_symbol}" if resolved_symbol else None
 
 
+def pedalboard_connection(
+    port_from,
+    port_to,
+    capture_ports,
+    playback_ports,
+    resolve_host_port,
+):
+    """Resolve a pedalboard edge to a JACK or concrete PipeWire link."""
+    source_path = port_from.removeprefix("/graph/")
+    destination_path = port_to.removeprefix("/graph/")
+    captures = dict(capture_ports)
+    playbacks = dict(playback_ports)
+    if "/" in source_path:
+        captures = {}
+    if "/" in destination_path:
+        playbacks = {}
+    pipewire_link = boundary_connection(
+        port_from,
+        port_to,
+        captures,
+        playbacks,
+        lambda port: resolve_pedalboard_port(port, resolve_host_port),
+    )
+    if pipewire_link is not None:
+        return "pipewire", pipewire_link
+
+    source = resolve_pedalboard_port(port_from, resolve_host_port)
+    destination = resolve_pedalboard_port(port_to, resolve_host_port)
+    if source is None or destination is None:
+        return None
+    return "jack", (source, destination)
+
+
 def _link_status(source, destination, runner):
     try:
         result = runner(

+ 67 - 60
build/arm64/patch_mod_ui_rigforge.py

@@ -30,7 +30,7 @@ def apply(source_root):
     replace_if_present(
         app / "mod" / "host.py",
         "from mod import (\n",
-        "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link\n"
+        "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
         "from mod import (\n",
     )
 
@@ -144,10 +144,6 @@ def apply(source_root):
         app / "mod" / "host.py",
         '''        if len(data) == 3:
             # Handle special cases
-            if data[2] in self.rigforge_capture_ports:
-                return self.rigforge_capture_ports[data[2]]
-            if data[2] in self.rigforge_playback_ports:
-                return self.rigforge_playback_ports[data[2]]
             if data[2] == "serial_midi_in":
 ''' + "        \n",
         '''        if len(data) == 3:
@@ -159,7 +155,7 @@ def apply(source_root):
             if data[2] == "serial_midi_in":
 ''',
     )
-    replace_once(
+    replace_if_present(
         app / "mod" / "host.py",
         '''    def connect(self, port_from, port_to, callback):
         if (port_from, port_to) in self.connections:
@@ -177,7 +173,7 @@ def apply(source_root):
         if (port_from, port_to) in self.connections:
 ''',
     )
-    replace_once(
+    replace_if_present(
         app / "mod" / "host.py",
         '''        def host_callback(ok):
             callback(ok)
@@ -190,8 +186,12 @@ def apply(source_root):
         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:
+        '''        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:
@@ -213,8 +213,12 @@ def apply(source_root):
             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)
+        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(
@@ -247,7 +251,7 @@ def apply(source_root):
         def host_callback(ok):
         ''',
     )
-    replace_once(
+    replace_if_present(
         app / "mod" / "host.py",
         '''    def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts,
                                                mappedNewMidiIns, mappedNewMidiOuts):
@@ -286,21 +290,7 @@ def apply(source_root):
                                                mappedNewMidiIns, mappedNewMidiOuts):
 ''',
     )
-    replace_if_present(
-        app / "mod" / "host.py",
-        '''                pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
-                if pipewire_link is not None:
-                    if not connect_link(*pipewire_link, retries=60, retry_interval=0.1):
-                        logging.error(
-                            "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
-                            pipewire_link[0], pipewire_link[1]
-                        )
-                        continue
-                else:
-                    self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
-                self.connections.append((port_from, port_to))
-''',
-        '''                pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
+    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,
@@ -312,14 +302,29 @@ def apply(source_root):
                     continue
                 self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
                 self.connections.append((port_from, port_to))
-''',
-    )
-    replace_once(
-        app / "mod" / "host.py",
-        '''                self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
+                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))
-''',
-        '''                pipewire_link = self._rigforge_pipewire_boundary(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,
@@ -331,9 +336,29 @@ def apply(source_root):
                     continue
                 self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
                 self.connections.append((port_from, port_to))
-''',
-    )
-    replace_once(
+'''
+    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:
             # Handle special cases
@@ -349,25 +374,7 @@ def apply(source_root):
 ''',
     )
 
-    replace_once(
-        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_once(
+    replace_if_present(
         app / "mod" / "host.py",
         '''        def host_callback(ok):
             callback(ok)
@@ -437,7 +444,7 @@ def apply(source_root):
         def host_callback(ok):
 ''',
     )
-    replace_once(
+    replace_if_present(
         app / "mod" / "session.py",
         '''    # Set a plugin block position within the canvas
 ''',
@@ -461,7 +468,7 @@ def apply(source_root):
 ''',
     )
 
-    replace_once(
+    replace_if_present(
         app / "mod" / "webserver.py",
         '''        elif cmd == "plugin_pos":
 ''',
@@ -482,12 +489,12 @@ def apply(source_root):
 ''',
     )
 
-    replace_once(
+    replace_if_present(
         app / "server.py",
         "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
         "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
     )
-    replace_once(
+    replace_if_present(
         app / "server.py",
         "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
         "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",

+ 15 - 1
scripts/run_mod_ui_service.py

@@ -68,7 +68,21 @@ def _resolve_host_alias(port):
         "rigforge_voice_reverb": 5,
     }
     if instance in instance_indices:
-        return f"effect_{instance_indices[instance]}:{symbol}"
+        effect_ports = {
+            "rigforge_voice_high_pass": {"in": "in", "out": "out"},
+            "rigforge_voice_compressor": {"in": "in", "out": "out"},
+            "rigforge_voice_de_esser": {"in": "in", "out": "out"},
+            "rigforge_voice_reverb": {
+                "input_l": "lv2_audio_in_1",
+                "output_l": "lv2_audio_out_1",
+            },
+        }
+        resolved_symbol = effect_ports.get(instance, {}).get(symbol)
+        return (
+            f"effect_{instance_indices[instance]}:{resolved_symbol}"
+            if resolved_symbol
+            else port
+        )
     return port
 
 

+ 40 - 1
tests/test_mod_ui_pipewire.py

@@ -12,6 +12,7 @@ from mod_ui_pipewire import (
     boundary_connection,
     connect_link,
     disconnect_link,
+    pedalboard_connection,
     resolve_pedalboard_port,
 )
 
@@ -143,7 +144,11 @@ class ModUiPipeWireTests(unittest.TestCase):
             ("/graph/rigforge_voice_high_pass/in", "effect_2:in"),
             ("/graph/rigforge_voice_compressor/out", "effect_3:out"),
             ("/graph/rigforge_voice_de_esser/in", "effect_4:in"),
-            ("/graph/rigforge_voice_reverb/input_l", "effect_5:input_l"),
+            ("/graph/rigforge_voice_reverb/input_l", "effect_5:lv2_audio_in_1"),
+            (
+                "/graph/rigforge_voice_reverb/output_l",
+                "effect_5:lv2_audio_out_1",
+            ),
         ):
             self.assertEqual(resolve_pedalboard_port(graph_port, resolver), expected)
         self.assertEqual(
@@ -151,6 +156,40 @@ class ModUiPipeWireTests(unittest.TestCase):
             "/graph/rigforge_ir/out",
         )
 
+    def test_resolves_plugin_edges_and_voice_playback_boundary(self):
+        captures = {"capture_3": "rigforge.mod-host-input.capture:capture_AUX2"}
+        playbacks = {
+            "playback_3": "rigforge.mod-host-output.playback:playback_AUX2"
+        }
+        resolver = lambda port: port
+
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/rigforge_voice_de_esser/out",
+                "/graph/rigforge_voice_reverb/input_l",
+                captures,
+                playbacks,
+                resolver,
+            ),
+            ("jack", ("effect_4:out", "effect_5:lv2_audio_in_1")),
+        )
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/rigforge_voice_reverb/output_l",
+                "/graph/playback_3",
+                captures,
+                playbacks,
+                resolver,
+            ),
+            (
+                "pipewire",
+                (
+                    "effect_5:lv2_audio_out_1",
+                    "rigforge.mod-host-output.playback:playback_AUX2",
+                ),
+            ),
+        )
+
     def test_connect_retries_transient_startup_port_registration_failure(self):
         edge = (
             "rigforge.mod-host-input.capture:capture_AUX0",

+ 6 - 6
tests/test_run_mod_ui_service.py

@@ -130,8 +130,8 @@ class ModUiStartupPipeWireTests(unittest.TestCase):
                 "effect_3:out",
                 "effect_4:in",
                 "effect_4:out",
-                "effect_5:input_l",
-                "effect_5:output_l",
+                "effect_5:lv2_audio_in_1",
+                "effect_5:lv2_audio_out_1",
                 "rigforge.mod-host-output.playback:playback_AUX2",
             ),
         )
@@ -143,8 +143,8 @@ class ModUiStartupPipeWireTests(unittest.TestCase):
                 stdout=(
                     "effect_2:out\n  |-> effect_3:in\n"
                     "effect_3:out\n  |-> effect_4:in\n"
-                    "effect_4:out\n  |-> effect_5:input_l\n"
-                    f"effect_5:output_l\n  |-> {self.playbacks[2]}\n"
+                    "effect_4:out\n  |-> effect_5:lv2_audio_in_1\n"
+                    f"effect_5:lv2_audio_out_1\n  |-> {self.playbacks[2]}\n"
                 ),
             ),
             timeout=0,
@@ -154,13 +154,13 @@ class ModUiStartupPipeWireTests(unittest.TestCase):
         runner = lambda *_args, **_kwargs: SimpleNamespace(
             returncode=0,
             stdout=(
-                f"effect_4:out\n  |-> effect_5:input_l\n"
+                f"effect_4:out\n  |-> effect_5:lv2_audio_in_1\n"
                 f"effect_5:output_r\n  |-> {self.playbacks[2]}\n"
             ),
         )
         with self.assertRaisesRegex(
             RuntimeError,
-            "effect_5:output_l -> " + self.playbacks[2],
+            "effect_5:lv2_audio_out_1 -> " + self.playbacks[2],
         ):
             wait_for_graph_links(
                 (