feat(preboard): shared pre-board chain feeding every board

Add a pre-board stage: one linear pedal chain that processes the input once,
before the board split, and feeds every board — for front-of-chain gates /
drive / EQ, and multi-board "voice spray" rigs (one source → N panned boards →
Blend).

Routing: a stable mono feed bus every board taps. `FeedPassThrough` copies the
input source — or, when a pre-chain exists, that chain's mono output — onto the
feed bus (`ensureFeed`/`buildFeed`/`tearDownFeed`). The pre-chain is modeled as
an unfinalized `PedalBoard` fed from the source; a stereo tail folds to mono
(board heads are mono). Empty pre-chain = passthrough, byte-for-byte
behavior-preserving. addBoard taps the feed bus; teardown releases it
remove-before-release.

State: additive `ShoeGazeState.preChain` (`decodeIfPresent` → nil for old rigs,
no format bump; `hasSameRigContent` includes it). `captureState` reads the LIVE
pre-pedals so knob tweaks are saved; `rebuildAllBoards` sets the pre-chain
before building boards.

Edit API: appendPrePedal / insertPrePedal / removePrePedal / movePrePedal —
each folds in live knob values, then a full ordering-safe rig rebuild
(`setPreBoardChain`, mirrors setInputSource; rolls back on failure). Undo: a
pre-chain topology change (compared by id sequence, so knob-only edits stay on
the surgical path) rebuilds from the snapshot, stopping/starting the engine.
`allPedals()` now includes the pre-chain so pre-pedal knob undo resolves.

UI: an inline pre-board strip above the boards — hidden to a "+ Pre" button when
empty; otherwise the pre-pedals (keyed by stable id) with a per-pedal remove and
a "feeds all boards" divider. Palette adds route to the pre-board via a flag
(reset on any dismissal). Add / remove go through the undo wrapper.

Known scope: a pre-board edit resets transient/looper state (full rebuild, like
input-switch — setup-time); chain-router branches read the input directly and
are not fed by the pre-board. Both documented.

Tests: PreBoardChainTests (feeds boards, closed pre-Volume silences every board,
remove restores direct feed, save/load incl. a knob tweak, prior pre-pedal's
knob survives adding another, old-rig decode) + a pre-board undo test. Full
suite 844 green; both demos build. External review + caveman sweep: one blocking
(live knob sync) fixed + regression-tested, all non-blocking addressed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 19:18:04 -08:00
parent 1f5b70edc7
commit 9dfadb129d
9 changed files with 592 additions and 28 deletions
@@ -184,6 +184,8 @@ public struct ShoeGazeBuilderView: View {
/// bottom sheets so the board canvas gets the full screen.
@State private var showRigsSheet: Bool = false
@State private var showPaletteSheet: Bool = false
/// When `true`, the next palette pick is added to the pre-board chain rather than a board.
@State private var addToPreBoard: Bool = false
@State private var showSettingsSheet: Bool = false
/// Type filter for the compact Add-Pedal sheet, hoisted so it sits in the sheet's fixed header.
@@ -585,7 +587,9 @@ public struct ShoeGazeBuilderView: View {
/// Hosts the compact Add-pedal palette sheet on its own node.
private var paletteSheetAnchor: some View {
Color.clear
.sheet(isPresented: $showPaletteSheet) {
// Reset the pre-board routing flag on any dismissal (incl. swipe-to-dismiss), so a later
// board-level "+" never misroutes its pick into the pre-board chain.
.sheet(isPresented: $showPaletteSheet, onDismiss: { addToPreBoard = false }) {
paletteSheet
}
}
@@ -720,6 +724,7 @@ public struct ShoeGazeBuilderView: View {
}
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
ControlMappingLegend()
preBoardStrip
boardArea
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
@@ -938,7 +943,7 @@ public struct ShoeGazeBuilderView: View {
.foregroundStyle(Color.white)
Spacer()
pedalFilterMenu
Button("Done") { showPaletteSheet = false }
Button("Done") { addToPreBoard = false; showPaletteSheet = false }
.fontWeight(.semibold)
}
.padding()
@@ -950,8 +955,17 @@ public struct ShoeGazeBuilderView: View {
axis: .vertical,
filter: $pedalFilter,
showsFilterMenu: false,
onAdd: { type in addPedal(type: type); showPaletteSheet = false },
onRouting: { action in performRouting(action); showPaletteSheet = false }
onAdd: { type in
if addToPreBoard { addPrePedal(type: type) } else { addPedal(type: type) }
addToPreBoard = false
showPaletteSheet = false
},
onRouting: { action in
// Routing regions belong to a board, never the linear pre-board chain.
addToPreBoard = false
performRouting(action)
showPaletteSheet = false
}
)
.padding()
}
@@ -1382,6 +1396,100 @@ public struct ShoeGazeBuilderView: View {
}
}
// MARK: - Pre-board strip
/// The shared pre-board processing chain, shown above the boards. Hidden to a thin "+ Pre" button
/// when empty; otherwise a horizontal row of pre-pedals over a divider marking that it feeds all
/// boards. Pre-pedals carry their own undo (knob edits) via the injected coordinator.
@ViewBuilder
private var preBoardStrip: some View {
let prePedals: [Pedal] = shoeGaze.preBoardPedals
if prePedals.isEmpty {
HStack {
Button {
addToPreBoard = true
showPaletteSheet = true
} label: {
Label("Pre-board", systemImage: "plus").font(.caption)
}
.buttonStyle(.bordered)
.tint(.gray)
.help("Add a pre-board pedal — processes the input once, feeding every board")
Spacer()
}
.padding(.horizontal, ShoeGazeBuilderView.outerPadding)
} else {
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.rowSpacing) {
HStack {
Text("Pre-board").font(.caption).bold().foregroundStyle(Color.white)
Spacer()
Button {
addToPreBoard = true
showPaletteSheet = true
} label: {
Image(systemName: "plus")
}
.buttonStyle(.bordered)
.tint(.gray)
.help("Add a pre-board pedal")
}
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: ShoeGazeBuilderView.rowSpacing) {
// Key by the pedal's stable id — a pre-board edit rebuilds the chain into new
// instances, so an offset key would bind a card to a torn-down pedal.
ForEach(Array(prePedals.enumerated()), id: \.element.id) { pair in
PedalView(pedal: pair.element)
.overlay(alignment: .topTrailing) {
Button(role: .destructive) {
removePreBoardPedal(at: pair.offset)
} label: {
Image(systemName: "xmark.circle.fill")
.font(.title3)
.foregroundStyle(Color.white, Color.black.opacity(0.55))
}
.buttonStyle(.plain)
.padding(4)
.help("Remove this pre-board pedal")
}
}
}
.padding(.horizontal, ShoeGazeBuilderView.outerPadding)
}
HStack(spacing: 6) {
Rectangle().fill(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity)).frame(height: 1)
Text("feeds all boards")
.font(.caption2)
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
.fixedSize()
Rectangle().fill(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity)).frame(height: 1)
}
.padding(.horizontal, ShoeGazeBuilderView.outerPadding)
}
.environment(undo)
.environment(\.shoeGazeTempoEnabled, shoeGaze.tempoEnabled)
}
}
private func addPrePedal(type: String) {
do {
try editing("Add \(type) (pre-board)") { try shoeGaze.appendPrePedal(PedalType(type)) }
autosave()
} catch {
print("[ShoeGazeBuilderView] appendPrePedal failed: \(error)")
reportError("Couldn’t add \(type)", error)
}
}
private func removePreBoardPedal(at index: Int) {
do {
try editing("Remove pre-board pedal") { try shoeGaze.removePrePedal(at: index) }
autosave()
} catch {
print("[ShoeGazeBuilderView] removePrePedal failed: \(error)")
reportError("Couldn’t remove pre-board pedal", error)
}
}
// MARK: - Board area
private var boardArea: some View {