Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/TunerPitchReadingTests.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

53 lines
1.6 KiB
Swift

// TunerPitchReadingTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdShoeGazeUI
@Suite("TunerPitchReading")
struct TunerPitchReadingTests {
@Test func concertAIsA4WithZeroCents() {
let reading: TunerPitchReading = TunerPitchReading(hz: 440.0)
#expect(reading.noteName == "A4")
#expect(abs(reading.cents) < 0.5)
}
@Test func oneOctaveDownIsA3() {
let reading: TunerPitchReading = TunerPitchReading(hz: 220.0)
#expect(reading.noteName == "A3")
#expect(abs(reading.cents) < 0.5)
}
@Test func middleCIsC4() {
let reading: TunerPitchReading = TunerPitchReading(hz: 261.6256)
#expect(reading.noteName == "C4")
#expect(abs(reading.cents) < 1.0)
}
@Test func slightlySharpReportsPositiveCents() {
// ~20 cents sharp of A4.
let sharpHz: Double = 440.0 * pow(2.0, 20.0 / 1200.0)
let reading: TunerPitchReading = TunerPitchReading(hz: sharpHz)
#expect(reading.noteName == "A4")
#expect(reading.cents > 15.0 && reading.cents < 25.0)
}
@Test func slightlyFlatReportsNegativeCents() {
// ~20 cents flat of A4.
let flatHz: Double = 440.0 * pow(2.0, -20.0 / 1200.0)
let reading: TunerPitchReading = TunerPitchReading(hz: flatHz)
#expect(reading.noteName == "A4")
#expect(reading.cents < -15.0 && reading.cents > -25.0)
}
@Test func lowGuitarStringIsE2() {
let reading: TunerPitchReading = TunerPitchReading(hz: 82.41)
#expect(reading.noteName == "E2")
}
}