947dfe427a
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>
61 lines
2.5 KiB
Swift
61 lines
2.5 KiB
Swift
// TunerTap.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
|
||
/// An internal synthesizer that taps the clean pre-effects input bus and runs a
|
||
/// `TunerPitchCapture` on it, so `ShoeGaze` can poll the current detected pitch from the
|
||
/// main thread while the tuner is engaged.
|
||
///
|
||
/// Mirrors `RecordTap`'s shape: reads one bus via `input(bus:)`, wires an analysis generator,
|
||
/// and writes to a dedicated scratch `ControlBus` purely so the engine evaluates it every
|
||
/// block — nothing downstream reads that bus.
|
||
final class TunerTap: SynthesizerBase {
|
||
|
||
/// Anti-alias lowpass cutoff, in Hz, ahead of the decimating YIN tracker. Must sit below
|
||
/// the decimated Nyquist (`sampleRate / (2 × decimation)`; ≈3 kHz at 48 kHz / 8×) so
|
||
/// decimation doesn't fold high harmonics back into the analysis band. `1200` Hz clears
|
||
/// every guitar/bass fundamental (highest is E4 ≈330 Hz) and their first harmonics — which
|
||
/// help YIN lock — while giving solid anti-alias margin.
|
||
private static let lowpassCutoffHz: Double = 1200.0
|
||
|
||
/// Butterworth Q (maximally flat, no resonant peak) for the anti-alias lowpass.
|
||
private static let lowpassQ: Double = 0.707
|
||
|
||
/// Index of the input bus to analyse.
|
||
private let inputBusIndex: Int
|
||
|
||
/// Scratch control bus the capture generator's passthrough writes to. Unread by anything
|
||
/// else — its only purpose is to give the engine a reason to evaluate the generator.
|
||
private let scratchControlBus: ControlBus
|
||
|
||
/// The pitch-capture generator created during `build()`. `nil` until `build()` has run.
|
||
private(set) var pitchCapture: TunerPitchCapture?
|
||
|
||
/// Creates a tuner tap.
|
||
///
|
||
/// - Parameters:
|
||
/// - inputBusIndex: Audio bus to analyse.
|
||
/// - scratchControlBus: A control bus reserved for this tap's unread passthrough output.
|
||
init(inputBusIndex: Int, scratchControlBus: ControlBus) {
|
||
self.inputBusIndex = inputBusIndex
|
||
self.scratchControlBus = scratchControlBus
|
||
super.init()
|
||
}
|
||
|
||
override func build() {
|
||
let source: In.Audio = input(bus: inputBusIndex)
|
||
let filtered: RBJLowPass.Audio = RBJLowPass.Audio(
|
||
input: source,
|
||
freq: TunerTap.lowpassCutoffHz,
|
||
q: TunerTap.lowpassQ
|
||
)
|
||
let capture: TunerPitchCapture = TunerPitchCapture(input: filtered)
|
||
pitchCapture = capture
|
||
output(bus: scratchControlBus, source: capture)
|
||
}
|
||
}
|