Looper reverse fix + header layout compaction + tempo toggle

Looper:
- Reverse now continues from the current play-head instead of jumping to
  duration-minus-position; anchor-based position tracking survives direction
  changes. Sync mode defers the flip to the next beat; Free applies immediately.
- Sync switch relabeled "Sync to Tempo".

Tempo/Tuner:
- Add a Tempo on/off toggle (ShoeGaze.setTempoEnabled) that hides the indicator
  and forces every tempo-dependent pedal switch (PedalSwitch.tempoDependent) off;
  PedalSwitchView disables such switches via the shoeGazeTempoEnabled environment.
- Tuner readout laid out inline; Tempo/Tuner pinned to fixed heights so toggling
  state no longer shifts surrounding layout.

Header:
- Collapsed to two rows: title + Tempo/Tuner (left, stacked) and engine options
  over input controls (right, trailing-aligned). TAP is a standard-height button.
- Removed the redundant Boards button; moved Clear into the board bar.
- Fixed the rig mute glyph size so toggling mute doesn't shift the volume row.

Help: added a Looper section documenting transport, Free/Sync, knobs, tracks,
and MIDI-assignable actions.

Tests: TempoEnableTests + looper reverse/deferral coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-04 12:31:11 -07:00
parent 4e58c9bd9b
commit 5090a9255f
12 changed files with 424 additions and 95 deletions
@@ -163,7 +163,7 @@ struct LooperPedalTests {
@Test func exposesLooperControls() throws {
let pedal: LooperPedal = LooperPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Crossfade", "Playback", "Overdub", "Feedback"])
#expect(pedal.effectSwitches.map { $0.label } == ["Sync"])
#expect(pedal.effectSwitches.map { $0.label } == ["Sync to Tempo"])
#expect(pedal.effectButtons.isEmpty)
#expect(pedal.effectTransportButtons.map { $0.label } == ["Loop", "Stop", "Cue Stop", "Reverse", "Reset"])
}
@@ -420,6 +420,75 @@ struct LooperPedalTests {
} }
}
@Test func reverseDoesNotJumpPlayHeadPosition() throws {
let sampleRate: Double = 44100.0
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
try makeQuantizedFixture(bpm: 120.0, sampleRate: sampleRate)
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
// Record a 1-second master (record start at 0, close at 44100) → masterLength = 44100.
pedal.pressLoop()
pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(0))
let closeSample: SampleTime = SampleTime(sampleRate)
pedal.pressLoop()
pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: closeSample)
#expect(pedal.transportState == .playing)
// A quarter of the way in, moving forward.
let quarter: SampleTime = closeSample + SampleTime(sampleRate * 0.25)
#expect(abs(pedal.playHeadFraction(at: quarter) - 0.25) < 0.001)
// Reversing here must NOT jump the read-out to the mirror point (0.75) — it stays at 0.25.
pedal.applyReverse(at: quarter)
#expect(abs(pedal.playHeadFraction(at: quarter) - 0.25) < 0.001,
"reverse must continue from the current position, not jump to duration − position")
// Advancing time now walks the position backward from 0.25.
let laterBy: SampleTime = SampleTime(sampleRate * 0.10)
#expect(abs(pedal.playHeadFraction(at: quarter + laterBy) - 0.15) < 0.001,
"reversed play head moves backward from the reverse point")
} }
}
@Test func reverseDefersToNextBeatInSyncMode() throws {
let sampleRate: Double = 44100.0
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
try makeQuantizedFixture(bpm: 120.0, sampleRate: sampleRate)
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
pedal.pressLoop()
pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(0))
pedal.pressLoop()
pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate))
#expect(pedal.transportState == .playing)
#expect(pedal.overdubbingTrackIndex == 0)
// Sync mode (default): the press is deferred — direction and overdub are untouched.
pedal.toggleReverse()
#expect(pedal.reverse == 0.0, "sync-mode reverse waits for the next beat")
#expect(pedal.overdubbingTrackIndex == 0, "overdub survives until the deferred reverse fires")
// The beat arrives: direction flips and the overdub ends.
pedal.applyDeferredReverse(generation: pedal.reverseGeneration, at: SampleTime(sampleRate * 2))
#expect(pedal.reverse == 1.0)
#expect(pedal.overdubbingTrackIndex == nil, "engaging reverse ends the overdub")
} }
}
@Test func reverseIsImmediateInFreeMode() throws {
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
pedal.syncToBeat = 0.0
pedal.pressLoop() // record A (immediate)
pedal.pressLoop() // play + overdub A (immediate)
#expect(pedal.transportState == .playing)
// Free mode: reverse applies right away, even with a clock present.
pedal.toggleReverse()
#expect(pedal.reverse == 1.0, "free-mode reverse is immediate")
#expect(pedal.overdubbingTrackIndex == nil, "engaging reverse ends the overdub")
} }
}
@Test func engineStopResetsLooperAndPostsNotice() throws {
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)
@@ -0,0 +1,55 @@
// TempoEnableTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
@testable import LyrebirdShoeGaze
@MainActor
@Suite("Tempo enable")
struct TempoEnableTests {
private func makeRigWithLooper() throws -> (ShoeGaze, SynthesisEngine, URL, LooperPedal) {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1)
let sg: ShoeGaze = ShoeGaze(engine: engine)
let board: PedalBoard = try sg.addBoard()
guard let looper: LooperPedal = PedalRegistry.makePedal(type: "Looper") as? LooperPedal else {
fatalError("Looper pedal must be registered")
}
try board.add(looper)
try sg.finalizeBoard(board)
return (sg, engine, url, looper)
}
@Test func tempoEnabledDefaultsOn() throws {
let (sg, _, url, _): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
defer { try? FileManager.default.removeItem(at: url) }
#expect(sg.tempoEnabled, "tempo indicator is on by default")
}
@Test func looperSyncSwitchIsTempoDependent() throws {
let (_, _, url, looper): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
defer { try? FileManager.default.removeItem(at: url) }
let syncSwitch: PedalSwitch? = looper.effectSwitches.first { $0.tempoDependent }
#expect(syncSwitch != nil, "the looper Sync-to-Tempo switch must be marked tempo-dependent")
}
@Test func disablingTempoForcesSyncSwitchesOff() throws {
let (sg, _, url, looper): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
defer { try? FileManager.default.removeItem(at: url) }
looper.syncToBeat = 1.0 // engage Sync
sg.setTempoEnabled(false)
#expect(!sg.tempoEnabled)
#expect(looper.syncToBeat == 0.0, "disabling tempo forces the looper back to Free")
// Re-enabling leaves it Free — the user re-selects Sync if wanted.
sg.setTempoEnabled(true)
#expect(sg.tempoEnabled)
#expect(looper.syncToBeat == 0.0)
}
}