Selaa lähdekoodia

add second loop

Johan Le Baut 1 viikko sitten
vanhempi
sitoutus
dda3603b06

+ 4 - 4
AGENTS.md

@@ -8,9 +8,9 @@ The current target is Debian GNU/Linux 13 on AArch64 with a Behringer UMC404HD 1
 
 ## Layout and architecture
 
-- `config/desired-state.yaml` is the central YAML description of the intended components, four mono sources, looper channel assignments, mix, the guitar NAM/cabinet chain, four-channel mod-host PipeWire boundaries, planned/forbidden connections, and exact external PipeWire links tracked for observation.
-- `config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf` is a PipeWire filter-chain fragment with eight mono mixer inputs (four direct sources and four looper returns), one mono output, and initial gain `0.2` per input. It defines the processing graph and ports, but does not create links to hardware or implement the looper graph.
-- `scripts/validate_desired_state.py` checks the YAML's four-source/physical-input model, single four-channel looper, source-to-channel assignments, mix declaration, and prohibition on routing looper returns back to looper inputs.
+- `config/desired-state.yaml` is the central YAML description of the intended components, four mono sources, two four-channel SooperLooper loops (sources feed the first loop; the second loop has no inputs and only output 1 routed to the mix), mix, the guitar NAM/cabinet chain, four-channel mod-host PipeWire boundaries, planned/forbidden connections, and exact external PipeWire links tracked for observation.
+- `config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf` is a PipeWire filter-chain fragment with nine mono mixer inputs (four direct sources, four first-loop returns, and one second-loop return) implemented as two cascaded mixer stages, one mono output, and initial external-input gain `0.2`. It defines the processing graph and ports, but does not create links to hardware or implement the looper graph.
+- `scripts/validate_desired_state.py` checks the YAML's four-source/physical-input model, one SooperLooper instance with two four-channel loops, source-to-first-loop channel assignments, the unconnected second-loop inputs and single mix return, mix declaration, and prohibition on routing looper returns back to looper inputs.
 - `scripts/observe_pipewire.py` validates the state and managed endpoint declarations, reads `pw-link -l`, and compares observed links against explicitly managed ports and links. Without `--reconcile-once`, it is read-only; one-shot reconciliation and the separately deployed timer create only declared missing links and remove only declared stale links.
 - `scripts/generate_mod_ui_pedalboard.py` builds the YAML-declared guitar NAM→IR chain and three direct-through source pairs; mod-ui owns plugin instances and internal cables after loading it.
 - `scripts/run_mod_host_ports.py` runs the paired four-channel PipeWire loopbacks which form stable mod-ui-visible input/output boundaries.
@@ -52,7 +52,7 @@ The observer invokes `pw-link -l` itself. Its default mode never creates or remo
 ## State and safety invariants
 
 - Preserve exactly the four named sources (`guitar`, `bass`, `voice`, `synth`) and physical inputs 1–4, each once, unless the validator and its tests are intentionally updated along with the model.
-- Preserve one looper component/instance and one four-channel loop; assign each declared source to one unique channel 1–4.
+- Preserve one looper component/instance and two four-channel loops; assign each declared source to one unique channel 1–4 on the first loop. Keep every second-loop input unconnected and route only its output 1 to direct-mix AUX8.
 - The mix must declare an output and include looper returns. Looper returns must not feed any looper input; the explicit forbidden connection is policy documentation, not an active route.
 - A managed link's endpoints must both be declared in `routing.managed_ports`, and names must match the observer's approved endpoint pattern. Use concrete PipeWire boundary ports rather than logical aliases or mod-ui plugin ports. Never add NAM→IR to Rigforge's managed links.
 - Link status values used by the observer are `planned` and `observed`; both are compared against the current graph. Only declare real target observations as `observed`.

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 8 - 6
README.md


+ 14 - 1
config/desired-state.yaml

@@ -20,7 +20,7 @@ system:
       kind: multichannel-looper
       software: SooperLooper
       instance_count: 1
-      loop_count: 1
+      loop_count: 2
       channels_per_loop: 4
       required_for_initial_audio_test: false
     - id: midi-controller
@@ -240,6 +240,7 @@ routing:
       looper_return_2: 0.2
       looper_return_3: 0.2
       looper_return_4: 0.2
+      looper_return_loop2_channel1: 0.2
     includes:
       - guitar
       - bass
@@ -314,6 +315,14 @@ routing:
     - sooperlooper:loop0_out_2
     - sooperlooper:loop0_out_3
     - sooperlooper:loop0_out_4
+    - sooperlooper:loop1_in_1
+    - sooperlooper:loop1_in_2
+    - sooperlooper:loop1_in_3
+    - sooperlooper:loop1_in_4
+    - sooperlooper:loop1_out_1
+    - sooperlooper:loop1_out_2
+    - sooperlooper:loop1_out_3
+    - sooperlooper:loop1_out_4
     - Midi-Bridge:UMC404HD 192k MIDI 1 (capture)
     - sooperlooper:midi_in
     - rigforge.direct-mix.input:playback_AUX0
@@ -324,6 +333,7 @@ routing:
     - rigforge.direct-mix.input:playback_AUX5
     - rigforge.direct-mix.input:playback_AUX6
     - rigforge.direct-mix.input:playback_AUX7
+    - rigforge.direct-mix.input:playback_AUX8
     - rigforge.direct-mix.output:capture_FL
     - alsa_output.hw_U192k_0:playback_AUX0
   managed_links:
@@ -375,6 +385,9 @@ routing:
     - from: sooperlooper:loop0_out_4
       to: rigforge.direct-mix.input:playback_AUX7
       status: observed
+    - from: sooperlooper:loop1_out_1
+      to: rigforge.direct-mix.input:playback_AUX8
+      status: observed
     - from: Midi-Bridge:UMC404HD 192k MIDI 1 (capture)
       to: sooperlooper:midi_in
       status: observed

+ 15 - 3
config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf

@@ -20,13 +20,25 @@ context.modules = [
                              "Gain 8" = 0.2
                          }
                      }
+                    {
+                        name    = output_mix
+                        type    = builtin
+                        label   = mixer
+                        control = {
+                            "Gain 1" = 1.0
+                            "Gain 2" = 0.2
+                        }
+                    }
                  ]
-                inputs  = [ "mix:In 1" "mix:In 2" "mix:In 3" "mix:In 4" "mix:In 5" "mix:In 6" "mix:In 7" "mix:In 8" ]
-                outputs = [ "mix:Out" ]
+                inputs  = [ "mix:In 1" "mix:In 2" "mix:In 3" "mix:In 4" "mix:In 5" "mix:In 6" "mix:In 7" "mix:In 8" "output_mix:In 2" ]
+                outputs = [ "output_mix:Out" ]
+                links = [
+                    { output = "mix:Out" input = "output_mix:In 1" }
+                ]
             }
             capture.props = {
                 node.name         = "rigforge.direct-mix.input"
-                audio.position    = [ AUX0 AUX1 AUX2 AUX3 AUX4 AUX5 AUX6 AUX7 ]
+                audio.position    = [ AUX0 AUX1 AUX2 AUX3 AUX4 AUX5 AUX6 AUX7 AUX8 ]
                 stream.dont-remix = true
                 media.class       = "Audio/Sink"
             }

+ 2 - 2
scripts/observe_pipewire.py

@@ -14,11 +14,11 @@ MANAGED_ENDPOINT_PATTERN = re.compile(
     r"^(?:"
     r"alsa_input\.hw_U192k_0:capture_AUX[0-3]|"
     r"alsa_output\.hw_U192k_0:playback_AUX[0-3]|"
-    r"rigforge\.direct-mix\.input:playback_AUX[0-7]|"
+    r"rigforge\.direct-mix\.input:playback_AUX[0-8]|"
     r"rigforge\.direct-mix\.output:capture_FL|"
     r"rigforge\.mod-host-input:playback_AUX[0-3]|"
     r"rigforge\.mod-host-output:capture_AUX[0-3]|"
-    r"sooperlooper:loop0_(?:in|out)_[1-4]|"
+    r"sooperlooper:loop[01]_(?:in|out)_[1-4]|"
     r"sooperlooper:midi_in|"
     r"Midi-Bridge:UMC404HD 192k MIDI 1 \(capture\)"
     r")$"

+ 47 - 3
scripts/validate_desired_state.py

@@ -244,6 +244,49 @@ def validate_mod_host_channel_routes(state, source_by_id):
     return errors
 
 
+def validate_additional_looper_routes(routing):
+    errors = []
+    links = routing.get("managed_links")
+    if not isinstance(links, list):
+        return ["routing.managed_links must be a list"]
+
+    second_loop_inputs = {
+        f"sooperlooper:loop1_in_{channel}" for channel in range(1, 5)
+    }
+    input_routes = [
+        link
+        for link in links
+        if (
+            isinstance(link, dict)
+            and isinstance(link.get("to"), str)
+            and link["to"] in second_loop_inputs
+        )
+    ]
+    if input_routes:
+        errors.append("SooperLooper loop1 inputs must remain unconnected")
+
+    second_loop_output_links = [
+        link
+        for link in links
+        if isinstance(link, dict)
+        and isinstance(link.get("from"), str)
+        and link["from"].startswith("sooperlooper:loop1_out_")
+    ]
+    expected_edge = (
+        "sooperlooper:loop1_out_1",
+        "rigforge.direct-mix.input:playback_AUX8",
+    )
+    declared_edges = [
+        (link.get("from"), link.get("to"))
+        for link in second_loop_output_links
+    ]
+    if declared_edges != [expected_edge]:
+        errors.append(
+            "SooperLooper loop1 must route only output 1 to direct-mix AUX8"
+        )
+    return errors
+
+
 def validate_state(state):
     errors = []
     if not isinstance(state, dict):
@@ -295,7 +338,7 @@ def validate_state(state):
     if physical_inputs != {1, 2, 3, 4}:
         errors.append("physical inputs must cover 1 through 4 exactly once")
 
-    # The required looper is one instance containing one four-channel loop.
+    # One SooperLooper instance hosts two four-channel loops.
     system = state.get("system")
     components = system.get("components") if isinstance(system, dict) else None
     if not isinstance(components, list):
@@ -306,8 +349,8 @@ def validate_state(state):
         errors.append(f"exactly one looper component is required, got {len(loopers)}")
     elif loopers[0].get("instance_count") != 1:
         errors.append("looper.instance_count must be 1")
-    elif loopers[0].get("loop_count") != 1:
-        errors.append("looper.loop_count must be 1")
+    elif loopers[0].get("loop_count") != 2:
+        errors.append("looper.loop_count must be 2")
     elif loopers[0].get("channels_per_loop") != 4:
         errors.append("looper.channels_per_loop must be 4")
 
@@ -369,6 +412,7 @@ def validate_state(state):
 
     errors.extend(validate_mod_host_chain(routing, source_by_id))
     errors.extend(validate_mod_host_channel_routes(state, source_by_id))
+    errors.extend(validate_additional_looper_routes(routing))
 
     parameters = state.get("parameters")
     if not isinstance(parameters, dict):

+ 1 - 1
tests/test_deploy.py

@@ -577,7 +577,7 @@ class DeploymentTests(unittest.TestCase):
         binary = (ROOT / config["binary_source"]).resolve()
         binding_file = (ROOT / config["binding_file"]).resolve()
         self.assertIn(
-            f'ExecStart="/usr/bin/pw-jack" "{binary}" -l 1 -c 4 -t 30 -m "{binding_file}"',
+            f'ExecStart="/usr/bin/pw-jack" "{binary}" -l 2 -c 4 -t 30 -m "{binding_file}"',
             installed,
         )
         self.assertIn(

+ 52 - 1
tests/test_desired_state.py

@@ -32,17 +32,68 @@ class DesiredStateValidationTests(unittest.TestCase):
         errors = validate_state(state)
         self.assertTrue(any("exactly four sources" in error for error in errors))
 
-    def test_requires_one_four_channel_loop(self):
+    def test_requires_one_sooperlooper_instance_with_two_four_channel_loops(self):
         state = copy.deepcopy(self.state)
         state["system"]["components"][1]["channels_per_loop"] = 2
         self.assertIn("looper.channels_per_loop must be 4", validate_state(state))
 
+        state = copy.deepcopy(self.state)
+        state["system"]["components"][1]["loop_count"] = 1
+        self.assertIn("looper.loop_count must be 2", validate_state(state))
+
         state = copy.deepcopy(self.state)
         state["routing"]["looper_inputs"][3]["channel"] = 3
         errors = validate_state(state)
         self.assertTrue(any("duplicate looper input channel" in error for error in errors))
         self.assertTrue(any("cover channels 1 through 4" in error for error in errors))
 
+    def test_second_loop_has_one_mix_return_and_no_inputs(self):
+        links = self.state["routing"]["managed_links"]
+        self.assertIn(
+            {
+                "from": "sooperlooper:loop1_out_1",
+                "to": "rigforge.direct-mix.input:playback_AUX8",
+                "status": "observed",
+            },
+            links,
+        )
+        self.assertFalse(
+            any(link["to"].startswith("sooperlooper:loop1_in_") for link in links)
+        )
+        self.assertFalse(
+            any(
+                link["from"].startswith("sooperlooper:loop1_out_")
+                and link["from"] != "sooperlooper:loop1_out_1"
+                for link in links
+            )
+        )
+
+        state = copy.deepcopy(self.state)
+        state["routing"]["managed_links"].append(
+            {
+                "from": "rigforge.mod-host-output:capture_AUX0",
+                "to": "sooperlooper:loop1_in_1",
+                "status": "planned",
+            }
+        )
+        self.assertIn(
+            "SooperLooper loop1 inputs must remain unconnected",
+            validate_state(state),
+        )
+
+        state = copy.deepcopy(self.state)
+        state["routing"]["managed_links"].remove(
+            next(
+                link
+                for link in state["routing"]["managed_links"]
+                if link["from"] == "sooperlooper:loop1_out_1"
+            )
+        )
+        self.assertIn(
+            "SooperLooper loop1 must route only output 1 to direct-mix AUX8",
+            validate_state(state),
+        )
+
     def test_requires_declared_mix_output(self):
         state = copy.deepcopy(self.state)
         state["routing"]["mix"]["output_port"] = ""

+ 13 - 15
tests/test_filter_chain_config.py

@@ -1,4 +1,3 @@
-import re
 import unittest
 from pathlib import Path
 
@@ -8,25 +7,24 @@ CONFIG = ROOT / "config" / "pipewire" / "filter-chain.conf.d" / "rigforge-direct
 
 
 class DirectMixConfigTests(unittest.TestCase):
-    def test_declares_eight_independent_mono_inputs_and_one_output(self):
+    def test_declares_nine_mono_inputs_using_two_supported_mixer_stages(self):
         config = CONFIG.read_text(encoding="utf-8")
-        self.assertEqual(re.findall(r'"Gain [1-8]" = 0\.2', config), [
-            '"Gain 1" = 0.2',
-            '"Gain 2" = 0.2',
-            '"Gain 3" = 0.2',
-            '"Gain 4" = 0.2',
-            '"Gain 5" = 0.2',
-            '"Gain 6" = 0.2',
-            '"Gain 7" = 0.2',
-            '"Gain 8" = 0.2',
-        ])
+        for gain in range(1, 9):
+            self.assertIn(f'"Gain {gain}" = 0.2', config)
+        self.assertIn('"Gain 1" = 1.0', config)
+        self.assertIn('"Gain 2" = 0.2', config)
+        self.assertNotIn('"Gain 9"', config)
         self.assertIn(
             'inputs  = [ "mix:In 1" "mix:In 2" "mix:In 3" "mix:In 4" '
-            '"mix:In 5" "mix:In 6" "mix:In 7" "mix:In 8" ]',
+            '"mix:In 5" "mix:In 6" "mix:In 7" "mix:In 8" "output_mix:In 2" ]',
             config,
         )
-        self.assertIn('outputs = [ "mix:Out" ]', config)
-        self.assertIn('audio.position    = [ AUX0 AUX1 AUX2 AUX3 AUX4 AUX5 AUX6 AUX7 ]', config)
+        self.assertIn('outputs = [ "output_mix:Out" ]', config)
+        self.assertIn(
+            '{ output = "mix:Out" input = "output_mix:In 1" }',
+            config,
+        )
+        self.assertIn('audio.position    = [ AUX0 AUX1 AUX2 AUX3 AUX4 AUX5 AUX6 AUX7 AUX8 ]', config)
         self.assertIn('audio.position    = [ FL ]', config)
 
     def test_uses_project_specific_node_names(self):

+ 26 - 0
tests/test_pipewire_observer.py

@@ -39,6 +39,7 @@ MIX_INPUT_4 = "rigforge.direct-mix.input:playback_AUX4"
 MIX_INPUT_5 = "rigforge.direct-mix.input:playback_AUX5"
 MIX_INPUT_6 = "rigforge.direct-mix.input:playback_AUX6"
 MIX_INPUT_7 = "rigforge.direct-mix.input:playback_AUX7"
+MIX_INPUT_8 = "rigforge.direct-mix.input:playback_AUX8"
 LOOPER_INPUT_1 = "sooperlooper:loop0_in_1"
 LOOPER_INPUT_2 = "sooperlooper:loop0_in_2"
 LOOPER_INPUT_3 = "sooperlooper:loop0_in_3"
@@ -47,6 +48,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"
+LOOPER2_INPUT_1 = "sooperlooper:loop1_in_1"
+LOOPER2_OUTPUT_1 = "sooperlooper:loop1_out_1"
 MIDI_BRIDGE_UMC = "Midi-Bridge:UMC404HD 192k MIDI 1 (capture)"
 SOOPERLOOPER_MIDI_IN = "sooperlooper:midi_in"
 MIX_OUTPUT = "rigforge.direct-mix.output:capture_FL"
@@ -269,9 +272,32 @@ class PipeWireObserverTests(unittest.TestCase):
             }
             <= links
         )
+        self.assertIn((LOOPER2_OUTPUT_1, MIX_INPUT_8), links)
+        self.assertFalse(
+            any(destination.startswith("sooperlooper:loop1_in_") for _, destination in links)
+        )
+        self.assertFalse(
+            any(
+                source.startswith("sooperlooper:loop1_out_")
+                and source != LOOPER2_OUTPUT_1
+                for source, _ in links
+            )
+        )
         self.assertEqual(validate_managed_links(self.desired_state), [])
         self.assertEqual(observe(self.desired_state, links), [])
 
+    def test_observer_flags_unexpected_connections_to_second_loop_inputs(self):
+        reports = observe(self.desired_state, {(CAB_OUTPUT, LOOPER2_INPUT_1)})
+        self.assertIn(
+            {
+                "kind": "unexpected",
+                "from": CAB_OUTPUT,
+                "to": LOOPER2_INPUT_1,
+                "action": "would-review",
+            },
+            reports,
+        )
+
     def test_reports_missing_voice_mix_link_without_expectation_of_dry_guitar(self):
         links = {
             (CAPTURE_0, AMP_INPUT),

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä