瀏覽代碼

bind midi sooperlooper

Johan Le Baut 1 周之前
父節點
當前提交
abf1c20250
共有 4 個文件被更改,包括 110 次插入 和 14 次删除
  1. 10 6
      README.md
  2. 7 1
      config/desired-state.yaml
  3. 18 6
      scripts/observe_pipewire.py
  4. 75 1
      tests/test_pipewire_observer.py

+ 10 - 6
README.md

@@ -22,7 +22,7 @@ sudo apt upgrade
 sudo apt install --no-install-recommends \\
   rtkit pipewire pipewire-jack wireplumber \\
   libspa-0.2-modules liblo-tools git \\
-  librubberband2 lilv-utils libcairo2 python3-rtmidi
+  librubberband2 lilv-utils libcairo2 python3-rtmidi libncurses6
 ```
 
 This records the preparation already performed on `rigforge` and is a starting point for documenting a second Pi. It is not yet a verified, version-pinned rebuild procedure: package versions, additional runtime dependencies, audio configuration, and service setup still need to be confirmed before reusing it as a complete deployment recipe.
@@ -58,7 +58,7 @@ For an initial read-only graph observation on a system with `pw-link`, run:
 python3 scripts/observe_pipewire.py
 ```
 
-The observer reads `pw-link -l` and compares only connections whose endpoints are explicitly listed under `routing.managed_ports`; expected edges go in `routing.managed_links`. Exact obsolete edges that may be removed by explicit reconciliation must be separately listed under `routing.managed_unlinks`. The current YAML declares the three guitar NAM/cabinet edges, the voice mixer edge, the mixer output edge, and the obsolete direct guitar bypass for removal. WirePlumber's unrelated hardware links remain outside project management. The default command only reports differences and never changes the graph; declared removals appear as `would-unlink`, while all other unexpected links remain `would-review`.
+The observer reads `pw-link -l` and compares only connections whose endpoints are explicitly listed under `routing.managed_ports`; expected edges go in `routing.managed_links`. Exact obsolete edges that may be removed by explicit reconciliation must be separately listed under `routing.managed_unlinks`. The current YAML declares the guitar NAM/cabinet edges, the voice mixer edge, the mixer output edge, the UMC MIDI bridge to SooperLooper's JACK MIDI input, and the obsolete direct guitar bypass for removal. WirePlumber's unrelated hardware links remain outside project management. The default command only reports differences and never changes the graph; declared removals appear as `would-unlink`, while all other unexpected links remain `would-review`.
 
 An explicit one-shot mode can create missing declared links after checking that the source and destination ports exist, then remove only present links explicitly declared in `routing.managed_unlinks`:
 
@@ -66,7 +66,9 @@ An explicit one-shot mode can create missing declared links after checking that
 python3 scripts/observe_pipewire.py --reconcile-once
 ```
 
-This mode never removes an unlisted link, changes undeclared connections, or restarts services. It attempts declared additions first and removes explicitly listed stale links only after every desired managed link is visible; if any desired link remains missing, removals are deferred. An `unavailable-port` action names the missing endpoint and its expected direction; missing `effect_0`/`effect_1` ports include a hint to start/check mod-host and plugin loading. It then re-reads the graph and reports remaining differences. Use it only during a safe test window: repaired or removed links can immediately change audible routing. Unit tests use simulated `pw-link` results.
+This mode never removes an unlisted link, changes undeclared connections, or restarts services. It attempts declared additions first and removes explicitly listed stale links only after every desired managed link is visible; if any desired link remains missing, removals are deferred. An `unavailable-port` action names the missing endpoint and its expected direction; missing effect ports hint to check mod-host, and a missing `sooperlooper:midi_in` hints to check the SooperLooper service. It then re-reads the graph and reports remaining differences. Use it only during a safe test window: repaired or removed links can immediately change audio or MIDI control routing. Unit tests use simulated `pw-link` results.
+
+The declared MIDI edge is a PipeWire graph connection from `Midi-Bridge:UMC404HD 192k MIDI 1 (capture)` to `sooperlooper:midi_in`. The latter is SooperLooper's JACK MIDI input; its engine feeds events through the loaded `.slb` bindings. This is separate from an ALSA sequencer `aconnect` subscription. Do not keep both paths active: duplicate MIDI events could execute a binding twice.
 
 On 2026-11-18, the target owner deliberately removed the managed AUX2 capture-to-mixer link during a safe test. Observation reported that single link as missing. After updating `rigforge` to commit `83fb0a7`, `--reconcile-once` requested the link, and the final check reported `differences: []`. A subsequent read-only observation also reported no differences, the microphone was confirmed audible again, and all 20 unit tests passed on the target. In a later target test, restarting `filter-chain.service` removed all three managed links; explicit `--reconcile-once` requested all three, and the final observer again reported `differences: []`. Audio audibility after this later repair was not reported. These tests verify one-shot repair on the current target, not continuous reconciliation or recovery when ports are unavailable. After any filter-chain service restart, run the read-only observer and, during a safe test window, explicitly reconcile if links are missing.
 
@@ -130,7 +132,7 @@ For LSP and Dragonfly Reverb, the YAML declares tags and release URLs, and the i
 
 `install sooperlooper` installs and enables an explicit `systemd --user` service; it is excluded from `install all`. The service runs the ARM64 artifact at `artifacts/sooperlooper/arm64/current/sooperlooper` through `/usr/bin/pw-jack` and loads `config/sooperlooper/fcb1010.slb`. The `-l` and `-c` arguments are rendered from the looper component's `loop_count` and `channels_per_loop` in `config/desired-state.yaml` (currently 1 and 4); `-t` is configured by `deployment.sooperlooper.timeout_seconds` (currently 30). The same build also produces the optional ARM64 `slconsole` OSC terminal client at `artifacts/sooperlooper/arm64/current/slconsole`; it is not installed or launched by the service.
 
-After startup, the unit waits four seconds and sends `/sl/0/set sf discrete_prefader 0` to `127.0.0.1:9951` with `/usr/bin/oscsend`. The delay, OSC endpoint, and `discrete_prefader` value are also declared in the desired state. This initializes the control expected by the FCB's volume bindings. It does not establish the audio links between SooperLooper, the sources, and the mixer; those routes and target behavior remain to be verified.
+After startup, the unit waits four seconds and sends `/sl/0/set sf discrete_prefader 0` to `127.0.0.1:9951` with `/usr/bin/oscsend`. The delay, OSC endpoint, and `discrete_prefader` value are also declared in the desired state. This initializes the control expected by the FCB's volume bindings. The service itself does not create PipeWire links: the graph-wide observer/reconciler manages the declared audio routes and the UMC MIDI bridge to SooperLooper's JACK MIDI input.
 
 ```sh
 ./scripts/deploy.sh install sooperlooper
@@ -138,7 +140,7 @@ systemctl --user status rigforge-sooperlooper.service
 journalctl -f _SYSTEMD_USER_UNIT=rigforge-sooperlooper.service
 ```
 
-Install requires the built ARM64 artifact, the tracked `.slb` file, and target runtime dependencies including `oscsend` from `liblo-tools`. The helper preserves any prior unit file and refuses to overwrite or remove locally edited managed units. It does not use `sudo` or restart PipeWire/WirePlumber. The owner reports that the service is installed on `rigforge`; OSC behavior, FCB control, and audio routing still need target verification.
+Install requires the built ARM64 artifact, the tracked `.slb` file, and target runtime dependencies including `oscsend` from `liblo-tools`. The helper preserves any prior unit file and refuses to overwrite or remove locally edited managed units. It does not use `sudo` or restart PipeWire/WirePlumber. The owner reports that the service is installed on `rigforge`; OSC initialization and service recovery still need target verification.
 
 Remove the service with `./scripts/deploy.sh uninstall sooperlooper`.
 
@@ -229,13 +231,15 @@ A PipeWire restart on the same date propagated to mod-host through `PartOf=`, bu
 
 On 2026-11-20, the direct mixer was expanded from four to eight mono inputs on the target, retaining AUX0–AUX3 for direct sources and adding AUX4–AUX7 for SooperLooper returns, all initially at gain 0.2. The target's observed ports confirmed the post-IR guitar branch into `sooperlooper:loop0_in_1`, capture AUX1–AUX3 into looper inputs 2–4, and the four `loop0_out` channels returning to mixer AUX4–AUX7. The direct post-IR guitar-to-AUX0 path remains connected. One-shot reconciliation completed with no remaining graph differences. This verifies links exist, not audible loop recording/playback or headroom with summed returns.
 
+On 2026-11-21, MIDI Note 1 was observed at the UMC ALSA port but did not reach SooperLooper through the ALSA sequencer path. A temporary direct `aconnect` link made all `.slb` bindings work. The owner removed that link and tested the PipeWire graph edge from `Midi-Bridge:UMC404HD 192k MIDI 1 (capture)` to `sooperlooper:midi_in`; the bindings then worked through SooperLooper's JACK MIDI input. This PipeWire edge is now declared for observation and explicit reconciliation. Automatic restoration by this updated repository version has not yet been deployed or verified on the target.
+
 The remaining target checks are:
 
 1. The read-only observer and one-shot repair have been tested on `rigforge`. Repairing one missing link restored the audible microphone path; after a later filter-chain service restart, reconciliation requested all three missing links and the observer reported no differences. The observer now also tracks the three guitar NAM/cabinet links. Do not run one-shot reconciliation against an older checkout: it could restore the dry guitar bypass.
 2. Test direct mixer inputs 2 and 4 with sources when available; their direct-to-mix routes remain unverified. Looper capture inputs 2–4 are now linked but have not been tested with instruments.
 3. Measure sustained stability and headroom at 48 kHz / 128 frames with all active sources; the current `ERR = 0` observation was brief.
 4. Re-test mod-host startup after installing the new port-readiness guard, then verify reboot with lingering enabled, startup resource limits, and recovery when an LV2 plugin fails to load.
-5. The owner has manually verified FCB notes 6–9 switching the guitar NAM models through the bridge, with near-instant reported transitions. The `midi-bridge` and `sooperlooper` services are installable locally, and the owner reports SooperLooper is installed on `rigforge`. Verify unattended startup and UMC unplug/replug recovery, SooperLooper OSC startup, the supplied FCB1010 bindings, audio routing, and the effect and persistence of `discrete_prefader 0` separately.
+5. The owner has manually verified FCB notes 6–9 switching the guitar NAM models through the bridge, with near-instant reported transitions. SooperLooper's supplied FCB1010 bindings were also tested successfully over the declared PipeWire MIDI edge. Verify that the updated observer restores this edge after reboot, service restart, and UMC unplug/replug; verify unattended startup, OSC initialization, audio routing, and the persistence/effect of `discrete_prefader 0` separately.
 
 Do not treat planned packages, commands, ports, or service settings as target-validated until these checks have been performed.
 

+ 7 - 1
config/desired-state.yaml

@@ -243,6 +243,8 @@ routing:
     - sooperlooper:loop0_out_2
     - sooperlooper:loop0_out_3
     - sooperlooper:loop0_out_4
+    - Midi-Bridge:UMC404HD 192k MIDI 1 (capture)
+    - sooperlooper:midi_in
     - rigforge.direct-mix.input:playback_AUX0
     - rigforge.direct-mix.input:playback_AUX1
     - rigforge.direct-mix.input:playback_AUX2
@@ -290,6 +292,9 @@ routing:
     - from: sooperlooper:loop0_out_4
       to: rigforge.direct-mix.input:playback_AUX7
       status: observed
+    - from: Midi-Bridge:UMC404HD 192k MIDI 1 (capture)
+      to: sooperlooper:midi_in
+      status: observed
     - from: rigforge.direct-mix.output:capture_FL
       to: alsa_output.hw_U192k_0:playback_AUX0
       status: observed
@@ -340,4 +345,5 @@ connections:
     status: explicitly-forbidden
   - from: UMC404HD-MIDI-1
     to: SooperLooper-MIDI
-    status: observed-device-unverified-routing
+    transport: PipeWire JACK MIDI
+    status: observed

+ 18 - 6
scripts/observe_pipewire.py

@@ -18,7 +18,9 @@ MANAGED_ENDPOINT_PATTERN = re.compile(
     r"rigforge\.direct-mix\.output:capture_FL|"
     r"effect_0:(?:input|output)|"
     r"effect_1:(?:in|out)|"
-    r"sooperlooper:loop0_(?:in|out)_[1-4]"
+    r"sooperlooper:loop0_(?:in|out)_[1-4]|"
+    r"sooperlooper:midi_in|"
+    r"Midi-Bridge:UMC404HD 192k MIDI 1 \(capture\)"
     r")$"
 )
 
@@ -46,7 +48,9 @@ def validate_managed_links(state):
         managed_ports = []
     for index, port in enumerate(managed_ports):
         if not isinstance(port, str) or not MANAGED_ENDPOINT_PATTERN.fullmatch(port):
-            errors.append(f"routing.managed_ports[{index}] is not an approved observed Rigforge or UMC port")
+            errors.append(
+                f"routing.managed_ports[{index}] is not an approved observed Rigforge, UMC, or MIDI port"
+            )
     if len(managed_ports) != len(set(port for port in managed_ports if isinstance(port, str))):
         errors.append("routing.managed_ports must not contain duplicate ports")
 
@@ -61,9 +65,13 @@ def validate_managed_links(state):
         source = link.get("from")
         destination = link.get("to")
         if not isinstance(source, str) or not MANAGED_ENDPOINT_PATTERN.fullmatch(source):
-            errors.append(f"routing.managed_links[{index}].from is not an approved observed Rigforge or UMC port")
+            errors.append(
+                f"routing.managed_links[{index}].from is not an approved observed Rigforge, UMC, or MIDI port"
+            )
         if not isinstance(destination, str) or not MANAGED_ENDPOINT_PATTERN.fullmatch(destination):
-            errors.append(f"routing.managed_links[{index}].to is not an approved observed Rigforge or UMC port")
+            errors.append(
+                f"routing.managed_links[{index}].to is not an approved observed Rigforge, UMC, or MIDI port"
+            )
         if (
             isinstance(source, str)
             and isinstance(destination, str)
@@ -88,11 +96,11 @@ def validate_managed_links(state):
         destination = link.get("to")
         if not isinstance(source, str) or not MANAGED_ENDPOINT_PATTERN.fullmatch(source):
             errors.append(
-                f"routing.managed_unlinks[{index}].from is not an approved observed Rigforge or UMC port"
+                f"routing.managed_unlinks[{index}].from is not an approved observed Rigforge, UMC, or MIDI port"
             )
         if not isinstance(destination, str) or not MANAGED_ENDPOINT_PATTERN.fullmatch(destination):
             errors.append(
-                f"routing.managed_unlinks[{index}].to is not an approved observed Rigforge or UMC port"
+                f"routing.managed_unlinks[{index}].to is not an approved observed Rigforge, UMC, or MIDI port"
             )
         if (
             isinstance(source, str)
@@ -222,6 +230,10 @@ def reconcile_once(state, runner=subprocess.run):
                         "mod-host must be running and load the NAM/IR plugins to expose "
                         "effect_0/effect_1 ports"
                     )
+                elif any(item["port"] == "sooperlooper:midi_in" for item in unavailable):
+                    action["hint"] = (
+                        "SooperLooper must be running under pw-jack and expose its JACK MIDI input"
+                    )
                 actions.append(action)
                 continue
             try:

+ 75 - 1
tests/test_pipewire_observer.py

@@ -41,6 +41,8 @@ LOOPER_OUTPUT_1 = "sooperlooper:loop0_out_1"
 LOOPER_OUTPUT_2 = "sooperlooper:loop0_out_2"
 LOOPER_OUTPUT_3 = "sooperlooper:loop0_out_3"
 LOOPER_OUTPUT_4 = "sooperlooper:loop0_out_4"
+MIDI_BRIDGE_UMC = "Midi-Bridge:UMC404HD 192k MIDI 1 (capture)"
+SOOPERLOOPER_MIDI_IN = "sooperlooper:midi_in"
 MIX_OUTPUT = "rigforge.direct-mix.output:capture_FL"
 PLAYBACK_0 = "alsa_output.hw_U192k_0:playback_AUX0"
 
@@ -129,7 +131,79 @@ class PipeWireObserverTests(unittest.TestCase):
         state["routing"]["managed_links"] = [
             {"from": "direct_mix", "to": PLAYBACK_0, "status": "planned"}
         ]
-        self.assertTrue(any("approved observed Rigforge or UMC port" in error for error in validate_managed_links(state)))
+        self.assertTrue(any("approved observed Rigforge, UMC, or MIDI port" in error for error in validate_managed_links(state)))
+
+    def test_rejects_unapproved_midi_endpoint(self):
+        state = copy.deepcopy(self.state)
+        unexpected = "Midi-Bridge:Unexpected MIDI device (capture)"
+        state["routing"]["managed_ports"] = [unexpected, SOOPERLOOPER_MIDI_IN]
+        state["routing"]["managed_links"] = [
+            {"from": unexpected, "to": SOOPERLOOPER_MIDI_IN, "status": "planned"}
+        ]
+        errors = validate_managed_links(state)
+        self.assertEqual(
+            sum("approved observed Rigforge, UMC, or MIDI port" in error for error in errors),
+            2,
+        )
+
+    def test_desired_graph_declares_the_tested_pipewire_midi_route(self):
+        links = {
+            (link["from"], link["to"])
+            for link in self.desired_state["routing"]["managed_links"]
+        }
+        self.assertIn((MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN), links)
+        self.assertIn(MIDI_BRIDGE_UMC, self.desired_state["routing"]["managed_ports"])
+        self.assertIn(SOOPERLOOPER_MIDI_IN, self.desired_state["routing"]["managed_ports"])
+        self.assertEqual(validate_managed_links(self.desired_state), [])
+
+    def test_reconcile_once_restores_the_pipewire_midi_route(self):
+        state = copy.deepcopy(self.desired_state)
+        state["routing"]["managed_ports"] = [MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN]
+        state["routing"]["managed_links"] = [
+            {"from": MIDI_BRIDGE_UMC, "to": SOOPERLOOPER_MIDI_IN, "status": "observed"}
+        ]
+        state["routing"]["managed_unlinks"] = []
+        links = set()
+        calls = []
+
+        def render_links():
+            return "".join(f"{source}\n  |-> {destination}\n" for source, destination in sorted(links))
+
+        def runner(command, **kwargs):
+            calls.append(command)
+            if command == ["pw-link", "-l"]:
+                return SimpleNamespace(stdout=render_links())
+            if command == ["pw-link", "-o"]:
+                return SimpleNamespace(stdout=f"{MIDI_BRIDGE_UMC}\n")
+            if command == ["pw-link", "-i"]:
+                return SimpleNamespace(stdout=f"{SOOPERLOOPER_MIDI_IN}\n")
+            if command == ["pw-link", MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN]:
+                links.add((MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN))
+                return SimpleNamespace(stdout="")
+            self.fail(f"unexpected command: {command}")
+
+        result = reconcile_once(state, runner)
+
+        self.assertEqual(
+            result["actions"],
+            [{
+                "kind": "link",
+                "from": MIDI_BRIDGE_UMC,
+                "to": SOOPERLOOPER_MIDI_IN,
+                "result": "requested",
+            }],
+        )
+        self.assertEqual(result["differences"], [])
+        self.assertIn(["pw-link", MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN], calls)
+
+    def test_parser_handles_pipewire_midi_link_names_with_spaces(self):
+        links = parse_pw_link_output(
+            f"{MIDI_BRIDGE_UMC}\n"
+            f"  |-> {SOOPERLOOPER_MIDI_IN}\n"
+            f"{SOOPERLOOPER_MIDI_IN}\n"
+            f"  |<- {MIDI_BRIDGE_UMC}\n"
+        )
+        self.assertEqual(links, {(MIDI_BRIDGE_UMC, SOOPERLOOPER_MIDI_IN)})
 
     def test_declared_guitar_effect_chain_and_voice_mix_links_match_observed_graph(self):
         links = {