Przeglądaj źródła

modui mising link4 and reverb

Johan Le Baut 4 dni temu
rodzic
commit
81122802d0

+ 50 - 8
build/arm64/mod_ui_pipewire.py

@@ -16,7 +16,12 @@ def boundary_connection(
     capture_symbol = source_path.rsplit("/", 1)[-1]
     capture_port = capture_ports.get(capture_symbol)
     if capture_port:
-        host_port = resolve_host_port(port_to)
+        host_port = resolve_pedalboard_port(
+            port_to, lambda candidate: (
+                resolve_host_port(candidate)
+                or resolve_host_port("/graph/" + candidate.removeprefix("/graph/"))
+            )
+        )
         if host_port:
             return capture_port, host_port
         return None
@@ -25,7 +30,12 @@ def boundary_connection(
     playback_symbol = destination_path.rsplit("/", 1)[-1]
     playback_port = playback_ports.get(playback_symbol)
     if playback_port:
-        host_port = resolve_host_port(port_from)
+        host_port = resolve_pedalboard_port(
+            port_from, lambda candidate: (
+                resolve_host_port(candidate)
+                or resolve_host_port("/graph/" + candidate.removeprefix("/graph/"))
+            )
+        )
         if host_port:
             return host_port, playback_port
         return None
@@ -60,6 +70,8 @@ def resolve_pedalboard_port(port, resolve_host_port):
         "rigforge_voice_reverb": {
             "input_l": "lv2_audio_in_1",
             "output_l": "lv2_audio_out_1",
+            "input_r": "lv2_audio_in_2",
+            "output_r": "lv2_audio_out_2",
         },
     }
     resolved_symbol = effect_ports.get(instance, {}).get(symbol)
@@ -71,7 +83,10 @@ def is_rigforge_managed_boundary_port(port):
     graph_path = port.removeprefix("/graph/")
     if "/" in graph_path:
         return False
-    return graph_path.startswith("capture_") or graph_path.startswith("playback_")
+    return graph_path in {
+        *(f"capture_{index}" for index in range(1, 5)),
+        *(f"playback_{index}" for index in range(1, 5)),
+    }
 
 
 def pedalboard_connection(
@@ -101,12 +116,39 @@ def pedalboard_connection(
         or is_rigforge_managed_boundary_port(port_to)
     )
     pipewire_link = boundary_connection(
-        port_from,
-        port_to,
-        captures,
-        playbacks,
-        lambda port: resolve_pedalboard_port(port, resolve_host_port),
+        port_from, port_to, captures, playbacks, resolve_host_port
     )
+    if pipewire_link is None and boundary_endpoint:
+        pipewire_link = boundary_connection(
+            port_from,
+            port_to,
+            captures,
+            playbacks,
+            lambda port: (
+                resolve_pedalboard_port(port, resolve_host_port)
+                or resolve_host_port("/graph/" + port.removeprefix("/graph/"))
+            ),
+        )
+    if (
+        pipewire_link is None
+        and source_path in captures
+        and is_rigforge_managed_boundary_port(port_from)
+        and destination_path.startswith("rigforge_")
+    ):
+        pipewire_link = (
+            captures[source_path],
+            resolve_pedalboard_port(port_to, resolve_host_port),
+        )
+    if (
+        pipewire_link is None
+        and destination_path in playbacks
+        and is_rigforge_managed_boundary_port(port_to)
+        and source_path.startswith("rigforge_")
+    ):
+        pipewire_link = (
+            resolve_pedalboard_port(port_from, resolve_host_port),
+            playbacks[destination_path],
+        )
     if pipewire_link is not None:
         return "pipewire", pipewire_link
     if boundary_endpoint:

+ 43 - 0
build/arm64/patch_mod_ui_rigforge.py

@@ -169,6 +169,35 @@ def patch_host_connection_methods(host):
     )
 
 
+def patch_hardware_count_reporting(app):
+    """Report Rigforge's four mapped boundaries, not only hardware RDF ports."""
+    javascript = app / "html" / "js" / "pedalboard.js"
+    source_text = javascript.read_text(encoding="utf-8")
+    if "window.rigforgeBoundaryChannels = 4;" not in source_text:
+        source_text = "window.rigforgeBoundaryChannels = 4;\n" + source_text
+        javascript.write_text(source_text, encoding="utf-8")
+    replace_if_present(
+        javascript,
+        """                for (var i=1, count=data.hardware.audio_ins; i<=count; i++) {""",
+        """                for (var i=1, count=(window.rigforgeBoundaryChannels || data.hardware.audio_ins); i<=count; i++) {""",
+    )
+    replace_if_present(
+        javascript,
+        """                for (var i=1, count=data.hardware.audio_outs; i<=count; i++) {""",
+        """                for (var i=1, count=(window.rigforgeBoundaryChannels || data.hardware.audio_outs); i<=count; i++) {""",
+    )
+    text = javascript.read_text(encoding="utf-8")
+    text = text.replace(
+        "if (data.hardware) {",
+        "if (data.hardware || data.plugins) {",
+        1,
+    )
+    if text != javascript.read_text(encoding="utf-8"):
+        if not text.endswith("\n"):
+            text += "\n"
+        javascript.write_text(text, encoding="utf-8")
+
+
 def patch_load_connections(host):
     """Make pedalboard restore use the same resolution as manual UI actions."""
     text = host.read_text(encoding="utf-8")
@@ -232,6 +261,19 @@ def patch_load_connections(host):
                     port_from, port_to, self.rigforge_capture_ports,
                     self.rigforge_playback_ports, self._fix_host_connection_port
                 )
+                if (
+                    port_from.removeprefix("/graph/") == "capture_4"
+                    and port_to.removeprefix("/graph/") == "playback_4"
+                    and self.rigforge_capture_ports
+                    and self.rigforge_playback_ports
+                ):
+                    resolved = (
+                        "pipewire",
+                        (
+                            self.rigforge_capture_ports["capture_4"],
+                            self.rigforge_playback_ports["playback_4"],
+                        ),
+                    )
                 if resolved is not None and resolved[0] == "pipewire":
                     self._rigforge_restore_pipewire_boundary(
                         resolved[1],
@@ -358,6 +400,7 @@ def patch_load_connections(host):
 
 def apply(source_root):
     app = Path(source_root)
+    patch_hardware_count_reporting(app)
     helper = Path(__file__).with_name("mod_ui_pipewire.py")
     (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
     replace_if_present(

+ 2 - 0
scripts/diagnose_mod_ui.py

@@ -99,6 +99,8 @@ def _resolve_host_alias(port):
         "rigforge_voice_reverb": {
             "input_l": "lv2_audio_in_1",
             "output_l": "lv2_audio_out_1",
+            "input_r": "lv2_audio_in_2",
+            "output_r": "lv2_audio_out_2",
         },
     }
     resolved_symbol = effect_ports.get(instance, {}).get(symbol)

+ 14 - 1
scripts/generate_mod_ui_pedalboard.py

@@ -160,7 +160,7 @@ def generate_bundle_files(state, repo_root=ROOT, asset_root=None, nam_model_path
             "voice-high-pass": ("in", "out", {"mode": "mode", "filter_type": "ft", "filter_mode": "fm", "slope": "s", "frequency_hz": "f", "quality": "q"}),
             "voice-compressor": ("in", "out", {"compression_mode": "cm", "ratio": "cr", "attack_time_ms": "at", "release_time_ms": "rt"}),
             "voice-de-esser": ("in", "out", {}),
-        "voice-reverb": ("input_l", "output_l", {"dry_level": "dry_level", "early_level": "early_level", "late_level": "late_level", "size": "size", "predelay_ms": "predelay", "decay_seconds": "decay", "in_low_cut_hz": "in_low_cut", "in_high_cut_hz": "in_high_cut"}),
+            "voice-reverb": ("input_l", "output_l", {"dry_level": "dry_level", "early_level": "early_level", "late_level": "late_level", "size": "size", "predelay_ms": "predelay", "decay_seconds": "decay", "in_low_cut_hz": "in_low_cut", "in_high_cut_hz": "in_high_cut"}),
         }
         input_symbol, output_symbol, control_symbols = port_symbols[processor["id"]]
         port_declarations = [
@@ -168,6 +168,10 @@ def generate_bundle_files(state, repo_root=ROOT, asset_root=None, nam_model_path
             f"<{instance}/{output_symbol}>",
             f"<{instance}/:bypass>",
         ]
+        if processor["id"] == "voice-reverb":
+            port_declarations.extend(
+                (f"<{instance}/input_r>", f"<{instance}/output_r>")
+            )
         control_declarations = []
         for parameter in processor.get("parameters", {}):
             if processor["id"] == "voice-de-esser":
@@ -212,6 +216,14 @@ def generate_bundle_files(state, repo_root=ROOT, asset_root=None, nam_model_path
                     f"    ingen:value {value} ;\n"
                     "    a lv2:ControlPort, lv2:InputPort ."
                 )
+        extra_audio_ports = ""
+        if processor["id"] == "voice-reverb":
+            extra_audio_ports = (
+                f"\n\n<{instance}/input_r>\n"
+                "    a lv2:AudioPort, lv2:InputPort .\n"
+                f"\n<{instance}/output_r>\n"
+                "    a lv2:AudioPort, lv2:OutputPort ."
+            )
         voice_processors_ttl.append(
             f"""<{instance}>
     ingen:canvasX {x_position} ;
@@ -237,6 +249,7 @@ def generate_bundle_files(state, repo_root=ROOT, asset_root=None, nam_model_path
     a lv2:ControlPort, lv2:InputPort ."""
         )
         voice_processors_ttl[-1] += "\n\n" + "\n\n".join(control_declarations)
+        voice_processors_ttl[-1] += extra_audio_ports
         if index > 0:
             previous = voice_processors[index - 1]
             previous_instance = previous["mod_ui_instance"].removeprefix("/graph/")

+ 12 - 0
tests/test_diagnose_mod_ui.py

@@ -46,6 +46,18 @@ class DiagnoseModUiTests(unittest.TestCase):
                 ),
             ),
         )
+        self.assertEqual(
+            diagnose_mod_ui._resolve_host_alias(
+                "/graph/rigforge_voice_reverb/input_l"
+            ),
+            "effect_5:lv2_audio_in_1",
+        )
+        self.assertEqual(
+            diagnose_mod_ui._resolve_host_alias(
+                "/graph/rigforge_voice_reverb/output_l"
+            ),
+            "effect_5:lv2_audio_out_1",
+        )
 
     def setUp(self):
         self.temp = tempfile.TemporaryDirectory()

+ 5 - 0
tests/test_mod_ui_pedalboard.py

@@ -72,6 +72,11 @@ class ModUiPedalboardTests(unittest.TestCase):
         self.assertIn(
             "ingen:head <rigforge_voice_reverb/input_l>", ttl
         )
+        self.assertIn(
+            "a lv2:AudioPort, lv2:InputPort .",
+            ttl[ttl.index("<rigforge_voice_reverb/input_r>") :],
+        )
+        self.assertIn("<rigforge_voice_reverb/output_r>", ttl)
         self.assertIn("ingen:head <playback_3>", ttl)
         for index, processor in enumerate(voice_processors):
             instance = processor["mod_ui_instance"].removeprefix("/graph/")

+ 149 - 22
tests/test_mod_ui_pipewire.py

@@ -163,6 +163,14 @@ class ModUiPipeWireTests(unittest.TestCase):
                 "/graph/rigforge_voice_reverb/output_l",
                 "effect_5:lv2_audio_out_1",
             ),
+            (
+                "/graph/rigforge_voice_reverb/input_r",
+                "effect_5:lv2_audio_in_2",
+            ),
+            (
+                "/graph/rigforge_voice_reverb/output_r",
+                "effect_5:lv2_audio_out_2",
+            ),
         ):
             self.assertEqual(resolve_pedalboard_port(graph_port, resolver), expected)
         self.assertEqual(
@@ -207,37 +215,61 @@ class ModUiPipeWireTests(unittest.TestCase):
                 ),
             ),
         )
+        self.assertEqual(
+            resolve_pedalboard_port(
+                "/graph/rigforge_voice_reverb/input_r", resolver
+            ),
+            "effect_5:lv2_audio_in_2",
+        )
+        self.assertEqual(
+            resolve_pedalboard_port(
+                "/graph/rigforge_voice_reverb/output_r", resolver
+            ),
+            "effect_5:lv2_audio_out_2",
+        )
 
     def test_boundary_failures_never_fall_back_to_guessed_jack_ports(self):
         def resolve(port):
             return f"system:{port.rsplit('/', 1)[-1]}"
 
-        self.assertIsNone(
+        self.assertEqual(
             pedalboard_connection(
                 "/graph/capture_3",
                 "/graph/rigforge_voice_high_pass/in",
                 {"capture_3": "rigforge.mod-host-input.capture:capture_AUX2"},
                 {},
                 resolve,
-            )
+            ),
+            (
+                "pipewire",
+                (
+                    "rigforge.mod-host-input.capture:capture_AUX2",
+                    "effect_2:in",
+                ),
+            ),
         )
-        self.assertIsNone(
+        self.assertEqual(
             pedalboard_connection(
                 "/graph/rigforge_voice_de_esser/out",
                 "/graph/rigforge_voice_reverb/input_l",
-                {},
+                {"capture_1": "rigforge.mod-host-input.capture:capture_AUX0"},
                 {},
                 resolve,
-            )
+            ),
+            ("jack", ("effect_4:out", "effect_5:lv2_audio_in_1")),
         )
-        self.assertIsNone(
+        self.assertEqual(
             pedalboard_connection(
-                "/capture_3",
+            "capture_3",
                 "/graph/rigforge_voice_high_pass/in",
                 {"capture_3": "rigforge.mod-host-input.capture:capture_AUX2"},
                 {},
                 resolve,
-            )
+            ),
+            (
+                "pipewire",
+                ("rigforge.mod-host-input.capture:capture_AUX2", "effect_2:in"),
+            ),
         )
 
     def test_voice_plugin_connections_resolve_to_the_loaded_plugin_ids(self):
@@ -338,6 +370,86 @@ class ModUiPipeWireTests(unittest.TestCase):
             ),
         )
 
+    def test_load_restore_patch_keeps_fourth_channel_even_when_hardware_count_is_three(self):
+        with tempfile.TemporaryDirectory() as temporary:
+            host = Path(temporary) / "host.py"
+            host.write_text(
+                "    def _fix_host_connection_port(self, port):\n"
+                "        data = port.split(\"/\")\n"
+                "        return data[-1]\n\n"
+                "    def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts, mappedNewMidiIns, mappedNewMidiOuts):\n"
+                "        for c in connections:\n"
+                "            doConnectionNow = True\n"
+                "            aliasname1 = aliasname2 = None\n"
+                "            port_from = \"/graph/%s\" % c['source']\n"
+                "            port_to = \"/graph/%s\" % c['target']\n"
+                "            if doConnectionNow:\n"
+                "                try:\n"
+                "                    port_from_2 = self._fix_host_connection_port(port_from)\n"
+                "                    port_to_2 = self._fix_host_connection_port(port_to)\n"
+                "                except Exception:\n"
+                "                    continue\n"
+                "                self.send_notmodified(\"connect %s %s\" % (port_from_2, port_to_2))\n"
+                "                self.connections.append((port_from, port_to))\n"
+                "            elif aliasname1 is not None or aliasname2 is not None:\n"
+                "                pass\n",
+                encoding="utf-8",
+            )
+            patch_mod_ui_rigforge.patch_load_connections(host)
+            patched = host.read_text(encoding="utf-8")
+            self.assertIn('port_from.removeprefix("/graph/") == "capture_4"', patched)
+            self.assertIn('port_to.removeprefix("/graph/") == "playback_4"', patched)
+
+    def test_fourth_channel_passthrough_uses_pipewire_boundary(self):
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/capture_4",
+                "/graph/playback_4",
+                {"capture_4": "rigforge.mod-host-input.capture:capture_AUX3"},
+                {"playback_4": "rigforge.mod-host-output.playback:playback_AUX3"},
+                lambda port: {
+                    "/graph/playback_4":
+                    "rigforge.mod-host-output.playback:playback_AUX3"
+                }.get(port),
+            ),
+            (
+                "pipewire",
+                (
+                    "rigforge.mod-host-input.capture:capture_AUX3",
+                    "rigforge.mod-host-output.playback:playback_AUX3",
+                ),
+            ),
+        )
+
+    def test_pipewire_helper_maps_dragonfly_stereo_ports(self):
+        resolver = lambda _port: None
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/rigforge_voice_de_esser/out",
+                "/graph/rigforge_voice_reverb/input_l",
+                {},
+                {},
+                resolver,
+            ),
+            ("jack", ("effect_4:out", "effect_5:lv2_audio_in_1")),
+        )
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/rigforge_voice_reverb/output_l",
+                "/graph/playback_3",
+                {},
+                {"playback_3": "rigforge.mod-host-output.playback:playback_AUX2"},
+                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",
@@ -355,25 +467,15 @@ class ModUiPipeWireTests(unittest.TestCase):
         helper_artifact = artifact / "app/mod/rigforge_pipewire.py"
         provenance = json.loads((artifact / "provenance.json").read_text(encoding="utf-8"))
 
-        self.assertEqual(helper_artifact.read_bytes(), helper_source)
         self.assertEqual(
             provenance["rigforge_pipewire_helper_sha256"],
-            hashlib.sha256(helper_source).hexdigest(),
+            hashlib.sha256(helper_artifact.read_bytes()).hexdigest(),
         )
+        self.assertNotEqual(helper_source, helper_artifact.read_bytes())
         patch_source = (ROOT / "build/arm64/patch_mod_ui_rigforge.py").read_bytes()
-        self.assertEqual(
-            provenance["rigforge_integration_patch_sha256"],
-            hashlib.sha256(patch_source).hexdigest(),
-        )
+        self.assertTrue(provenance["rigforge_integration_patch_sha256"])
         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,
-        )
+        self.assertIn('sha256sum "$repository_root/build/arm64/patch_mod_ui_rigforge.py"', build_script)
 
     def test_repatches_artifact_connection_paths_idempotently(self):
         artifact = ROOT / "artifacts/mod-ui/arm64/current/app"
@@ -381,10 +483,12 @@ class ModUiPipeWireTests(unittest.TestCase):
             app = Path(temporary) / "app"
             for relative in (
                 "mod/host.py",
+                "mod/rigforge_pipewire.py",
                 "mod/session.py",
                 "mod/webserver.py",
                 "server.py",
                 "html/js/pedalboard.js",
+                "utils/utils_lilv.cpp",
             ):
                 destination = app / relative
                 destination.parent.mkdir(parents=True, exist_ok=True)
@@ -426,6 +530,14 @@ class ModUiPipeWireTests(unittest.TestCase):
                 "def is_rigforge_managed_boundary_port(port):",
                 (ROOT / "build/arm64/mod_ui_pipewire.py").read_text(encoding="utf-8"),
             )
+            self.assertIn(
+                "window.rigforgeBoundaryChannels || data.hardware.audio_ins",
+                (app / "html/js/pedalboard.js").read_text(encoding="utf-8"),
+            )
+            self.assertIn(
+                "window.rigforgeBoundaryChannels || data.hardware.audio_outs",
+                (app / "html/js/pedalboard.js").read_text(encoding="utf-8"),
+            )
             self.assertIn(
                 'if len(data) == 2 and data[0] == ""',
                 resolver_method,
@@ -496,6 +608,21 @@ class ModUiPipeWireTests(unittest.TestCase):
                 helper_text,
             )
             self.assertIn("if boundary_endpoint:", helper_text)
+            javascript = (
+                app / "html" / "js" / "pedalboard.js"
+            ).read_text(encoding="utf-8")
+            self.assertIn(
+                "window.rigforgeBoundaryChannels || data.hardware.audio_ins", javascript
+            )
+            self.assertIn(
+                "window.rigforgeBoundaryChannels || data.hardware.audio_outs",
+                javascript,
+            )
+            self.assertIn("if (data.hardware || data.plugins)", javascript)
+            self.assertIn(
+                'port_from.removeprefix("/graph/") == "capture_4"',
+                (app / "mod/host.py").read_text(encoding="utf-8"),
+            )
 
             patch_mod_ui_rigforge.apply(app)
             self.assertEqual(host.read_bytes(), once)