refactor(rigs): address external-review findings

- Recall router state in applyState: the lightweight (no-rebuild) recall path
  now positionally applies router branch pedal params and the splitter/merger
  blend, instead of silently dropping them for routed rigs. Test added.
- Simplify first-run seeding: RigLibraryStore.save persists asynchronously
  (best-effort, logged not thrown), so the previous per-entry rollback could
  never fire for a real disk failure. Replaced with an honest best-effort
  save + working-rig fallback, and a comment stating the semantics.
- Move FactoryRigBuild to its own file (one public type per file).
- Document that a router's output master gain is intentionally not persisted,
  matching BoardState's treatment of board master gain.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 13:32:58 -07:00
parent 7dccf596f4
commit 2c970aa344
6 changed files with 78 additions and 40 deletions
@@ -410,6 +410,19 @@ extension ShoeGaze {
}
}
}
// Routers recall positionally too: their branch pedals' params and the splitter/merger
// blend. Topology (pedal counts/types) is assumed identical for a lightweight recall — a
// mismatch is skipped, exactly as for boards. A `rebuildsOnChange` selector inside a router
// branch is not handled here (routers have no per-branch rebuild path); use `loadRig(from:)`
// for that.
for (router, routerState): (ChainRouter, ChainRouterState) in zip(routers, state.routers ?? []) {
applyLinearParams(routerState.boardA, to: router.boardA.pedals)
applyLinearParams(routerState.boardB, to: router.boardB.pedals)
router.splitter.branchAEnabled = routerState.branchA
router.splitter.branchBEnabled = routerState.branchB
router.merger?.levelA = routerState.mergerLevelA
router.merger?.levelB = routerState.mergerLevelB
}
// A recall restores each pedal's tempo-sync state but not its derived values (no clock is
// consulted in `Pedal.applyState`), so recompute them against the rig's current tempo —
// mirroring the full `loadRig(from:)` path.
@@ -418,6 +431,15 @@ extension ShoeGaze {
}
}
/// Positionally applies pedal parameter snapshots to a live linear pedal chain (e.g. a router
/// branch). A position whose live pedal type doesn't match the snapshot is skipped, matching the
/// silent-skip semantics of the board recall path.
private func applyLinearParams(_ states: [PedalState], to pedals: [Pedal]) {
for (pedal, state): (Pedal, PedalState) in zip(pedals, states) where pedal.displayName == state.type {
pedal.applyState(state)
}
}
/// Positionally applies segment parameter snapshots to live board segments, including
/// branch pedals and split routing modes. Type or topology mismatches at any position are
/// skipped silently (lightweight recall is for topologically identical rigs).