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:
@@ -14,9 +14,25 @@ import LyrebirdUI
|
||||
@Suite("RigStore")
|
||||
struct RigStoreTests {
|
||||
|
||||
/// Redirects `RigStore` to a unique temp file so the suite never touches — let alone
|
||||
/// overwrites or deletes — the running app's real autosave in Application Support. Returns
|
||||
/// the temp file URL (its parent directory is created).
|
||||
private func isolateAutosave() throws -> URL {
|
||||
let dir: URL = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("RigStoreTests-" + UUID().uuidString, isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
let file: URL = dir.appendingPathComponent("autosave-rig.json")
|
||||
RigStore.autosaveURLOverride = file
|
||||
return file
|
||||
}
|
||||
|
||||
@Test func savesAndRestoresAcrossInstances() throws {
|
||||
let autosave: URL = try isolateAutosave()
|
||||
defer {
|
||||
RigStore.autosaveURLOverride = nil
|
||||
try? FileManager.default.removeItem(at: autosave.deletingLastPathComponent())
|
||||
}
|
||||
RigStore.clear()
|
||||
defer { RigStore.clear() }
|
||||
|
||||
// Build a rig and autosave it.
|
||||
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
||||
@@ -42,7 +58,37 @@ struct RigStoreTests {
|
||||
#expect(b.boards.last?.label == "Clean")
|
||||
}
|
||||
|
||||
@Test func restorePreservesCurrentRigID() throws {
|
||||
let autosave: URL = try isolateAutosave()
|
||||
defer {
|
||||
RigStore.autosaveURLOverride = nil
|
||||
try? FileManager.default.removeItem(at: autosave.deletingLastPathComponent())
|
||||
}
|
||||
RigStore.clear()
|
||||
|
||||
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: urlA) }
|
||||
let a: ShoeGaze = ShoeGaze(engine: engineA)
|
||||
let board: PedalBoard = try a.addBoard()
|
||||
try a.appendPedal(.overdrive, to: board)
|
||||
try a.finalizeBoard(board)
|
||||
let rigID: UUID = UUID()
|
||||
a.currentRigID = rigID
|
||||
#expect(RigStore.save(a))
|
||||
|
||||
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: urlB) }
|
||||
let b: ShoeGaze = ShoeGaze(engine: engineB)
|
||||
#expect(RigStore.restore(into: b))
|
||||
#expect(b.currentRigID == rigID, "restore must carry the source-rig id so the UI highlights it")
|
||||
}
|
||||
|
||||
@Test func restoreReturnsFalseWhenNoAutosave() throws {
|
||||
let autosave: URL = try isolateAutosave()
|
||||
defer {
|
||||
RigStore.autosaveURLOverride = nil
|
||||
try? FileManager.default.removeItem(at: autosave.deletingLastPathComponent())
|
||||
}
|
||||
RigStore.clear()
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
Reference in New Issue
Block a user