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
@@ -84,21 +84,30 @@ func readStereoCAF(url: URL, sampleRate: Double = 44100.0) -> [Float] {
&clientFormat
) == noErr else { return [] }
let readFrames: UInt32 = 4096
var samples: [Float] = [Float](repeating: 0, count: Int(readFrames) * 2)
var framesRead: UInt32 = readFrames
samples.withUnsafeMutableBufferPointer { ptr in
var bufList: AudioBufferList = AudioBufferList(
mNumberBuffers: 1,
mBuffers: AudioBuffer(
mNumberChannels: 2,
mDataByteSize: UInt32(ptr.count * MemoryLayout<Float>.size),
mData: ptr.baseAddress
// Read the whole file in fixed-size chunks — a single `ExtAudioFileRead` call only
// fills one chunk's worth of frames, so anything past `chunkFrames` would otherwise be
// silently dropped for renders longer than one chunk.
let chunkFrames: UInt32 = 4096
var chunk: [Float] = [Float](repeating: 0, count: Int(chunkFrames) * 2)
var allSamples: [Float] = []
while true {
var framesRead: UInt32 = chunkFrames
chunk.withUnsafeMutableBufferPointer { ptr in
var bufList: AudioBufferList = AudioBufferList(
mNumberBuffers: 1,
mBuffers: AudioBuffer(
mNumberChannels: 2,
mDataByteSize: UInt32(ptr.count * MemoryLayout<Float>.size),
mData: ptr.baseAddress
)
)
)
_ = ExtAudioFileRead(fileRef, &framesRead, &bufList)
_ = ExtAudioFileRead(fileRef, &framesRead, &bufList)
}
guard framesRead > 0 else { break }
allSamples.append(contentsOf: chunk.prefix(Int(framesRead) * 2))
if framesRead < chunkFrames { break }
}
return Array(samples.prefix(Int(framesRead) * 2))
return allSamples
}
// MARK: - Signal analysis