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>
This commit is contained in:
2026-07-03 09:22:20 -07:00
parent 097253b410
commit 947dfe427a
47 changed files with 3263 additions and 176 deletions
@@ -533,9 +533,12 @@ public struct ShoeGazeBuilderView: View {
private var transportRow: some View {
_ = transportTick
return HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
Text("ShoeGaze Builder")
.font(.title2).bold()
.foregroundStyle(Color.white)
VStack(alignment: .leading, spacing: 1) {
Text("ShoeGaze Builder")
.font(.title2).bold()
.foregroundStyle(Color.white)
currentRigLabel
}
if shoeGaze.isRecording {
// Recording indicator (both platforms; recording is driven from the macOS Record
// menu or the iOS controls below).
@@ -549,6 +552,8 @@ public struct ShoeGazeBuilderView: View {
}
}
Spacer()
TempoView(shoeGaze: shoeGaze)
TunerView(shoeGaze: shoeGaze)
if let midi: MIDIController = midi {
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
}
@@ -729,6 +734,11 @@ public struct ShoeGazeBuilderView: View {
let wasRunning: Bool = shoeGaze.engine.isRunning
if wasRunning { shoeGaze.engine.stop() }
// Clearing the rig discards its MIDI bindings — they are addressed positionally and
// belong to the rig being cleared. Reset before rebuilding so stale bindings can't
// re-resolve onto the fresh board's pedals.
shoeGaze.midiMap = nil
// Snapshot before removing — removeBoard mutates shoeGaze.boards.
for board: PedalBoard in Array(shoeGaze.boards) {
shoeGaze.removeBoard(board)
@@ -1096,6 +1106,32 @@ public struct ShoeGazeBuilderView: View {
return library.entries.first(where: { $0.id == id })?.name
}
/// A subtitle under the app title showing which rig is loaded. Resolves the name from the
/// library once it has loaded; shows "Unsaved rig" when the working graph has no source-rig
/// id (a cleared / never-saved session). Reads `shoeGaze.currentRigID` and `library.entries`
/// so it refreshes automatically when a rig is loaded or the library finishes loading.
private var currentRigLabel: some View {
let hasSource: Bool = currentRigID != nil
let name: String
if let resolved: String = currentRigName() {
name = resolved
} else if hasSource {
// Source id exists but the library hasn't resolved it yet (still loading).
name = library.isLoaded ? "Unknown rig" : "Loading…"
} else {
name = "Unsaved rig"
}
return HStack(spacing: 5) {
Image(systemName: hasSource ? "guitars.fill" : "guitars")
.font(.caption2)
Text(name)
.font(.caption)
.lineLimit(1)
}
.foregroundStyle(Color.white.opacity(hasSource ? 0.8 : 0.5))
.help(hasSource ? "Loaded rig: \(name)" : "This rig has not been saved to the library yet")
}
/// A default name for a new rig: `"Rig N"` where N avoids collisions with existing names.
private func defaultNewRigName() -> String {
let base: String = "Rig"