10 Commits

Author SHA1 Message Date
josh 7720fbec7b bump versions 2026-07-12 12:32:36 -07:00
josh 3228614071 Release notes for 2.1.1: input mute + rig-persisted I/O
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 12:30:36 -07:00
josh e207728a12 Review nits: name pulse-settle constant, fix stale comments
Non-blocking cleanups from the clean review pass:
- EngineConfigView.startEngine: collapse the redundant early-return in the
  sample-rate-mismatch branch into the shared tail.
- InputMuteButton: hoist the 0.2s settle duration to a named pulseSettleDuration.
- InputMuteTests: correct a stale "input defaults muted" comment (library default
  is audible; the test mutes explicitly).
- Plan doc: setInputMuted(true) runs before engine.start(), not after; note the
  addBoard priming.

464 tests pass; macOS app builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 21:41:57 -07:00
josh e36074e9d3 Review fix: prime input-mute ramp + mute before engine start
Two blocking findings from external review:

1. UIParamNode itself ramps from previousOutputValue (seeded at the compile-time
   default, advanced only by RT render — update() doesn't touch it) to the target
   over the first block. So a node told to start muted still ramped full-gain→0
   across block 0; the earlier "hard gate" only moved the leak from Lag to the
   param's own ramp. The mutedInputRendersSilent test passed by accident (the
   test-loop tone is quiet in that first block).
   Fix: prime previousOutputValue to the target. Race-free before a node is
   spliced into the graph (addBoard) and safe on a spliced node while the engine
   is stopped; a running engine keeps the ramp as a click-free live toggle. New
   setInputMuteGain(_:muted:seedRamp:) / primeInputMute helpers; setInputMuted
   seeds only when engine.isRunning == false.

2. EngineConfigView.startEngine called setInputMuted(true) AFTER engine.start(),
   so the engine came up unmuted for the first blocks. Moved it before start()
   (engine stopped there, so the gain is seeded with no ramp).

Also: correct the setInputMuted doc (abrupt kill-switch, not "smoothed").
Regression test stoppedMutePrimesNodesSoTheresNoStartRamp asserts the ramp start
equals the target (no pending ramp) after a stopped mute and for a board added
while muted. 464 tests pass; both app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 21:34:46 -07:00
josh b29c8848ef Review fix: exact-silence input mute (hard kill-switch gate)
External review found the lagged mute gate leaks a faint transient (~-54 dB) on
its first blocks: Lag seeds its state at 0, so gating on a lagged value never
starts at exactly zero on a rig that comes up muted — the moment the mute is
meant to keep things quiet. Measured directly via an NRT render.

- Gate the input with a hard, un-lagged kill switch `(inputMute - 1) * -1` in
  both HardwareInputPassThrough and TestLoopTap. A muted node is then exactly
  silent from the first sample; a kill-switch mute is expected to be abrupt.
  Drop the now-unused muteLagTime constant.
- Flip the library default to `inputMuted = false` (audible). Muting is the app's
  Start-time policy (EngineConfigView already re-asserts muted on user Start), so
  headless/offline library use isn't forced silent and render tests that route the
  test-loop through a board no longer depend on a leak to see signal. The pulsing
  glow now also starts at engine Start rather than before it.
- Tests: add render-level mutedInputRendersSilent (exact silence) and
  unmutedInputRendersSignal; update the default-state and MIDI-latch expectations;
  drop the StereoRouting un-mutes that the leak had made necessary.
- Plan doc: correct the mute default / gate description and the UserDefaults note.

463 tests pass; both app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 16:03:50 -07:00
josh be0e3d118b Declare LSSupportsOpeningDocumentsInPlace on iOS
The iOS app declares a .shoegaze document type but didn't state whether it opens
documents in place. Incoming files are read and imported into the rig library (a
copy), never edited in place, so declare false — silencing the launch warning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:45:43 -07:00
josh 5542ee5b5a Document input mute in Help; pulsing glow while muted
- Help: cover the input mute in Setup ("input starts muted on every Start"),
  Choosing an Input (hard input gate vs the output Rig Mute, MIDI-mappable), and
  the MIDI switch list (Rig Mute / Input Mute).
- Input-mute button is now its own view with a pulsing red ring + shadow that
  oscillates under a repeatForever animation while muted, so new users see why
  the rig is silent. The glow settles out when un-muted and never intercepts taps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:44:02 -07:00
josh b0294612f8 Fix mapping-badge actor warnings; un-crowd the transport row
- MappingBadge.pcFill/ccFill/keyFill are marked nonisolated so the nonisolated
  MappingBadgeKind.fill can read them (a SwiftUI View's statics are otherwise
  main-actor-isolated). Clears three "actor-isolated ... from a nonisolated
  context" warnings.
- The input-mute button pushed the docked desktop transport cluster past the row
  width, clipping the Rate picker and I/O steppers. Render the three rig toggles
  (Bypass / Mute / Input) icon-only there via .labelStyle(.iconOnly); the .help
  tooltips remain and the compact layout still shows text labels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:38:22 -07:00
josh cc3a986cde Persist I/O + input via the rig, not UserDefaults
The rig snapshot already stores inputSource + input/output channel counts and
syncs them via the autosave envelope and the iCloud rig library. Make that the
single source of truth instead of the parallel UserDefaults path.

- RigStore.restore applies the saved channel layout (applyChannelLayout) before
  loadRig, while stopped at launch, so a saved live-input channel validates
  against the restored count instead of falling back to the test loop. The
  general loadRig policy (don't force layout mid-session) is unchanged.
- applyInputSource and the engine-config onConfigApplied now autosave, so input
  and I/O changes are captured into the rig immediately.
- Remove the UserDefaults keys and read/write sites: ShoeGaze.inputSelection
  (builder view + iOS model) and the ShoeGaze.inputChannels/outputChannels keys
  added earlier (EngineConfigView + both app targets build at the default layout
  now; RigStore.restore supplies the rig's layout).
- Fresh-launch default: the seed paths set inputSource = liveInput(0) when the
  engine has an input channel, so a first launch listens to the instrument. A
  restored rig keeps its own saved input; the view's on-appear hook only requests
  mic access for a restored live selection (test-loop fallback on denial).

Test: RigStore.restoreAppliesSavedChannelLayoutAndInput. 461 tests pass; both
app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:34:23 -07:00
josh 5987ec7b78 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>
2026-07-11 15:17:51 -07:00
24 changed files with 685 additions and 76 deletions
+37
View File
@@ -4,6 +4,43 @@ All notable changes to ShoeGaze are recorded here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
[semantic versioning](https://semver.org/spec/v2.0.0.html).
## [2.1.1] — 2026-07-12
A quieter, more predictable startup. The input feeding the pedals now has its own
mute — separate from the rig-output mute — that arms every time you start the engine,
so nothing squeals the instant it spins up. New rigs open listening to In 0 instead of
the test-loop phrase, and your input choice and I/O channel counts now travel with the
rig (and iCloud) instead of a separate local setting.
### Added
- **Input mute.** A hard kill-switch on the incoming guitar / mic signal, distinct from
the rig-output mute. It arms automatically every time you press Start (so a fresh
engine is silent until you're ready), sits next to the Start/Stop transport with a
pulsing red glow while active, and is MIDI-mappable (footswitch or key), like Rig Mute.
### Changed
- **New rigs open on In 0** (live input) instead of the built-in test-loop phrase.
- **Input & I/O persist with the rig.** The input selection and the engine's input /
output channel counts are stored in the rig (and sync via iCloud), and are reapplied
on launch — so a multi-channel setup and a chosen input channel survive a restart
instead of reverting to the defaults. Replaces the previous local-only input setting.
- The docked (macOS) transport shows the Bypass / Mute / Input toggles as icons so the
row no longer crowds the sample-rate and channel controls.
### Fixed
- A muted input is now **exactly** silent from the first sample — no brief start-up
transient when the engine begins rendering.
- iOS: the app declares in-place document support, clearing a launch-time console warning.
### Compatibility
Additive: rigs saved before this release load unchanged (input defaults to In 0, or the
test loop when no live input is available), and 2.1.1 rigs still open in older builds —
the input-mute state isn't persisted and the extra I/O fields are ignored there.
## [2.1.0] — 2026-07-10
Tempo comes to the pedals. Delay times and modulation rates can lock to a note
@@ -163,7 +163,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = HE5VJFE9E4;
@@ -176,7 +176,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 2.0.0;
MARKETING_VERSION = 2.1.1;
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -194,7 +194,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = HE5VJFE9E4;
ENABLE_HARDENED_RUNTIME = YES;
@@ -206,7 +206,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 2.0.0;
MARKETING_VERSION = 2.1.1;
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
"state" : {
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
"version" : "1.2.0"
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
"version" : "1.2.3"
}
},
{
+7
View File
@@ -95,6 +95,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
override init() {
let coreDriver: CoreAudioDriver = CoreAudioDriver()
// The engine is built with the default layout; the autosaved rig's saved I/O layout (if any)
// is applied by `RigStore.restore` below, so a multi-channel setup survives relaunch.
let engine: SynthesisEngine = SynthesisEngine(
blockSize: AppDelegate.blockSize,
sampleRate: AppDelegate.sampleRate,
@@ -127,6 +129,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
/// Seeds one board with a single pedal so the builder opens with an audible starting point.
private static func seedInitialBoard(into shoeGaze: ShoeGaze) {
// Fresh launch (no autosaved rig): default to live In 0 rather than the test-loop arpeggio,
// so the app comes up listening to the instrument. A restored rig keeps its own saved input.
if shoeGaze.engine.numInputChannels > 0 {
shoeGaze.inputSource = .liveInput(channel: 0)
}
var created: PedalBoard?
do {
let board: PedalBoard = try shoeGaze.addBoard()
+2 -2
View File
@@ -28,9 +28,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<string>2.1.2</string>
<key>CFBundleVersion</key>
<string>7</string>
<string>10</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
@@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
"state" : {
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
"version" : "1.2.0"
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
"version" : "1.2.3"
}
},
{
+4
View File
@@ -17,6 +17,10 @@
</array>
</dict>
</array>
<!-- Incoming .shoegaze files are read and imported into the rig library (a copy), never
edited in place, so the app opens a copy rather than the original document. -->
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
@@ -34,12 +34,6 @@ final class ShoeGazeBuilderiOSAppModel {
private static let numAudioBuses: Int = 256
private static let seedPedalType: PedalType = .overdrive
/// UserDefaults key persisting the input selection. Must match the key written by the
/// builder view (`ShoeGazeBuilderView.inputSelectionDefaultsKey`).
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
/// Persisted value meaning "live input, channel 0".
private static let liveInputChannelZeroTag: Int = 0
// MARK: - Owned objects
/// The active ShoeGaze builder session. Swapped out when live input is enabled (the engine
@@ -144,6 +138,8 @@ final class ShoeGazeBuilderiOSAppModel {
) -> (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) {
let sampleRate: Double = AVAudioSession.sharedInstance().sampleRate
let driver: iOSAudioDriver = iOSAudioDriver()
// The engine is built with the default layout; the autosaved rig's saved I/O (if any) is
// applied by `RigStore.restore`, so an output change survives relaunch.
let engine: SynthesisEngine = SynthesisEngine(
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
sampleRate: sampleRate,
@@ -222,14 +218,12 @@ final class ShoeGazeBuilderiOSAppModel {
if wasRunning { try? engine.start() }
}
/// Selects live input on channel 0 and persists the choice for restore-on-relaunch.
/// Selects live input on channel 0 and autosaves so the rig (the source of truth for the input
/// selection) records it for restore-on-relaunch.
private func selectLiveInputAndPersist() {
do {
try shoeGaze.setInputSource(.liveInput(channel: 0))
UserDefaults.standard.set(
ShoeGazeBuilderiOSAppModel.liveInputChannelZeroTag,
forKey: ShoeGazeBuilderiOSAppModel.inputSelectionDefaultsKey
)
save()
} catch {
print("[ShoeGazeBuilderiOS] selecting live input failed: \(error)")
}
@@ -237,6 +231,11 @@ final class ShoeGazeBuilderiOSAppModel {
/// Seeds a single default board so the rig is never empty after a failed restore.
private static func seedFallbackBoard(into shoeGaze: ShoeGaze) {
// Fresh launch (no autosaved rig): default to live In 0 rather than the test-loop arpeggio.
// A restored rig keeps its own saved input selection.
if shoeGaze.engine.numInputChannels > 0 {
shoeGaze.inputSource = .liveInput(channel: 0)
}
do {
let board: PedalBoard = try shoeGaze.addBoard()
board.label = "Board 1"
+23
View File
@@ -1,4 +1,27 @@
# Releases
## ShoeGaze 2.1.1
A quieter, more predictable startup. The signal feeding the pedals now has its own mute
that arms every time you start the engine, new rigs open listening to your instrument,
and your input and I/O settings travel with the rig instead of a local-only setting.
### Highlights
- **Input mute** — a hard kill-switch on the incoming guitar / mic signal, separate from
the rig-output mute. Arms automatically on every Start (silent until you're ready),
sits by the Start/Stop transport with a pulsing red glow while active, and is
MIDI-mappable like Rig Mute. A muted input is exactly silent from the first sample.
- **Opens on In 0** — new rigs listen to live input instead of the test-loop phrase.
- **Input & I/O persist with the rig** — the input selection and engine input/output
channel counts are stored in the rig (and iCloud) and reapplied on launch, so a
multi-channel setup and a chosen input survive a restart. Replaces the old local-only
input setting.
- **Tidier transport** — the docked macOS Bypass / Mute / Input toggles are icons so the
row no longer crowds the rate and channel controls.
### Compatibility
Additive: rigs saved before this release load unchanged, and 2.1.1 rigs still open in
older builds (input-mute state isn't persisted; the extra I/O fields are ignored there).
## ShoeGaze 2.1.0
Tempo comes to the pedals. Delay times and LFO rates can lock to note divisions of the
@@ -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`).
@@ -43,6 +55,11 @@ final class HardwareInputPassThrough: SynthesizerBase {
// MARK: - Build
override func build() {
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
// Hard kill-switch gate: `1 − inputMute`, so mute 0 → gain 1 (audible), 1 → gain 0 (exactly
// silent). Unlagged on purpose — a lagged gate never settles to exactly zero on its first
// blocks and leaks a faint transient right when the mute is meant to keep things quiet; a
// kill-switch mute is expected to be abrupt anyway.
let muteGain: any ValidGeneratorInput = ($inputMute - 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.
@@ -44,6 +55,11 @@ final class TestLoopTap: SynthesizerBase {
// MARK: - Build
override func build() {
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
// Hard kill-switch gate: `1 − inputMute`, so mute 0 → gain 1 (audible), 1 → gain 0 (exactly
// silent). Unlagged on purpose — a lagged gate never settles to exactly zero on its first
// blocks and leaks a faint transient right when the mute is meant to keep things quiet; a
// kill-switch mute is expected to be abrupt anyway.
let muteGain: any ValidGeneratorInput = ($inputMute - 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)
@@ -85,15 +85,29 @@ public enum RigStore {
do {
let data: Data = try Data(contentsOf: url)
let decoder: JSONDecoder = JSONDecoder()
let state: ShoeGazeState
let rigID: UUID?
if let envelope: AutosaveEnvelope = try? decoder.decode(AutosaveEnvelope.self, from: data) {
try shoeGaze.loadRig(from: envelope.state)
shoeGaze.currentRigID = envelope.currentRigID
state = envelope.state
rigID = envelope.currentRigID
} else {
// Pre-envelope autosave: a bare ShoeGazeState with no recorded source rig.
let state: ShoeGazeState = try decoder.decode(ShoeGazeState.self, from: data)
try shoeGaze.loadRig(from: state)
shoeGaze.currentRigID = nil
state = try decoder.decode(ShoeGazeState.self, from: data)
rigID = nil
}
// Unlike a mid-session rig load — where forcing the layout would fight the global engine
// config and the iOS enable-live-input flow — a launch restore SHOULD reinstate the
// rig's saved I/O layout so a multi-channel setup (and a saved live-input channel)
// survives relaunch. Apply it first, while the engine is stopped, so `loadRig`'s
// input-channel validation runs against the restored count. A failure here is
// non-fatal — fall through to `loadRig`, which still rebuilds the boards.
do {
try shoeGaze.applyChannelLayout(from: state)
} catch {
print("[RigStore] channel-layout restore failed (continuing): \(error)")
}
try shoeGaze.loadRig(from: state)
shoeGaze.currentRigID = rigID
return !shoeGaze.boards.isEmpty
} catch {
print("[RigStore] restore failed: \(error)")
+74
View File
@@ -301,6 +301,9 @@ public final class ShoeGaze {
inputBusIndex: testBus.index,
outputBusIndex: board.headBus.index
)
// Prime the mute gain before splicing the node in, so its very first render block
// reflects the current mute state with no ramp (see `primeInputMute`).
primeInputMute(tap.inputMuteNode, muted: inputMuted)
try engine.add(tap, position: NodePosition.after(source))
testLoopTaps.append(tap)
// Record the tap as the head input node so PedalBoard.add(_:) can chain the first
@@ -316,6 +319,8 @@ public final class ShoeGaze {
inputBusIndex: hardwareInputBusIndex,
outputBusIndex: board.headBus.index
)
// Prime the mute gain before splicing the node in (see `primeInputMute`).
primeInputMute(passThrough.inputMuteNode, muted: inputMuted)
try engine.add(passThrough)
inputPassThroughs.append(passThrough)
board.headInputNode = passThrough
@@ -433,6 +438,13 @@ 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 `false` (audible); the app re-asserts it
/// muted on each user engine start (see `EngineConfigView`) so a fresh start is silent until the
/// player un-mutes, without forcing silence on headless / offline library use. See
/// ``setInputMuted(_:)``.
public private(set) var inputMuted: Bool = false
/// 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 +597,68 @@ 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) as an abrupt kill-switch gate (unlagged, so a
/// muted input is exactly silent — see the note in `HardwareInputPassThrough.build()`).
///
/// The app re-asserts this muted on each user engine start (see `EngineConfigView`) 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) {
// Seed the ramp start only while the engine is stopped: then the next Start renders the new
// mute state from block zero with no audible→muted (or muted→audible) ramp — which is exactly
// what "muted on Start" needs. While the engine is running, seeding `previousOutputValue`
// would race the RT thread; leaving it lets the one-block ramp act as a click-free toggle.
let seedRamp: Bool = !engine.isRunning
for tap: TestLoopTap in testLoopTaps {
setInputMuteGain(tap.inputMuteNode, muted: muted, seedRamp: seedRamp)
}
for passThrough: HardwareInputPassThrough in inputPassThroughs {
setInputMuteGain(passThrough.inputMuteNode, muted: muted, seedRamp: seedRamp)
}
inputMuted = muted
}
/// Primes a freshly-created input-mute node (not yet spliced into the graph) to the given mute
/// state so its first render block has no ramp. Race-free because the node is not yet evaluated
/// by the RT thread. See ``setInputMuteGain(_:muted:seedRamp:)``.
private func primeInputMute(_ node: UIParamNode, muted: Bool) {
setInputMuteGain(node, muted: muted, seedRamp: true)
}
/// Sets an input node's mute gain. `update` stores the atomic target the RT thread ramps toward
/// from `previousOutputValue`; that seed is only advanced by RT render, so `update` alone leaves
/// a one-block ramp from the node's prior value. When `seedRamp` is `true` (node not yet spliced,
/// or engine stopped) we also seed `previousOutputValue` to the target so there is no ramp.
private func setInputMuteGain(_ node: UIParamNode, muted: Bool, seedRamp: Bool) {
let value: Double = muted ? 1.0 : 0.0
node.update(value)
if seedRamp { node.previousOutputValue = value }
}
/// 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 }
}
/// The `previousOutputValue` (ramp start) of every board input-mute node. Exposed for tests to
/// confirm a stopped-engine mute is *primed* — ramp start equal to the target — so the next
/// render can't ramp from the prior value and leak a block. See ``setInputMuteGain(_:muted:seedRamp:)``.
var inputMutePreviousValues: [Double] {
testLoopTaps.map { $0.inputMuteNode.previousOutputValue }
+ inputPassThroughs.map { $0.inputMuteNode.previousOutputValue }
}
/// 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.
///
@@ -42,9 +42,11 @@ enum MappingBadgeKind {
/// One coloured pill — e.g. `CC11`, `PC3`, `⇧B` — marking a control's binding.
struct MappingBadge: View {
static let pcFill: Color = Color(red: 0.11, green: 0.37, blue: 0.65)
static let ccFill: Color = Color(red: 0.33, green: 0.29, blue: 0.72)
static let keyFill: Color = Color(red: 0.73, green: 0.46, blue: 0.09)
// `nonisolated` so the nonisolated `MappingBadgeKind.fill` can read them — a SwiftUI `View`'s
// statics are otherwise main-actor-isolated. The values are immutable `Sendable` colours.
nonisolated static let pcFill: Color = Color(red: 0.11, green: 0.37, blue: 0.65)
nonisolated static let ccFill: Color = Color(red: 0.33, green: 0.29, blue: 0.72)
nonisolated static let keyFill: Color = Color(red: 0.73, green: 0.46, blue: 0.09)
private static let fontSize: CGFloat = 9
private static let paddingH: CGFloat = 5
@@ -193,6 +193,12 @@ public struct EngineConfigView: View {
)
}
}
// A deliberate user Start comes up with the input muted so accidental noise can't leak
// the instant the engine spins up. Set it BEFORE start (engine is stopped here, so the
// gain is seeded with no ramp) — asserting it after start would leave the first render
// blocks unmuted. Transient stop/start-around-rebuild paths call `engine.start()`
// directly and are unaffected — they preserve the current mute state.
shoeGaze.setInputMuted(true)
try shoeGaze.engine.start()
} catch {
handleStartError(error)
+15 -5
View File
@@ -40,6 +40,9 @@ public struct HelpView: View {
steps: [
"Set the sample Rate and the input/output channel counts in the top-right controls.",
"Press Start to run the engine; press again to Stop. Most controls stay live while running.",
"Input starts MUTED every time you press Start — a safety default so nothing squeals "
+ "the instant the engine spins up. The Input Mute button (microphone icon, left of "
+ "the Start button) pulses red while muted; click it to let your instrument through.",
"Bypass Rig compares your sound with and without the whole pedalboard.",
]
)
@@ -63,11 +66,17 @@ public struct HelpView: View {
topicSection(
icon: "waveform",
title: "Choosing an Input",
intro: "Pick what feeds the board.",
intro: "Pick what feeds the board, and mute it when you need silence.",
steps: [
"Input ▸ Test Loop plays a built-in phrase, so you can hear the rig with no guitar connected.",
"Input ▸ In 0 (Live Input on iOS) uses your audio interface or mic. iOS asks for "
+ "microphone access the first time you enable it.",
+ "microphone access the first time you enable it. New rigs open on In 0.",
"Input Mute (microphone icon, left of Start) is a hard gate on the incoming signal — "
+ "distinct from Rig Mute, which silences the OUTPUT. Use it to stop feedback or "
+ "handling noise while you set up. It pulses red while muted, and re-arms muted on "
+ "every Start.",
"The input mute is MIDI-mappable — bind it to a footswitch or key in MIDI / Control "
+ "Mapping for a hands-free panic mute of your instrument.",
]
)
topicSection(
@@ -143,9 +152,10 @@ public struct HelpView: View {
steps: [
"The keys icon in the top bar lights green when a device is connected. Tap it to open "
+ "MIDI / Control Mapping.",
"Switches: footswitches and letter keys toggle Rig Bypass, All Boards, and each board's "
+ "Solo / Audible / Bypass or a pedal's bypass. Tap PC then press a footswitch, or Key "
+ "then press a key. One switch or key can drive several actions at once — a scene.",
"Switches: footswitches and letter keys toggle Rig Bypass, Rig Mute, Input Mute, All "
+ "Boards, and each board's Solo / Audible / Bypass or a pedal's bypass. Tap PC then "
+ "press a footswitch, or Key then press a key. One switch or key can drive several "
+ "actions at once — a scene.",
"Keys fire only when you're not typing — while a text field (like a rig name) is focused, "
+ "letters go to the field, not to your mappings.",
"Hold Shift, Control, or Option while learning to bind a modified key — a and ⇧a are "
@@ -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 {
@@ -59,8 +59,6 @@ public struct ShoeGazeBuilderView: View {
private static let backgroundGreen: Double = 0.07
private static let backgroundBlue: Double = 0.06
private static let testLoopTag: Int = -1
/// UserDefaults key persisting the last input selection (`-1` = test loop, `>= 0` = channel).
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
/// Maximum crossfade duration honoured by board-switch keyboard shortcuts.
private static let maxCrossfadeSeconds: Double = 10.0
/// Highest board reachable via a ⌘-number switch shortcut.
@@ -745,7 +743,7 @@ public struct ShoeGazeBuilderView: View {
EngineConfigView(
shoeGaze: shoeGaze,
hardwareSampleRate: hardwareSampleRate,
onConfigApplied: { transportTick.toggle() },
onConfigApplied: { transportTick.toggle(); autosave() },
transportOnly: true
)
#if !os(macOS)
@@ -760,6 +758,7 @@ public struct ShoeGazeBuilderView: View {
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
rigBypassButton
rigMuteButton
inputMuteButton
helpButton
if let midi: MIDIController = midi {
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
@@ -891,7 +890,7 @@ public struct ShoeGazeBuilderView: View {
EngineConfigView(
shoeGaze: shoeGaze,
hardwareSampleRate: hardwareSampleRate,
onConfigApplied: { transportTick.toggle() }
onConfigApplied: { transportTick.toggle(); autosave() }
)
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
@@ -1115,12 +1114,19 @@ public struct ShoeGazeBuilderView: View {
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
}
helpButton
rigBypassButton
rigMuteButton
// Icon-only in the docked desktop cluster so the four toggles + Rate picker +
// I/O steppers + Start never overrun the row and clip the pickers. Each button
// keeps its `.help` tooltip; the compact layout still shows the text labels.
Group {
rigBypassButton
rigMuteButton
inputMuteButton
}
.labelStyle(.iconOnly)
EngineConfigView(
shoeGaze: shoeGaze,
hardwareSampleRate: hardwareSampleRate,
onConfigApplied: { transportTick.toggle() }
onConfigApplied: { transportTick.toggle(); autosave() }
)
}
.frame(height: TempoView.enabledHeight)
@@ -1202,6 +1208,75 @@ 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, with a
/// pulsing red glow while muted so new users spot why they hear nothing.
private var inputMuteButton: some View {
InputMuteButton(shoeGaze: shoeGaze)
}
/// The input-mute toggle with a pulsing red glow while active. Its own view so it can own the
/// repeating-animation state; the glow reads `pulse`, which oscillates under a `repeatForever`
/// animation only while the input is muted.
private struct InputMuteButton: View {
let shoeGaze: ShoeGaze
/// Oscillates 0↔1 under a repeating animation while muted, driving the glow's radius/opacity.
@State private var pulse: Bool = false
private static let glowCornerRadius: CGFloat = 6
private static let glowLineWidth: CGFloat = 1.5
private static let glowRadiusLow: CGFloat = 2
private static let glowRadiusHigh: CGFloat = 9
private static let glowOpacityLow: Double = 0.35
private static let glowOpacityHigh: Double = 0.95
private static let pulseDuration: Double = 0.85
private static let pulseSettleDuration: Double = 0.2
var body: 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)
.overlay(glow(muted: muted))
.help("Mute the input feeding the pedals — silences the incoming guitar / mic signal")
.onChange(of: muted) { _, nowMuted in startOrStopPulse(muted: nowMuted) }
.onAppear { startOrStopPulse(muted: muted) }
}
/// A red ring + shadow that pulses while muted, and is invisible otherwise. Non-interactive
/// so it never intercepts the button's taps.
private func glow(muted: Bool) -> some View {
RoundedRectangle(cornerRadius: InputMuteButton.glowCornerRadius, style: .continuous)
.strokeBorder(Color.red, lineWidth: InputMuteButton.glowLineWidth)
.shadow(
color: Color.red,
radius: pulse ? InputMuteButton.glowRadiusHigh : InputMuteButton.glowRadiusLow
)
.opacity(muted ? (pulse ? InputMuteButton.glowOpacityHigh : InputMuteButton.glowOpacityLow) : 0)
.allowsHitTesting(false)
}
/// Starts the forever-repeating pulse when muted, or settles it back to rest when not.
private func startOrStopPulse(muted: Bool) {
if muted {
pulse = false
withAnimation(.easeInOut(duration: InputMuteButton.pulseDuration).repeatForever(autoreverses: true)) {
pulse = true
}
} else {
withAnimation(.easeOut(duration: InputMuteButton.pulseSettleDuration)) { pulse = false }
}
}
}
// MARK: - Board area
private var boardArea: some View {
@@ -1352,7 +1427,7 @@ public struct ShoeGazeBuilderView: View {
if wasRunning { shoeGaze.engine.stop() }
do {
try shoeGaze.setInputSource(source)
persistInputSelection(source)
autosave() // the rig is the source of truth for the input selection; record it now
} catch {
print("[ShoeGazeBuilderView] setInputSource failed: \(error)")
}
@@ -1362,43 +1437,26 @@ public struct ShoeGazeBuilderView: View {
transportTick.toggle()
}
// MARK: - Input persistence
// MARK: - Input restore
/// Saves the current input choice so it is restored on the next launch.
private func persistInputSelection(_ source: InputSource) {
let value: Int
switch source {
case .testLoop:
value = ShoeGazeBuilderView.testLoopTag
case .liveInput(let channel):
value = channel
}
UserDefaults.standard.set(value, forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
}
/// Restores the saved input choice once on appear. With no saved choice, defaults to live
/// input when the microphone is already authorised and the engine has an input channel —
/// otherwise stays on the test loop. A saved live channel that no longer fits the engine, or
/// a since-revoked permission, falls back to the test loop via `switchInput(to:)`.
/// Reconciles the microphone permission with the input source the rig already restored.
///
/// The rig (autosave envelope / library entry) is the single source of truth for the input
/// selection — `RigStore.restore` / `loadRig` set `shoeGaze.inputSource` before this view
/// appears, and a fresh-launch seed defaults it to live In 0. This runs once on appear only to
/// make a restored live-input selection actually audible: it requests mic access (surfacing the
/// prompt at launch rather than at the first Start) and falls back to the test loop on denial.
/// A restored test-loop selection is honoured untouched.
private func restoreInputSelection() {
guard !didRestoreInput else { return }
didRestoreInput = true
let defaults: UserDefaults = UserDefaults.standard
if defaults.object(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey) != nil {
let stored: Int = defaults.integer(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
if stored >= 0, stored < shoeGaze.engine.numInputChannels {
switchInput(to: .liveInput(channel: stored))
} else if stored >= 0, shoeGaze.engine.numInputChannels == 0,
MicrophonePermission.isAuthorized, let onEnableLiveInput {
// iOS: a live choice was saved and the mic is already authorised — rebuild the
// engine with an input channel silently (no prompt, since access is granted).
onEnableLiveInput()
guard case .liveInput = shoeGaze.inputSource else { return }
MicrophonePermission.request { granted in
if !granted {
showMicDeniedAlert = true
applyInputSource(.testLoop)
}
// 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.
switchInput(to: .liveInput(channel: 0))
}
}
@@ -0,0 +1,189 @@
// 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 audible at the library level (the app mutes on engine Start), and
/// muting drives every board's input writer to the silent gain.
@Test func defaultsAudibleThenMuteDrivesInputNodes() 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 audible: Double = 0.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
#expect(!sg.inputMuteNodeValues.isEmpty)
sg.setInputMuted(true)
let muted: Double = 1.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
}
}
/// `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 })
}
}
/// A muted input renders **exactly** silent through a full render — the kill-switch gate reaches
/// zero with no residual. A lagged gate leaked a faint transient on its first blocks; the hard
/// gate does not.
@Test func mutedInputRendersSilent() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.25, 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(true) // mute explicitly before Start (library default is audible)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(!hasNonSilentOutput(samples),
"a muted input must render silent — the kill-switch gate leaves no residual")
}
}
/// Muting while the engine is stopped **primes** every input node — its ramp start (`previous
/// OutputValue`) equals the muted target — so the next Start renders muted from block zero with no
/// audible→muted ramp. Guards against the `UIParamNode` one-block ramp leaking a fresh node's
/// prior (audible) value. A freshly-added board is primed the same way.
@Test func stoppedMutePrimesNodesSoTheresNoStartRamp() 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)
// Default audible: node value and ramp start both at 0 (no pending ramp).
let audible: Double = 0.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == audible })
// Mute while stopped: both the target and the ramp start move to 1 → no leak on Start.
sg.setInputMuted(true)
let muted: Double = 1.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == muted },
"a stopped-engine mute must prime the ramp start so the first render can't ramp")
// A board added while muted comes up primed muted too.
let second: PedalBoard = try sg.addBoard()
try second.add(VolumePedal())
try sg.finalizeBoard(second)
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == muted })
#expect(sg.inputMuteNodeValues.count == 2)
}
}
/// Un-muting the input lets the test-loop signal through — the gate opens fully.
@Test func unmutedInputRendersSignal() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.25, 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)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(hasNonSilentOutput(samples),
"an un-muted input must pass the test-loop signal through")
}
}
/// The live-input pass-through path is driven by `setInputMuted` identically to the test-loop tap.
@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 audible: Double = 0.0
#expect(!sg.inputMuted)
#expect(sg.inputMuteNodeValues == [audible])
sg.setInputMuted(true)
let muted: Double = 1.0
#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 library session starts audible (the app mutes on engine Start).
#expect(sg.inputMuted == false, "input defaults audible at the library level")
controller.armSwitchLearn(.inputMute)
controller.ingestForTesting(.programChange(channel: 0, program: 2)) // learn only
#expect(sg.inputMuted == false, "learn must not toggle")
controller.ingestForTesting(.programChange(channel: 0, program: 2))
#expect(sg.inputMuted == true, "first press 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 == false, "second press un-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) }
@@ -83,6 +83,41 @@ struct RigStoreTests {
#expect(b.currentRigID == rigID, "restore must carry the source-rig id so the UI highlights it")
}
/// A launch restore reinstates the rig's saved I/O layout so a multi-channel setup survives
/// relaunch, and a saved live-input channel that only fits the wider layout stays selected
/// (rather than falling back to the test loop against the fresh engine's default count).
@Test func restoreAppliesSavedChannelLayoutAndInput() throws {
let autosave: URL = try isolateAutosave()
defer {
RigStore.autosaveURLOverride = nil
try? FileManager.default.removeItem(at: autosave.deletingLastPathComponent())
}
RigStore.clear()
// Save a rig on a 2-in / 2-out engine with live input on channel 1.
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05, numOutputChannels: 2, numInputChannels: 2, numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: urlA) }
let a: ShoeGaze = ShoeGaze(engine: engineA, inputSource: .liveInput(channel: 1))
let board: PedalBoard = try a.addBoard()
try a.appendPedal(.overdrive, to: board)
try a.finalizeBoard(board)
#expect(RigStore.save(a))
// Restore into a fresh engine built with the default single input channel.
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05, numOutputChannels: 2, numInputChannels: 1, numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: urlB) }
let b: ShoeGaze = ShoeGaze(engine: engineB)
#expect(RigStore.restore(into: b))
#expect(b.engine.numInputChannels == 2, "restore must reapply the rig's saved input count")
#expect(b.inputSource == .liveInput(channel: 1),
"the saved live-input channel must survive because the layout was restored first")
}
@Test func restoreReturnsFalseWhenNoAutosave() throws {
let autosave: URL = try isolateAutosave()
defer {
@@ -0,0 +1,93 @@
# 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:
- The app **re-asserts it muted every time the engine is (user-)started**, so a fresh start
is silent until the player un-mutes — kills accidental ruckus. (The library-level default is
*audible*; muting is the app's Start-time policy, so headless / offline library use isn't
forced silent.)
- 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 **hard** gain `(inputMute − 1)·−1` — an un-lagged kill switch. (A lagged
gate never settles to exactly zero on its first blocks and leaks a faint transient at the very
moment the mute is meant to keep things quiet; a kill-switch mute is expected to be abrupt.)
### ShoeGaze
- `public private(set) var inputMuted: Bool = false` (app mutes on Start)
- `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)` **before**
`engine.start()`, while the engine is stopped — so the gain is seeded (`previousOutputValue`
primed to the target, no ramp) and the very first render block is already muted. Asserting it
after start would leave the opening blocks unmuted. Transient stop/start-around-rebuild paths
(`applyInputSource`, `performClear`) call `engine.start()` directly and are unaffected — they
preserve the current mute state. Nodes are also primed at creation in `addBoard()` (before the
node is spliced into the graph), so a board added while muted has no first-block leak either.
### 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 + input via the rig (iCloud), not UserDefaults
The rig snapshot (`ShoeGazeState`) **already** persists `inputSource`, `numInputChannels`,
and `numOutputChannels`, and the autosave envelope + rig library (iCloud) already carry
them. Two problems remained:
1. `loadRig(from:)` deliberately does **not** apply the saved channel layout (forcing it on
every mid-session load would fight the global engine config / the iOS live-input rebuild).
So at **launch**, the engine kept the app default (1 in / 2 out); a saved live-input
channel `>=` that count failed validation and fell back to the test loop — the "In
doesn't persist" bug.
2. A **second, competing** persistence path (`ShoeGazeBuilderView`'s UserDefaults
`ShoeGaze.inputSelection`, plus the iOS model's copy) fought the rig's own `inputSource`.
Fix — make the rig the single source of truth:
- **Launch applies the saved layout.** `RigStore.restore` calls
`applyChannelLayout(from: state)` **before** `loadRig`, while the engine is stopped, so the
input-channel validation runs against the restored count. A launch restore is exactly the
place this is wanted (unlike a mid-session load), so the general `loadRig` policy is
unchanged.
- **Input changes autosave.** `applyInputSource` / the engine-config `onConfigApplied` call
`autosave()`, so a changed input or I/O layout is captured into the rig immediately.
- **No UserDefaults path.** The `ShoeGaze.inputSelection` key and its read/write sites (builder
view + iOS model) are removed; the engine channel counts are never persisted to UserDefaults at
all. The app targets build the engine at the default layout; `RigStore.restore` supplies the
rig's saved layout.
- **Fresh-launch default.** When there is no autosaved rig, the seed paths
(`AppDelegate.seedInitialBoard` / iOS `seedFallbackBoard`) set `inputSource = .liveInput(0)`
when the engine has an input channel, so a first launch listens to the instrument rather
than the test loop. A restored rig keeps its own saved input. The builder view's on-appear
hook now only requests mic access for a restored live-input selection (falling back to the
test loop on denial).
## 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`.