5987ec7b78
Input mute: a hard gate on the signal feeding every board (guitar / mic), distinct from the rig-output mute. Each board input writer (TestLoopTap / HardwareInputPassThrough) gains a lagged @UIParam mute gain; ShoeGaze holds inputMuted (default true), drives every input node, and brings newly-added boards up at the current state. A deliberate user Start re-asserts the mute so a fresh engine is silent until the player un-mutes — cutting accidental noise. Toggle sits beside the Start/Stop transport and is MIDI mappable (MIDIMap.Action.inputMute). First launch now defaults to live In 0 instead of the test-loop arpeggio. I/O persistence: the engine's input/output channel counts now persist to UserDefaults (written by EngineConfigView, restored by the app targets at engine construction), so a multi-channel setup survives relaunch and a saved live-input channel stays valid — fixing the input selection reverting to the test loop after a restart. Tests: InputMuteTests (default-muted, node driving, per-board adoption, live path) + a MIDI PC input-mute latch test. StereoRouting render tests un-mute before rendering. 460 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.6 KiB
Swift
69 lines
2.6 KiB
Swift
// TestLoopTap.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// 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: - Parameters
|
|
|
|
/// Input mute — `0` = audible, `1` = muted. Driven across every board input node by
|
|
/// `ShoeGaze.setInputMuted(_:)`, which sets a newly-added node to the session's current mute
|
|
/// state. Defaults audible so direct users that don't drive the mute pass the signal through.
|
|
@UIParam var inputMute: Double = 0.0
|
|
|
|
/// The live `UIParamNode` backing `inputMute`, driven by `ShoeGaze.setInputMuted(_:)`.
|
|
var inputMuteNode: UIParamNode { $inputMute }
|
|
|
|
// 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: - Constants
|
|
|
|
/// Lag time in seconds for the mute transition — smooths audible ↔ muted to prevent clicks.
|
|
private let muteLagTime: Double = 0.02
|
|
|
|
// 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() {
|
|
// Gate the copied signal by a lagged mute: mute 0 → gain 1 (audible), 1 → gain 0 (silent).
|
|
let muteLagged: Lag.Control = Lag.Control(input: $inputMute, time: muteLagTime)
|
|
let muteGain: any ValidGeneratorInput = (muteLagged - 1.0) * -1.0
|
|
output(bus: outputBusIndex, source: input(bus: inputBusIndex) * muteGain)
|
|
}
|
|
}
|