Add input mute + persist engine I/O counts
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>
This commit is contained in:
@@ -33,6 +33,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||
private static let inputChannels: Int = 1
|
||||
private static let numAudioBuses: Int = 256
|
||||
|
||||
/// UserDefaults keys persisting the last-used engine channel counts. Must match the keys
|
||||
/// written by the builder's engine-config UI (`EngineConfigView.inputChannelsDefaultsKey` /
|
||||
/// `outputChannelsDefaultsKey`) so the choice survives relaunch.
|
||||
private static let inputChannelsDefaultsKey: String = "ShoeGaze.inputChannels"
|
||||
private static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
|
||||
|
||||
/// Reads a persisted channel count, clamped to `[minimum, 8]`, falling back to `fallback` when
|
||||
/// no value has been saved yet.
|
||||
private static func persistedChannelCount(
|
||||
forKey key: String,
|
||||
fallback: Int,
|
||||
minimum: Int
|
||||
) -> Int {
|
||||
let defaults: UserDefaults = UserDefaults.standard
|
||||
guard defaults.object(forKey: key) != nil else { return fallback }
|
||||
let stored: Int = defaults.integer(forKey: key)
|
||||
let maximumChannels: Int = 8
|
||||
return max(minimum, min(stored, maximumChannels))
|
||||
}
|
||||
|
||||
// MARK: - Window geometry constants
|
||||
|
||||
private static let windowWidth: CGFloat = 1_400
|
||||
@@ -95,11 +115,23 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||
|
||||
override init() {
|
||||
let coreDriver: CoreAudioDriver = CoreAudioDriver()
|
||||
// Seed I/O from the last-used counts so a multi-input/output setup survives relaunch (and a
|
||||
// saved live-input channel stays valid). Falls back to the built-in defaults on first launch.
|
||||
let restoredOutputs: Int = AppDelegate.persistedChannelCount(
|
||||
forKey: AppDelegate.outputChannelsDefaultsKey,
|
||||
fallback: AppDelegate.outputChannels,
|
||||
minimum: 1
|
||||
)
|
||||
let restoredInputs: Int = AppDelegate.persistedChannelCount(
|
||||
forKey: AppDelegate.inputChannelsDefaultsKey,
|
||||
fallback: AppDelegate.inputChannels,
|
||||
minimum: 0
|
||||
)
|
||||
let engine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: AppDelegate.blockSize,
|
||||
sampleRate: AppDelegate.sampleRate,
|
||||
numOutputChannels: AppDelegate.outputChannels,
|
||||
numInputChannels: AppDelegate.inputChannels,
|
||||
numOutputChannels: restoredOutputs,
|
||||
numInputChannels: restoredInputs,
|
||||
numAudioBuses: AppDelegate.numAudioBuses,
|
||||
driver: coreDriver
|
||||
)
|
||||
|
||||
@@ -37,6 +37,9 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
/// UserDefaults key persisting the input selection. Must match the key written by the
|
||||
/// builder view (`ShoeGazeBuilderView.inputSelectionDefaultsKey`).
|
||||
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
|
||||
/// UserDefaults key persisting the last-used output-channel count. Must match the key written by
|
||||
/// the builder's engine-config UI (`EngineConfigView.outputChannelsDefaultsKey`).
|
||||
private static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
|
||||
/// Persisted value meaning "live input, channel 0".
|
||||
private static let liveInputChannelZeroTag: Int = 0
|
||||
|
||||
@@ -144,10 +147,17 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
) -> (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) {
|
||||
let sampleRate: Double = AVAudioSession.sharedInstance().sampleRate
|
||||
let driver: iOSAudioDriver = iOSAudioDriver()
|
||||
// Restore the last-used output count so it survives relaunch (input stays on the
|
||||
// permission-gated rebuild flow). Falls back to the default on first launch.
|
||||
let defaults: UserDefaults = UserDefaults.standard
|
||||
let maximumChannels: Int = 8
|
||||
let restoredOutputs: Int = defaults.object(forKey: outputChannelsDefaultsKey) != nil
|
||||
? max(1, min(defaults.integer(forKey: outputChannelsDefaultsKey), maximumChannels))
|
||||
: ShoeGazeBuilderiOSAppModel.outputChannels
|
||||
let engine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
|
||||
sampleRate: sampleRate,
|
||||
numOutputChannels: ShoeGazeBuilderiOSAppModel.outputChannels,
|
||||
numOutputChannels: restoredOutputs,
|
||||
numInputChannels: inputChannels,
|
||||
numAudioBuses: ShoeGazeBuilderiOSAppModel.numAudioBuses,
|
||||
driver: driver
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Internal synthesizer that copies one hardware input bus to a board head bus.
|
||||
///
|
||||
@@ -18,6 +19,17 @@ import LyrebirdSynth
|
||||
/// `teardown()` releases the head bus back to the allocator.
|
||||
final class HardwareInputPassThrough: SynthesizerBase {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Input mute — `0` = audible, `1` = muted (a hard gate on the incoming signal, distinct from
|
||||
/// the rig-output mute). 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 (e.g. `ChainRouter`) 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 hardware input bus to read from (typically `engine.numOutputChannels`).
|
||||
@@ -26,6 +38,11 @@ final class HardwareInputPassThrough: SynthesizerBase {
|
||||
/// 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 pass-through that copies `inputBusIndex` to `outputBusIndex`.
|
||||
@@ -43,6 +60,9 @@ final class HardwareInputPassThrough: SynthesizerBase {
|
||||
// MARK: - Build
|
||||
|
||||
override func build() {
|
||||
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Internal synthesizer that copies the shared global test-loop bus to a board head bus.
|
||||
///
|
||||
@@ -19,6 +20,16 @@ import LyrebirdSynth
|
||||
/// - 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.
|
||||
@@ -27,6 +38,11 @@ final class TestLoopTap: SynthesizerBase {
|
||||
/// 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`
|
||||
@@ -44,6 +60,9 @@ final class TestLoopTap: SynthesizerBase {
|
||||
// MARK: - Build
|
||||
|
||||
override func build() {
|
||||
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,6 +360,8 @@ public final class MIDIController {
|
||||
shoeGaze.toggleRigBypassed()
|
||||
case .rigMute:
|
||||
shoeGaze.toggleRigMuted()
|
||||
case .inputMute:
|
||||
shoeGaze.toggleInputMuted()
|
||||
case .allBoards:
|
||||
// One-shot: cancel any solo and bring every board back up.
|
||||
shoeGaze.selectAllBoards(crossfadeSeconds: boardActionCrossfade)
|
||||
@@ -422,7 +424,7 @@ public final class MIDIController {
|
||||
/// Not used for resolution (bindings resolve by UUID) — purely a human-readable snapshot.
|
||||
private func hint(for action: MIDIMap.Action) -> String? {
|
||||
switch action {
|
||||
case .rigBypass, .rigMute, .allBoards:
|
||||
case .rigBypass, .rigMute, .inputMute, .allBoards:
|
||||
return nil
|
||||
case .boardSolo(let boardID), .boardAudible(let boardID), .boardBypass(let boardID):
|
||||
return board(id: boardID)?.label
|
||||
|
||||
@@ -72,6 +72,8 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
||||
case rigBypass
|
||||
/// Mutes/unmutes the rig output (a hard silence, not a bypass).
|
||||
case rigMute
|
||||
/// Mutes/unmutes the input feeding every board (the incoming guitar / mic signal).
|
||||
case inputMute
|
||||
/// Cancels any solo and makes every board audible again (the "All" button).
|
||||
case allBoards
|
||||
case boardSolo(boardID: UUID)
|
||||
|
||||
@@ -302,6 +302,7 @@ public final class ShoeGaze {
|
||||
outputBusIndex: board.headBus.index
|
||||
)
|
||||
try engine.add(tap, position: NodePosition.after(source))
|
||||
tap.inputMuteNode.update(inputMuted ? 1.0 : 0.0)
|
||||
testLoopTaps.append(tap)
|
||||
// Record the tap as the head input node so PedalBoard.add(_:) can chain the first
|
||||
// pedal after it automatically (without needing an explicit `after:`).
|
||||
@@ -317,6 +318,7 @@ public final class ShoeGaze {
|
||||
outputBusIndex: board.headBus.index
|
||||
)
|
||||
try engine.add(passThrough)
|
||||
passThrough.inputMuteNode.update(inputMuted ? 1.0 : 0.0)
|
||||
inputPassThroughs.append(passThrough)
|
||||
board.headInputNode = passThrough
|
||||
}
|
||||
@@ -433,6 +435,11 @@ public final class ShoeGaze {
|
||||
/// `true` when the rig output is muted (hard-silenced, not bypassed). Survives a rebuild.
|
||||
public private(set) var rigMuted: Bool = false
|
||||
|
||||
/// `true` when the **input** feeding every board is muted — the incoming guitar / mic signal,
|
||||
/// distinct from ``rigMuted`` (the output). Defaults `true` and is re-asserted on each user
|
||||
/// engine start so a fresh start is silent until the player un-mutes. See ``setInputMuted(_:)``.
|
||||
public private(set) var inputMuted: Bool = true
|
||||
|
||||
/// Identities of boards currently in per-board full bypass. Observable so UI toggles refresh;
|
||||
/// authoritative bypass value lives on each board's `boardBypassNode`. Transient (not persisted).
|
||||
public private(set) var bypassedBoards: Set<ObjectIdentifier> = []
|
||||
@@ -585,6 +592,38 @@ public final class ShoeGaze {
|
||||
setRigMuted(!rigMuted)
|
||||
}
|
||||
|
||||
/// Mutes or un-mutes the **input** feeding every board — the incoming guitar / mic signal,
|
||||
/// distinct from the rig-output ``setRigMuted(_:)``. Applied to every board's input writer
|
||||
/// (test-loop tap or hardware pass-through), smoothed to avoid clicks.
|
||||
///
|
||||
/// Defaults muted (``inputMuted`` starts `true`) and is re-asserted on each user engine start
|
||||
/// so a fresh start is silent until the player un-mutes — preventing accidental input noise.
|
||||
///
|
||||
/// - Parameter muted: `true` to silence the input, `false` to let it through.
|
||||
public func setInputMuted(_ muted: Bool) {
|
||||
let value: Double = muted ? 1.0 : 0.0
|
||||
for tap: TestLoopTap in testLoopTaps {
|
||||
tap.inputMuteNode.update(value)
|
||||
}
|
||||
for passThrough: HardwareInputPassThrough in inputPassThroughs {
|
||||
passThrough.inputMuteNode.update(value)
|
||||
}
|
||||
inputMuted = muted
|
||||
}
|
||||
|
||||
/// Toggles the input mute. See ``setInputMuted(_:)``.
|
||||
public func toggleInputMuted() {
|
||||
setInputMuted(!inputMuted)
|
||||
}
|
||||
|
||||
/// The live mute-gain values of every board input writer (test-loop taps and hardware
|
||||
/// pass-throughs). `1` = muted, `0` = audible. Exposed for tests to confirm the RT nodes are
|
||||
/// actually driven by ``setInputMuted(_:)``, not just the ``inputMuted`` flag.
|
||||
var inputMuteNodeValues: [Double] {
|
||||
testLoopTaps.map { $0.inputMuteNode.value }
|
||||
+ inputPassThroughs.map { $0.inputMuteNode.value }
|
||||
}
|
||||
|
||||
/// Removes a single board and its associated input source and output master from
|
||||
/// the engine, then releases the board's buses. The other boards are unaffected.
|
||||
///
|
||||
|
||||
@@ -31,6 +31,10 @@ public struct EngineConfigView: View {
|
||||
/// Channel-count stepper bounds.
|
||||
private static let maxInputs: Int = 8
|
||||
private static let maxOutputs: Int = 8
|
||||
/// UserDefaults keys persisting the last-used engine channel counts so they survive relaunch.
|
||||
/// The app targets read these when constructing the engine (fallback to their own defaults).
|
||||
static let inputChannelsDefaultsKey: String = "ShoeGaze.inputChannels"
|
||||
static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
|
||||
/// Sample-rate comparison tolerance in Hz.
|
||||
private static let rateEpsilon: Double = 0.5
|
||||
private static let rowSpacing: CGFloat = 12
|
||||
@@ -162,12 +166,21 @@ public struct EngineConfigView: View {
|
||||
outputChannels: pendingOutputs
|
||||
)
|
||||
}
|
||||
persistChannelCounts()
|
||||
onConfigApplied()
|
||||
} catch {
|
||||
print("[EngineConfigView] live reconfigure failed: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Persists the current channel counts so the next launch rebuilds the engine with the same
|
||||
/// I/O. Read by the app targets at engine-construction time.
|
||||
private func persistChannelCounts() {
|
||||
let defaults: UserDefaults = UserDefaults.standard
|
||||
defaults.set(pendingInputs, forKey: EngineConfigView.inputChannelsDefaultsKey)
|
||||
defaults.set(pendingOutputs, forKey: EngineConfigView.outputChannelsDefaultsKey)
|
||||
}
|
||||
|
||||
private func label(_ text: String) -> some View {
|
||||
Text(text)
|
||||
.font(.subheadline)
|
||||
@@ -192,6 +205,7 @@ public struct EngineConfigView: View {
|
||||
outputChannels: pendingOutputs
|
||||
)
|
||||
}
|
||||
persistChannelCounts()
|
||||
}
|
||||
try shoeGaze.engine.start()
|
||||
} catch {
|
||||
@@ -207,7 +221,14 @@ public struct EngineConfigView: View {
|
||||
abs(hardware - shoeGaze.engine.sampleRate) > EngineConfigView.rateEpsilon {
|
||||
shoeGaze.engine.stop()
|
||||
presentMismatch(requested: shoeGaze.engine.sampleRate, hardware: hardware)
|
||||
transportTick.toggle()
|
||||
onConfigApplied()
|
||||
return
|
||||
}
|
||||
// A deliberate user start comes up with the input muted so accidental noise can't leak the
|
||||
// instant the engine spins up — the player un-mutes when ready. Transient stop/start-around-
|
||||
// rebuild paths call `engine.start()` directly and are unaffected.
|
||||
shoeGaze.setInputMuted(true)
|
||||
transportTick.toggle()
|
||||
onConfigApplied()
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ public struct MIDIMappingSheet: View {
|
||||
var rows: [SwitchRowModel] = [
|
||||
SwitchRowModel(id: "sw-rig", action: .rigBypass, label: "Rig Bypass"),
|
||||
SwitchRowModel(id: "sw-mute", action: .rigMute, label: "Rig Mute"),
|
||||
SwitchRowModel(id: "sw-input-mute", action: .inputMute, label: "Input Mute"),
|
||||
SwitchRowModel(id: "sw-all", action: .allBoards, label: "All Boards On"),
|
||||
]
|
||||
for board: PedalBoard in shoeGaze.boards {
|
||||
|
||||
@@ -760,6 +760,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
rigBypassButton
|
||||
rigMuteButton
|
||||
inputMuteButton
|
||||
helpButton
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
|
||||
@@ -1117,6 +1118,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
helpButton
|
||||
rigBypassButton
|
||||
rigMuteButton
|
||||
inputMuteButton
|
||||
EngineConfigView(
|
||||
shoeGaze: shoeGaze,
|
||||
hardwareSampleRate: hardwareSampleRate,
|
||||
@@ -1202,6 +1204,22 @@ public struct ShoeGazeBuilderView: View {
|
||||
.help("Mute the entire rig output — silences all sound")
|
||||
}
|
||||
|
||||
/// Input-mute toggle, shown beside the Start/Stop transport. Silences the incoming guitar / mic
|
||||
/// signal (distinct from the rig-output mute). Comes up muted on each engine start.
|
||||
private var inputMuteButton: some View {
|
||||
let muted: Bool = shoeGaze.inputMuted
|
||||
return Button {
|
||||
shoeGaze.toggleInputMuted()
|
||||
} label: {
|
||||
Label(muted ? "Input Muted" : "Mute Input",
|
||||
systemImage: muted ? "mic.slash.fill" : "mic.fill")
|
||||
.font(.subheadline)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(muted ? .red : .gray)
|
||||
.help("Mute the input feeding the pedals — silences the incoming guitar / mic signal")
|
||||
}
|
||||
|
||||
// MARK: - Board area
|
||||
|
||||
private var boardArea: some View {
|
||||
@@ -1396,9 +1414,15 @@ public struct ShoeGazeBuilderView: View {
|
||||
onEnableLiveInput()
|
||||
}
|
||||
// A test-loop choice (or live with no host hook / no permission) leaves the test loop.
|
||||
} else if MicrophonePermission.isAuthorized, shoeGaze.engine.numInputChannels > 0 {
|
||||
// First launch with no saved choice but mic already granted → default to live input.
|
||||
} else if shoeGaze.engine.numInputChannels > 0 {
|
||||
// First launch, no saved choice → default to live input In 0 rather than the test-loop
|
||||
// arpeggio. `switchInput` requests mic access and falls back to the test loop on denial.
|
||||
switchInput(to: .liveInput(channel: 0))
|
||||
} else if let onEnableLiveInput, MicrophonePermission.isAuthorized {
|
||||
// iOS first launch with no input channel yet but mic already granted → rebuild with a
|
||||
// live input silently. (Undetermined permission stays on the test loop to avoid an
|
||||
// unprompted rebuild; the user can enable live input explicitly.)
|
||||
onEnableLiveInput()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// InputMuteTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
/// Tests for the input mute — the hard gate on the signal feeding every board, distinct from the
|
||||
/// rig-output mute.
|
||||
@MainActor
|
||||
@Suite("InputMute")
|
||||
struct InputMuteTests {
|
||||
|
||||
/// A fresh session defaults to input-muted, and every board's input writer comes up muted so a
|
||||
/// just-started engine is silent until the player un-mutes.
|
||||
@Test func defaultsMutedAndDrivesInputNodes() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
#expect(sg.inputMuted)
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
|
||||
#expect(!sg.inputMuteNodeValues.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
/// `setInputMuted(false)` un-mutes every input node and clears the flag; re-muting restores it.
|
||||
@Test func setInputMutedDrivesAllNodes() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
sg.setInputMuted(false)
|
||||
#expect(!sg.inputMuted)
|
||||
let audible: Double = 0.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
||||
|
||||
sg.toggleInputMuted()
|
||||
#expect(sg.inputMuted)
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
|
||||
}
|
||||
}
|
||||
|
||||
/// A board added while the input is un-muted comes up audible — the current mute state is
|
||||
/// applied to newly-wired input nodes, not just the ones present when the toggle flipped.
|
||||
@Test func newBoardAdoptsCurrentMuteState() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let first: PedalBoard = try sg.addBoard()
|
||||
try first.add(VolumePedal())
|
||||
try sg.finalizeBoard(first)
|
||||
|
||||
sg.setInputMuted(false)
|
||||
|
||||
let second: PedalBoard = try sg.addBoard()
|
||||
try second.add(VolumePedal())
|
||||
try sg.finalizeBoard(second)
|
||||
|
||||
let audible: Double = 0.0
|
||||
#expect(sg.inputMuteNodeValues.count == 2)
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
||||
}
|
||||
}
|
||||
|
||||
/// The live-input pass-through path is driven identically to the test-loop tap path.
|
||||
@Test func liveInputPassThroughIsMuted() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: 0.05,
|
||||
numOutputChannels: 2,
|
||||
numInputChannels: 1,
|
||||
numAudioBuses: 256
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine, inputSource: .liveInput(channel: 0))
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuted)
|
||||
#expect(sg.inputMuteNodeValues == [muted])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,26 @@ struct MIDIControllerPCTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func inputMuteLatchesOnEachPressAndIsSeparateFromRigMute() throws {
|
||||
let (controller, sg, _, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
// A fresh session starts input-muted by default.
|
||||
#expect(sg.inputMuted == true, "input defaults muted")
|
||||
|
||||
controller.armSwitchLearn(.inputMute)
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2)) // learn only
|
||||
#expect(sg.inputMuted == true, "learn must not toggle")
|
||||
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == false, "first press un-mutes the input")
|
||||
#expect(sg.rigMuted == false, "input mute must not touch the rig-output mute")
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == true, "second press re-mutes the input")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func pedalBypassLatches() throws {
|
||||
let (controller, sg, boards, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
@@ -70,6 +70,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight != nil, "Stereo board should have a right tail bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -103,6 +104,7 @@ struct StereoRoutingTests {
|
||||
#expect(delay.outputBusRight != nil, "Auto-stereoized pedal should have a right output bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -128,6 +130,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "Stereo-native pedal should widen a mono board")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -156,6 +159,7 @@ struct StereoRoutingTests {
|
||||
|
||||
try board.add(ReverbPedal()) // mono pedal after merge, width-1
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -203,6 +207,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "collectStereo should make the board stereo")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
return deinterleave(readStereoCAF(url: url))
|
||||
@@ -292,6 +297,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight == nil)
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# 2.1.1 — Input mute + I/O persistence
|
||||
|
||||
Two small, related fixes to cut down accidental noise at engine start and make the
|
||||
input configuration survive relaunch.
|
||||
|
||||
## (a) Input mute toggle
|
||||
|
||||
A hard mute on the **input** feeding every board (the guitar / mic signal), distinct
|
||||
from the existing rig-**output** mute. Goals:
|
||||
|
||||
- Defaults **muted**, and is **re-asserted muted every time the engine is (user-)started**,
|
||||
so a fresh start is silent until the player un-mutes — kills accidental ruckus.
|
||||
- A toggle button sits **next to the Start/Stop transport**.
|
||||
- **MIDI mappable** (Program Change + computer key), like Rig Mute.
|
||||
- Also default the input source to **In 0** (live input) instead of the test-loop arpeggio.
|
||||
|
||||
### RT graph
|
||||
|
||||
Each board's input writer (`TestLoopTap` in test-loop mode, `HardwareInputPassThrough`
|
||||
in live mode) gains an `@UIParam inputMute` (0 = audible, 1 = muted). `build()` multiplies
|
||||
the copied signal by a lagged mute gain (20 ms, click-free), mirroring
|
||||
`BoardOutputMaster.rigOutputGainStage()`.
|
||||
|
||||
### ShoeGaze
|
||||
|
||||
- `public private(set) var inputMuted: Bool = true`
|
||||
- `setInputMuted(_:)` drives every `testLoopTaps` + `inputPassThroughs` mute node; `toggleInputMuted()`.
|
||||
- `addBoard()` sets each new input node's mute to the current `inputMuted` so rebuilds stay consistent.
|
||||
|
||||
### Engine start
|
||||
|
||||
`EngineConfigView.startEngine()` calls `shoeGaze.setInputMuted(true)` after a successful
|
||||
user Start. Transient stop/start-around-rebuild paths (`applyInputSource`, `performClear`)
|
||||
call `engine.start()` directly and are unaffected — they preserve the current mute state.
|
||||
|
||||
### MIDI
|
||||
|
||||
- `MIDIMap.Action.inputMute`
|
||||
- `MIDIController.perform` → `toggleInputMuted()`; `hint` → nil.
|
||||
- `MIDIMappingSheet` switch row "Input Mute".
|
||||
|
||||
### Default to In 0
|
||||
|
||||
`ShoeGazeBuilderView.restoreInputSelection()` first-launch (no saved choice) branch requests
|
||||
mic access and selects `.liveInput(channel: 0)` (falling back to test loop on denial / no
|
||||
input), instead of only auto-selecting when already authorised.
|
||||
|
||||
## (b) Persist In/Out channel counts (+ reliable last-input)
|
||||
|
||||
The last-used input **selection** already persists (`ShoeGaze.inputSelection`), but the
|
||||
engine's **channel counts** do not — so on relaunch the engine reverts to the app default
|
||||
(1 in / 2 out). A saved input channel `>=` the smaller default count then fails validation
|
||||
and silently falls back to the test loop. That is the "In doesn't persist" bug.
|
||||
|
||||
Fix: persist the channel counts too.
|
||||
|
||||
- WRITE: `EngineConfigView` persists `pendingInputs` / `pendingOutputs` to UserDefaults
|
||||
(`ShoeGaze.inputChannels` / `ShoeGaze.outputChannels`) whenever they change while stopped.
|
||||
- READ/APPLY at launch, where the engine is actually constructed:
|
||||
- macOS `AppDelegate`: seed `numInputChannels` / `numOutputChannels` from the saved values
|
||||
(fallback 1 / 2).
|
||||
- iOS `ShoeGazeBuilderiOSAppModel`: seed `numOutputChannels` from saved (fallback 2). Input
|
||||
stays on the existing permission-gated rebuild flow.
|
||||
|
||||
Key strings are duplicated in the app targets with a "must match" comment, matching the
|
||||
existing convention for `inputSelectionDefaultsKey`.
|
||||
|
||||
## Tests
|
||||
|
||||
- `InputMuteTests` — `HardwareInputPassThrough` / `TestLoopTap` mute gain; `ShoeGaze.setInputMuted`
|
||||
drives all input nodes; `addBoard` brings a new board up at the current mute state.
|
||||
- `MIDIController` — an `inputMute` switch action toggles `shoeGaze.inputMuted`.
|
||||
Reference in New Issue
Block a user