feat(undo): parameter undo for knobs, sliders, switches, selectors
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>
This commit is contained in:
@@ -246,6 +246,9 @@ struct TempoSyncKnobView: View {
|
||||
let knob: PedalKnob
|
||||
let param: TempoSyncableParam
|
||||
|
||||
/// Undo coordinator injected by the host; `nil` outside the builder.
|
||||
@Environment(UndoCoordinator.self) private var undo: UndoCoordinator?
|
||||
|
||||
/// Presentation flag for the division-picker popover.
|
||||
@State private var showDivisionPicker: Bool = false
|
||||
|
||||
@@ -270,6 +273,18 @@ struct TempoSyncKnobView: View {
|
||||
|
||||
VStack(spacing: TempoSyncKnobView.cellSpacing) {
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.onEditingEnded { previous, newValue in
|
||||
// Only reachable when free (synced knobs are disabled), so a recorded edit is a
|
||||
// genuine manual turn of this time/rate knob.
|
||||
undo?.recordParameterEdit(
|
||||
label: knob.label,
|
||||
pedalID: pedal.id,
|
||||
group: .knob,
|
||||
controlLabel: knob.label,
|
||||
oldValue: previous,
|
||||
newValue: newValue
|
||||
)
|
||||
}
|
||||
.foregroundStyle(Color.white)
|
||||
.disabled(isSynced)
|
||||
.opacity(isSynced ? TempoSyncKnobView.syncedDialOpacity : 1.0)
|
||||
@@ -513,6 +528,9 @@ public struct PedalView: View {
|
||||
/// Mirrors ``ShoeGaze/tempoEnabled`` so tempo-sync knob affordances hide when tempo is off.
|
||||
@Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool
|
||||
|
||||
/// Undo coordinator injected by the host; `nil` outside the builder (edits aren't recorded).
|
||||
@Environment(UndoCoordinator.self) private var undo: UndoCoordinator?
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a stompbox pedal view for the given pedal.
|
||||
@@ -597,6 +615,18 @@ public struct PedalView: View {
|
||||
PedalInfoView(pedal: pedal)
|
||||
.presentationDetents([.medium, .large])
|
||||
}
|
||||
// Let the self-contained control views (switch / selector / slider) record one undo
|
||||
// checkpoint per edit. Captures this pedal's id + the coordinator; a no-op when `undo` is nil.
|
||||
.environment(\.pedalParameterEditRecorder) { @MainActor [pedal, undo] (group: PedalControlGroup, label: String, oldValue: Double, newValue: Double) in
|
||||
undo?.recordParameterEdit(
|
||||
label: label,
|
||||
pedalID: pedal.id,
|
||||
group: group,
|
||||
controlLabel: label,
|
||||
oldValue: oldValue,
|
||||
newValue: newValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Content layouts
|
||||
@@ -670,7 +700,7 @@ public struct PedalView: View {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { knobPair in
|
||||
let knob: PedalKnob = knobPair.element
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
recordingKnob(knob)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
@@ -866,7 +896,7 @@ public struct PedalView: View {
|
||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||
HStack(alignment: .top, spacing: PedalView.advancedPopoverSpacing) {
|
||||
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { knobPair in
|
||||
ParameterKnob(knobPair.element.label, node: knobPair.element.node, range: knobPair.element.range)
|
||||
recordingKnob(knobPair.element, group: .advancedKnob)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
@@ -924,11 +954,28 @@ public struct PedalView: View {
|
||||
if tempoEnabled, let param: TempoSyncableParam = syncableParam(for: knob) {
|
||||
TempoSyncKnobView(pedal: pedal, knob: knob, param: param)
|
||||
} else {
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
recordingKnob(knob)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
|
||||
/// A ``ParameterKnob`` that records one undo checkpoint per drag (via the coordinator) when the
|
||||
/// user finishes turning it. The control is addressed by the pedal's id, its group, and its
|
||||
/// label so undo re-resolves the live node even after an intervening rebuild.
|
||||
private func recordingKnob(_ knob: PedalKnob, group: PedalControlGroup = .knob) -> ParameterKnob {
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.onEditingEnded { previous, newValue in
|
||||
undo?.recordParameterEdit(
|
||||
label: knob.label,
|
||||
pedalID: pedal.id,
|
||||
group: group,
|
||||
controlLabel: knob.label,
|
||||
oldValue: previous,
|
||||
newValue: newValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The tempo-syncable descriptor whose parameter node backs `knob`, or `nil` if the knob is
|
||||
/// not syncable. Matched by `UIParamNode` identity so it is robust to label changes.
|
||||
private func syncableParam(for knob: PedalKnob) -> TempoSyncableParam? {
|
||||
@@ -1141,7 +1188,7 @@ public struct PedalView: View {
|
||||
@ViewBuilder
|
||||
private var levelControl: some View {
|
||||
if let level: PedalKnob = pedal.knobs.last {
|
||||
ParameterKnob(level.label, node: level.node, range: level.range)
|
||||
recordingKnob(level)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
@@ -1152,7 +1199,7 @@ public struct PedalView: View {
|
||||
@ViewBuilder
|
||||
private var mixControl: some View {
|
||||
if pedal.showsMixControl, let mix: PedalKnob = pedal.knobs.dropLast().last {
|
||||
ParameterKnob(mix.label, node: mix.node, range: mix.range)
|
||||
recordingKnob(mix)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user