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
+48 -15
View File
@@ -90,9 +90,11 @@ private struct ScrewDot: View {
/// A small circular LED that glows green when the effect is engaged.
///
/// Bypass polarity: `0` = engaged (effect ON), `1` = bypassed.
/// The LED is lit when `bypassValue < 0.5`.
private struct LEDIndicator: View {
/// A small round LED, lit green when `isOn` and dark otherwise. Polarity-agnostic — the
/// caller decides what `isOn` means for its own control (e.g. bypass's `value < 0.5`, or a
/// plain toggle's `value >= 0.5`). `internal` (not `private`) so other views in this module
/// (e.g. `PedalButtonView`) can reuse the same stompbox LED look.
struct LEDIndicator: View {
private static let diameter: CGFloat = 10
private static let glowRadius: CGFloat = 6
@@ -101,13 +103,11 @@ private struct LEDIndicator: View {
private static let dimBrightness: Double = 0.15
private static let rimStrokeOpacity: Double = 0.30
let bypassValue: Double
private var isEngaged: Bool { bypassValue < 0.5 }
let isOn: Bool
var body: some View {
ZStack {
if isEngaged {
if isOn {
Circle()
.fill(Color.green.opacity(LEDIndicator.glowOpacity))
.frame(
@@ -117,7 +117,7 @@ private struct LEDIndicator: View {
.blur(radius: LEDIndicator.glowRadius / 2)
}
Circle()
.fill(isEngaged ? Color.green : Color(white: LEDIndicator.dimBrightness))
.fill(isOn ? Color.green : Color(white: LEDIndicator.dimBrightness))
.frame(width: LEDIndicator.diameter, height: LEDIndicator.diameter)
.overlay(
Circle()
@@ -132,8 +132,10 @@ private struct LEDIndicator: View {
// MARK: - Footswitch
/// A round footswitch-style button that toggles bypass on/off.
private struct FootswitchButton: View {
/// A round footswitch-style button that flips a `UIParamNode` between `0` and `1`.
/// `internal` (not `private`) so other views in this module (e.g. `PedalButtonView`) can
/// reuse the same stompbox footswitch look for non-bypass toggles.
struct FootswitchButton: View {
private static let diameter: CGFloat = 44
private static let strokeWidth: CGFloat = 2.5
@@ -291,9 +293,11 @@ public struct PedalView: View {
// Content stack
VStack(spacing: PedalView.sectionSpacing) {
namePlate
looperTimeline
knobGrid
selectorRow
switchRow
buttonRow
sliderBank(sliders)
Spacer(minLength: 0)
bottomControls
@@ -334,6 +338,15 @@ public struct PedalView: View {
.clipShape(RoundedRectangle(cornerRadius: PedalView.namePlateCornerRadius))
}
/// Loop timeline strip — rendered only for the double-width `LooperPedal`, between the
/// name plate and the knob grid. Other pedals render nothing here.
@ViewBuilder
private var looperTimeline: some View {
if let looper: LooperPedal = pedal as? LooperPedal {
LooperTimelineView(pedal: looper)
}
}
/// Info button tucked just under the top-left corner screw.
private var infoButton: some View {
Button {
@@ -417,6 +430,22 @@ public struct PedalView: View {
}
}
/// Row of stomp-style action buttons drawn from `pedal.effectButtons`, beneath the
/// switch row. Renders nothing when the pedal publishes no buttons.
@ViewBuilder
private var buttonRow: some View {
let buttons: [PedalButton] = pedal.effectButtons
if !buttons.isEmpty {
HStack(spacing: PedalView.knobRowItemSpacing) {
Spacer(minLength: 0)
ForEach(Array(buttons.enumerated()), id: \.offset) { pair in
PedalButtonView(pair.element)
}
Spacer(minLength: 0)
}
}
}
/// Row of vertical faders drawn from `pedal.effectSliders`, beneath the switch row.
/// Renders nothing when the pedal publishes no sliders.
@ViewBuilder
@@ -431,16 +460,19 @@ public struct PedalView: View {
}
}
/// Enclosure width — the base stompbox width, widened to fit a wide vertical-fader bank
/// (e.g. a multi-band graphic EQ) so its faders are never clipped.
/// Enclosure width — the base stompbox width scaled by the pedal's `widthUnits`
/// (a control-dense pedal such as the looper asks for a double-width card), widened
/// further to fit a wide vertical-fader bank (e.g. a multi-band graphic EQ) so its
/// faders are never clipped.
private func enclosureWidth(for sliders: [PedalSlider]) -> CGFloat {
let unitWidth: CGFloat = PedalView.enclosureWidth * CGFloat(max(1, pedal.widthUnits))
let sliderCount: Int = sliders.count
guard sliderCount > 0 else { return PedalView.enclosureWidth }
guard sliderCount > 0 else { return unitWidth }
let bankContentWidth: CGFloat =
CGFloat(sliderCount) * PedalView.sliderBankItemWidth
+ CGFloat(max(0, sliderCount - 1)) * PedalView.sliderBankSpacing
let needed: CGFloat = bankContentWidth + 2 * PedalView.enclosurePadding
return max(PedalView.enclosureWidth, needed)
return max(unitWidth, needed)
}
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
@@ -479,9 +511,10 @@ public struct PedalView: View {
// re-renders whenever the bypass parameter changes on the main thread
// (UIParamNode is @Observable).
let bypassValue: Double = pedal.$bypass.value
let engagedThreshold: Double = 0.5
return VStack(spacing: PedalView.bypassSectionSpacing) {
LEDIndicator(bypassValue: bypassValue)
LEDIndicator(isOn: bypassValue < engagedThreshold)
FootswitchButton(node: pedal.$bypass)
}
}