1f5b70edc7
Tier 2 of the rig-undo feature, on the same undo stack as the structural (tier 1) edits. Records one undo checkpoint when the user finishes changing a pedal control, so ⌘Z / the ↶ button step back through knob turns and switch flips as well as add/remove/move. - UndoEntry.parameter + PedalControlGroup (knob/advancedKnob/slider/switch/ selector); UndoCoordinator.recordParameterEdit + .parameter handling in undo()/redo(). applyParameter re-resolves the LIVE node by (pedalID, group, controlLabel) via ShoeGaze.pedal(id:), so an undo lands on the right control even after an intervening structural rebuild replaced the pedal's node (pedal ids persist through rebuild). old == new records nothing. - Knobs record via Lyrebird 2.3.0's ParameterKnob.onEditingEnded (one edit per drag): PedalView.recordingKnob (main / advanced / mix / level / looper) and TempoSyncKnobView. - Self-contained views (VerticalParameterSlider, PedalSwitchView, PedalSelectorKnobView) record via a new \.pedalParameterEditRecorder environment closure PedalView installs, capturing pedal.id + the coordinator. Slider/selector snapshot node.value at drag start; switch records old→new on the committing tap. - rebuildsOnChange switches/selectors are deliberately NOT recorded (they alter graph topology and would fight the structural restore's live-value merge) — documented as a known gap, along with tempo-sync division changes. - Bump the Lyrebird pin to 2.3.0 (the released tag with onEditingEnded), drop the dev-time local path override. Tests: 18 UndoCoordinator tests (knob/slider/switch/selector round-trips, post-rebuild re-resolution, + a catalogue test asserting unique control labels per group so the by-label resolution can't mis-target). Full suite 837 green; both demo schemes build against 2.3.0. External review + caveman sweep: no blocking findings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
2.0 KiB
Swift
43 lines
2.0 KiB
Swift
// PedalRebuildEnvironment.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftUI
|
|
import LyrebirdSynth
|
|
import LyrebirdShoeGaze
|
|
|
|
/// Environment action a leaf pedal control can call to ask the host to rebuild the board that
|
|
/// contains the given pedal — needed when a pedal setting that is *not* a live `@UIParam` (e.g.
|
|
/// the Neural Amp's model file, stored in ``Pedal/resourcePath``) changes and only takes effect
|
|
/// after the pedal's graph is rebuilt. Set once near the builder root; defaults to a no-op.
|
|
private struct PedalRebuildActionKey: EnvironmentKey {
|
|
static let defaultValue: @MainActor @Sendable (Pedal) -> Void = { _ in }
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
/// Rebuilds the board containing the passed pedal. No-op unless the host installs it.
|
|
var pedalRebuildAction: @MainActor @Sendable (Pedal) -> Void {
|
|
get { self[PedalRebuildActionKey.self] }
|
|
set { self[PedalRebuildActionKey.self] = newValue }
|
|
}
|
|
}
|
|
|
|
/// Environment action a leaf pedal control calls when the user finishes changing it, so the host
|
|
/// can record one undo checkpoint per edit. Arguments: the control's group, its label, and the
|
|
/// values before and after the edit. ``PedalView`` installs it capturing the pedal's id and the
|
|
/// undo coordinator; it defaults to a no-op, so a control outside the builder records nothing.
|
|
private struct PedalParameterEditRecorderKey: EnvironmentKey {
|
|
static let defaultValue: @MainActor @Sendable (PedalControlGroup, String, Double, Double) -> Void = { _, _, _, _ in }
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
/// Records a finished parameter edit (group, control label, old value, new value). No-op unless
|
|
/// the host installs it.
|
|
var pedalParameterEditRecorder: @MainActor @Sendable (PedalControlGroup, String, Double, Double) -> Void {
|
|
get { self[PedalParameterEditRecorderKey.self] }
|
|
set { self[PedalParameterEditRecorderKey.self] = newValue }
|
|
}
|
|
}
|