Files
ShoeGaze/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSApp.swift
T
josh a8bd0242a3 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>
2026-11-25 10:22:51 -08:00

55 lines
2.1 KiB
Swift

// ShoeGazeBuilderiOSApp.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import SwiftUI
import LyrebirdShoeGazeUI
/// iOS entry point for the ShoeGaze Builder.
///
/// Holds the `ShoeGazeBuilderiOSAppModel` as `@State` so it is created once and owned for the
/// lifetime of the app. The audio engine is **not** started automatically — the user presses
/// Start in ``ShoeGazeBuilderView``. The engine is stopped when the view disappears.
///
/// ``ShoeGazeBuilderView`` draws its own header/title and manages its own scroll regions (palette
/// + board canvas), so it is hosted directly — no `NavigationStack`, title, or outer `ScrollView`.
/// A fill frame keeps it pinned to the full window so portrait isn't vertically centered.
@main
struct ShoeGazeBuilderiOSApp: App {
@State private var model: ShoeGazeBuilderiOSAppModel = ShoeGazeBuilderiOSAppModel()
@State private var showSplash: Bool = true
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ZStack {
ShoeGazeBuilderView(
shoeGaze: model.shoeGaze,
library: model.library,
hardwareSampleRate: { model.hardwareSampleRate },
onEnableLiveInput: { model.enableLiveInput() },
midi: model.midi,
undo: model.undo
)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.task { await model.startLibrary() }
.onDisappear { model.stop() }
.onOpenURL { url in model.importDocument(at: url) }
if showSplash {
SplashView(isActive: $showSplash)
.transition(.opacity)
.zIndex(1)
}
}
}
.onChange(of: scenePhase) { _, phase in
// Persist the rig whenever the app leaves the foreground.
if phase != .active { model.save() }
}
}
}