// 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) } }