Files
ShoeGaze/Sources/LyrebirdShoeGaze/Presets/PedalBoard+Preset.swift
T
josh 947dfe427a Add looper pedal: beat-quantized transport, undo, reverse, timeline
Extend the looper into a double-width tempo-aware pedal:

- Beat-quantized transport: record start and loop close both snap to the
  next beat via a LyrebirdRoutine waiting on the shared clock; loop length
  is an exact whole-beat span. Falls back to immediate/unquantized when no
  clock is present.
- Loop-length read-outs (frames/seconds/beats), transport state, and a
  sample-clock-derived play-head position for the UI timeline.
- Overdub undo (pre-dub snapshot + restore), reverse playback (live rate
  flip), and feedback-decay overdub (overdub preLevel via a Feedback knob).
- Inject the shared LyrebirdClock + SynthesisEngine into Pedal via
  PedalBoard/ChainRouter so tempo-aware pedals can reach them.
- New double-width LooperTimelineView (state badge, length read-out,
  sweeping play-head) wired into PedalView via Pedal.widthUnits.

Concurrency hardening from RT-safety review: a transportGeneration counter
drops superseded deferred beat/undo callbacks that LyrebirdRoutine.stop()
cannot recall once enqueued; the undo restore is deferred past the RT
overdub gate-close; transport routines use non-blocking stop().

Note: this commit also snapshots pre-existing uncommitted work-in-progress
already in the tree (MIDI control refactor, Tuner, Tempo, preset changes),
which is interleaved with the looper changes through shared files and could
not be split into a separately-building commit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:22:20 -07:00

51 lines
2.0 KiB
Swift

// PedalBoard+Preset.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
extension PedalBoard {
/// Captures the current state of this board's label and full signal-chain topology as a
/// `BoardState`.
///
/// Walks the board's ordered segments, snapshotting each linear pedal and each split
/// region (parallel and stereo) in signal-flow order — including branch pedal chains and
/// the section's routing mode. The engine graph is not modified; this is read-only.
///
/// - Returns: A `BoardState` reflecting the board's current topology and parameters.
public func captureState() -> BoardState {
let segmentStates: [BoardSegmentState] = orderedSegments.map { segment in
switch segment {
case .pedal(let pedal):
return BoardSegmentState.pedal(pedal.captureState())
case .parallel(let section):
return BoardSegmentState.parallel(ParallelSectionState(
branchA: section.branchA.pedals.map { $0.captureState() },
branchB: section.branchB.pedals.map { $0.captureState() },
mode: section.splitter.mode
))
case .stereoSplit(let section):
return BoardSegmentState.stereoSplit(StereoSplitState(
left: section.left.pedals.map { $0.captureState() },
right: section.right.pedals.map { $0.captureState() },
route: section.route
))
case .stereoUnzip(let section):
return BoardSegmentState.stereoUnzip(StereoUnzipState(
left: section.left.pedals.map { $0.captureState() },
right: section.right.pedals.map { $0.captureState() },
route: section.route
))
case .mergeToMono:
return BoardSegmentState.mergeToMono
}
}
return BoardState(id: id, label: label, segments: segmentStates)
}
}