// ScopeAttachTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT #if os(macOS) || os(Linux) import Testing import LyrebirdSynth @testable import LyrebirdLiveCompile @MainActor @Suite("LiveSession scope attach") struct ScopeAttachTests { private func makeEngine(outChannels: Int = 2) -> SynthesisEngine { SynthesisEngine( blockSize: 64, controlBlockSize: 16, sampleRate: 48_000, numOutputChannels: outChannels, numInputChannels: 0, numAudioBuses: 16, numControlBuses: 16, eventQueueCapacity: lyrebirdDefaultEventQueueCapacity, driver: OfflineDriver() ) } @Test func attachesStereoScopeByDefault() { let engine: SynthesisEngine = makeEngine(outChannels: 2) let session: LiveSession = LiveSession(engine: engine) let scope: ScopeCapture? = session.scope #expect(scope != nil) #expect(scope?.buses == [0, 1]) // Installed on the engine so the RT thread writes to it. #expect(engine.scopeTap === scope) } @Test func attachScopeFalseInstallsNothing() { let engine: SynthesisEngine = makeEngine() let session: LiveSession = LiveSession(engine: engine, attachScope: false) #expect(session.scope == nil) #expect(engine.scopeTap == nil) } @Test func monoEngineTapsOneBus() { let engine: SynthesisEngine = makeEngine(outChannels: 1) let session: LiveSession = LiveSession(engine: engine) #expect(session.scope?.buses == [0]) } @Test func reusesExistingTapRatherThanReplacing() { let engine: SynthesisEngine = makeEngine() let existing: ScopeCapture = ScopeCapture(buses: [0], bufferSize: 256) engine.scopeTap = existing let session: LiveSession = LiveSession(engine: engine) // attach on, but a tap exists #expect(session.scope === existing) #expect(engine.scopeTap === existing) } } #endif