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:
@@ -0,0 +1,123 @@
|
||||
// TunerTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("ShoeGaze Tuner")
|
||||
struct TunerTests {
|
||||
|
||||
private func makeShoeGaze(duration: Double) -> (ShoeGaze, SynthesisEngine, URL) {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: duration, numAudioBuses: 64)
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine, inputSource: .testLoop)
|
||||
return (shoeGaze, engine, url)
|
||||
}
|
||||
|
||||
@Test func engageAddsTapAndDisengageRemovesIt() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.2)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
#expect(!shoeGaze.tunerEngaged)
|
||||
#expect(shoeGaze.currentPitchHz == nil)
|
||||
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.tunerEngaged)
|
||||
|
||||
try engine.start()
|
||||
#expect(shoeGaze.currentPitchHz != nil)
|
||||
|
||||
shoeGaze.disengageTuner()
|
||||
#expect(!shoeGaze.tunerEngaged)
|
||||
#expect(shoeGaze.currentPitchHz == nil)
|
||||
}
|
||||
|
||||
@Test func engagingWithMuteOnMutesRigAndDisengageRestores() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
_ = engine
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
shoeGaze.tunerMutesRig = true
|
||||
#expect(!shoeGaze.rigMuted)
|
||||
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.rigMuted, "Engaging with tunerMutesRig=true should mute the rig")
|
||||
|
||||
shoeGaze.disengageTuner()
|
||||
#expect(!shoeGaze.rigMuted, "Disengaging should restore the pre-engage mute state")
|
||||
}
|
||||
|
||||
@Test func disengageRestoresPriorMutedStateNotAlwaysUnmuted() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
_ = engine
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
shoeGaze.tunerMutesRig = true
|
||||
shoeGaze.setRigMuted(true) // already muted before engaging, for an unrelated reason
|
||||
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.rigMuted)
|
||||
|
||||
shoeGaze.disengageTuner()
|
||||
#expect(shoeGaze.rigMuted, "Rig was already muted before engaging — disengage must not unmute it")
|
||||
}
|
||||
|
||||
@Test func tunerMutesRigFalseDoesNotTouchRigMute() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
_ = engine
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
shoeGaze.tunerMutesRig = false
|
||||
shoeGaze.engageTuner()
|
||||
#expect(!shoeGaze.rigMuted)
|
||||
|
||||
shoeGaze.disengageTuner()
|
||||
#expect(!shoeGaze.rigMuted)
|
||||
}
|
||||
|
||||
@Test func toggleTunerEngagedFlipsState() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
_ = engine
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
shoeGaze.toggleTunerEngaged()
|
||||
#expect(shoeGaze.tunerEngaged)
|
||||
shoeGaze.toggleTunerEngaged()
|
||||
#expect(!shoeGaze.tunerEngaged)
|
||||
}
|
||||
|
||||
@Test func engageIsANoOpWhenAlreadyEngaged() throws {
|
||||
let (shoeGaze, engine, url): (ShoeGaze, SynthesisEngine, URL) = makeShoeGaze(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
_ = engine
|
||||
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
shoeGaze.engageTuner()
|
||||
shoeGaze.tunerMutesRig = false // change after first engage — should have no effect until re-engage
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.rigMuted, "Second engageTuner() call while already engaged must be a no-op")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user