// TestLoopTap.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth /// Internal synthesizer that copies the shared global test-loop bus to a board head bus. /// /// In `.testLoop` mode every board reads the **same** global ``TestLoopSource`` (so all boards /// stay phase-locked instead of each running an independently-phased arpeggio). A `TestLoopTap` /// per board reads the global test bus at `inputBusIndex` and writes it to the board's head bus /// at `outputBusIndex`, so the first pedal still reads from a board-owned bus. /// /// Added `.after(_:)` the global source so it evaluates once the source has written the test bus /// for the current block. /// /// - Note: Must be removed from the engine before the board's `teardown()` releases the head bus. final class TestLoopTap: SynthesizerBase { // MARK: - Routing /// Index of the shared global test-loop bus to read from. private let inputBusIndex: Int /// Index of the board head bus to write to. private let outputBusIndex: Int // MARK: - Init /// Creates a tap that copies `inputBusIndex` (the global test bus) to `outputBusIndex` /// (a board head bus). /// /// - Parameters: /// - inputBusIndex: Shared global test-loop bus index to read from. /// - outputBusIndex: Board head bus index to write to. init(inputBusIndex: Int, outputBusIndex: Int) { self.inputBusIndex = inputBusIndex self.outputBusIndex = outputBusIndex super.init() } // MARK: - Build override func build() { output(bus: outputBusIndex, source: input(bus: inputBusIndex)) } }