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:
@@ -60,6 +60,11 @@ public final class ShoeGaze {
|
||||
/// The engine that owns all nodes.
|
||||
public let engine: SynthesisEngine
|
||||
|
||||
/// Shared tempo clock for the tempo indicator / tap-tempo and any future
|
||||
/// tempo-synced features. Default `120` BPM. `reconfigureEngine(_:)` rebuilds boards
|
||||
/// against the same `engine` instance, so this clock stays valid across reconfigures.
|
||||
public let clock: LyrebirdClock
|
||||
|
||||
/// All boards managed by this instance.
|
||||
public private(set) var boards: [PedalBoard] = []
|
||||
|
||||
@@ -96,6 +101,34 @@ public final class ShoeGaze {
|
||||
/// (same module, different file) can mutate it.
|
||||
internal var recordTaps: [RecordTap] = []
|
||||
|
||||
// MARK: - Tuner state
|
||||
|
||||
/// `true` while the tuner is engaged (between `engageTuner()` and `disengageTuner()`).
|
||||
public internal(set) var tunerEngaged: Bool = false
|
||||
|
||||
/// Whether ``ShoeGaze/engageTuner()`` also mutes the rig output for the duration.
|
||||
/// Defaults to `true`. Read and applied only at engage time — toggling this while
|
||||
/// already engaged takes effect on the next engage/disengage cycle.
|
||||
public var tunerMutesRig: Bool = true
|
||||
|
||||
/// The active `TunerTap`, or `nil` while disengaged. `internal` so
|
||||
/// `ShoeGaze+Tuner.swift` (same module, different file) can mutate it.
|
||||
internal var tunerTap: TunerTap?
|
||||
|
||||
/// The scratch control bus allocated for `tunerTap`'s unread passthrough output,
|
||||
/// released on disengage.
|
||||
internal var tunerScratchControlBus: ControlBus?
|
||||
|
||||
/// `rigMuted`'s value at the moment `engageTuner()` muted the rig, so
|
||||
/// `disengageTuner()` can restore it rather than always unmuting.
|
||||
internal var tunerRestoreMuteOnDisengage: Bool = false
|
||||
|
||||
// MARK: - Tempo state
|
||||
|
||||
/// Timestamps of recent `tapTempo()` calls, oldest first. `internal` so
|
||||
/// `ShoeGaze+Tempo.swift` (same module, different file) can mutate it.
|
||||
internal var tapTimestamps: [Date] = []
|
||||
|
||||
// MARK: - Scope state
|
||||
|
||||
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
||||
@@ -139,6 +172,7 @@ public final class ShoeGaze {
|
||||
) {
|
||||
self.engine = engine
|
||||
self.inputSource = inputSource
|
||||
clock = LyrebirdClock(engine: engine, bpm: ShoeGaze.defaultTempoBpm)
|
||||
installScopeTap()
|
||||
}
|
||||
|
||||
@@ -162,7 +196,7 @@ public final class ShoeGaze {
|
||||
/// - `EngineAddError` if the engine rejects a node insertion.
|
||||
@discardableResult
|
||||
public func addBoard() throws -> PedalBoard {
|
||||
let board: PedalBoard = try PedalBoard(engine: engine)
|
||||
let board: PedalBoard = try PedalBoard(engine: engine, clock: clock)
|
||||
board.label = "Board \(boards.count + 1)"
|
||||
|
||||
// Route the input source to the board head bus.
|
||||
@@ -463,6 +497,10 @@ public final class ShoeGaze {
|
||||
/// Removes a single board and its associated input source and output master from
|
||||
/// the engine, then releases the board's buses. The other boards are unaffected.
|
||||
///
|
||||
/// > Note: MIDI bindings address boards/pedals by UUID, so a removed board's bindings simply
|
||||
/// > stop resolving (inert, and invisible in the mapping UI since there is no board/pedal to
|
||||
/// > list) — no binding maintenance is needed here.
|
||||
///
|
||||
/// - Important: Same async-removal caveat as ``teardown()`` — call with the engine
|
||||
/// stopped, or accept up to one block of glitch on a still-running engine.
|
||||
///
|
||||
@@ -548,7 +586,7 @@ public final class ShoeGaze {
|
||||
/// - `EngineAddError` if the engine rejects any node insertion.
|
||||
@discardableResult
|
||||
public func makeChainRouter() throws -> ChainRouter {
|
||||
let router: ChainRouter = try ChainRouter(engine: engine, inputSource: inputSource)
|
||||
let router: ChainRouter = try ChainRouter(engine: engine, inputSource: inputSource, clock: clock)
|
||||
routers.append(router)
|
||||
return router
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user