Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/LooperTransportState.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

31 lines
1.1 KiB
Swift

// LooperTransportState.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// Publicly-observable transport phase of ``LooperPedal``, surfaced for the UI so it can
/// colour the record LED, animate the "waiting for the next beat" armed states, and drive
/// the loop timeline.
///
/// The two `armed…` cases exist only when the pedal has a tempo ``LyrebirdClock`` — a
/// transport action then waits for the next beat boundary before it takes effect. Without a
/// clock the pedal transitions straight between ``empty``, ``recording`` and ``playing``.
public enum LooperTransportState: Sendable, Equatable {
/// No take recorded yet. `Record` begins recording (or arms it, with a clock).
case empty
/// A `Record` has been requested and the pedal is waiting for the next beat to start.
case armedRecord
/// Actively recording the primary take.
case recording
/// A stop has been requested and the pedal is waiting for the next beat to close the loop.
case armedStop
/// Looping playback of the recorded take (overdub / reverse / mute apply here).
case playing
}