feat(undo): multi-level structural undo/redo for rig edits
Add UndoCoordinator: 50-deep undo/redo of structural edits (add/insert/ remove/move pedals in any lane, stereo-split/parallel/merge/unzip routing, add/remove/move boards, Clear Board). Each edit records a named checkpoint via a perform(label:) wrapper threaded through the builder, board-flow, board-bar, and boards-sheet views (injected through the SwiftUI environment, re-injected onto the boards sheet). Restore is surgical, not a whole-rig reload: it reconciles board-by-board (remove added / re-add removed / rebuild changed / reorder) using the same per-board rebuild path as an ordinary edit, so undo never tears the rig down — recording, looper buffers, other boards' reverb/delay tails, and bypass/solo state all survive. It also merges live parameter values by pedal id, so undoing a topology edit never reverts a knob turned afterwards; a pedal the edit removed returns with its snapshot values. No-op edits record nothing (compared via hasSameRigContent). History clears on rig load / new / switch. UI: macOS Edit menu (Undo ⌘Z / Redo ⇧⌘Z with dynamic "Undo <action>" titles, deferring to a text field's own editor while typing); iOS visible ↶/↷ buttons + ⌘Z/⇧⌘Z. Rig mute moves from ⌘Z to ⌘M. Help text updated. Fix: every pedal edit rebuilt the board via BoardState(label:segments:) without id:, regenerating the board UUID and breaking MIDI board bindings after any edit. Thread id: board.id through all 10 rebuild sites; add editingPreservesBoardIdentity regression test. Tests: 12 UndoCoordinator tests (restore correctness, param preservation, untouched-board identity, multi-board re-add, depth cap, no-op, throwing action). Full suite 830 green; both demo schemes build (macOS + iPad). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,9 @@ public struct ShoeGazeView: View {
|
||||
private let shoeGaze: ShoeGaze
|
||||
private let hardwareSampleRate: () -> Double?
|
||||
|
||||
/// Multi-level undo / redo for board edits made from this view, injected into the board bar.
|
||||
@State private var undo: UndoCoordinator
|
||||
|
||||
/// Bumped on each transport button press to force a re-read of the engine's
|
||||
/// running state. The button labels/enabled-state read `shoeGaze.engine.isRunning`
|
||||
/// directly (the single source of truth) rather than a private mirror that could
|
||||
@@ -102,6 +105,7 @@ public struct ShoeGazeView: View {
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self.hardwareSampleRate = hardwareSampleRate
|
||||
self._undo = State(initialValue: UndoCoordinator(shoeGaze: shoeGaze))
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
@@ -118,6 +122,7 @@ public struct ShoeGazeView: View {
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
)
|
||||
.environment(undo)
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
boardList
|
||||
@@ -249,7 +254,7 @@ public struct ShoeGazeView: View {
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||
let board: PedalBoard = pair.element
|
||||
PedalBoardView(board: board) {
|
||||
shoeGaze.removeBoard(board)
|
||||
undo.perform("Remove Board") { shoeGaze.removeBoard(board) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,10 +298,12 @@ public struct ShoeGazeView: View {
|
||||
private func addBoard() {
|
||||
var createdBoard: PedalBoard?
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
createdBoard = board
|
||||
try board.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
try undo.perform("Add Board") {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
createdBoard = board
|
||||
try board.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
}
|
||||
} catch {
|
||||
if let board: PedalBoard = createdBoard {
|
||||
shoeGaze.removeBoard(board)
|
||||
|
||||
Reference in New Issue
Block a user