Compare commits
18 Commits
v2.1.0
...
ed3283f645
| Author | SHA1 | Date | |
|---|---|---|---|
| ed3283f645 | |||
| 8983e8829e | |||
| e697789bd7 | |||
| 09fa4e8d4b | |||
| 37777826d1 | |||
| a1a7683bc9 | |||
| 3d67c7b450 | |||
| 551b650d45 | |||
| 7720fbec7b | |||
| 3228614071 | |||
| e207728a12 | |||
| e36074e9d3 | |||
| b29c8848ef | |||
| be0e3d118b | |||
| 5542ee5b5a | |||
| b0294612f8 | |||
| cc3a986cde | |||
| 5987ec7b78 |
@@ -4,6 +4,56 @@ 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.3] — 2026-07-13
|
||||
|
||||
A tuner fix. Engaging the chromatic tuner could crackle or pop through the output —
|
||||
even with "Mute while tuning" on — until a steady note was detected.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Tuner no longer leaks into the audio output.** The tuner's pitch-detection stage
|
||||
was mistakenly written to an audio output bus instead of its internal analysis bus,
|
||||
so the tracked frequency was summed onto an output channel — bypassing the rig mute
|
||||
and crackling while the pitch was still unstable (it stopped once a note locked). The
|
||||
tuner now writes only to its analysis bus; engaging it leaves the output untouched.
|
||||
|
||||
## [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
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1600;
|
||||
LastUpgradeCheck = 2620;
|
||||
LastUpgradeCheck = 2660;
|
||||
TargetAttributes = {
|
||||
C3B100000000000000000014 = {
|
||||
CreatedOnToolsVersion = 16.0;
|
||||
@@ -163,10 +163,9 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 14;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = ShoeGazeBuilder/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||
@@ -176,7 +175,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 2.0.0;
|
||||
MARKETING_VERSION = 2.1.6;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -194,9 +193,8 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 14;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = ShoeGazeBuilder/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||
@@ -206,7 +204,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 2.0.0;
|
||||
MARKETING_VERSION = 2.1.6;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -249,6 +247,7 @@
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -311,6 +310,7 @@
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = 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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "2620"
|
||||
LastUpgradeVersion = "2660"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 345 KiB After Width: | Height: | Size: 200 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 345 KiB After Width: | Height: | Size: 200 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 643 KiB |
@@ -28,9 +28,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.0.0</string>
|
||||
<string>${MARKETING_VERSION}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>7</string>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.music</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
C3C10000000000000000000D /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001C /* LyrebirdUI */; };
|
||||
C3C10000000000000000001D /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001E /* Lyrebird */; };
|
||||
C3C100000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3C100000000000000000030 /* Assets.xcassets */; };
|
||||
C3C1000000000000000000B1 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C1000000000000000000B0 /* SplashView.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -22,6 +23,7 @@
|
||||
C3C100000000000000000007 /* ShoeGazeBuilderiOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeBuilderiOSApp.swift; sourceTree = "<group>"; };
|
||||
C3C100000000000000000008 /* ShoeGazeBuilderiOSAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeBuilderiOSAppModel.swift; sourceTree = "<group>"; };
|
||||
C3C100000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
C3C1000000000000000000B0 /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -60,6 +62,7 @@
|
||||
children = (
|
||||
C3C100000000000000000007 /* ShoeGazeBuilderiOSApp.swift */,
|
||||
C3C100000000000000000008 /* ShoeGazeBuilderiOSAppModel.swift */,
|
||||
C3C1000000000000000000B0 /* SplashView.swift */,
|
||||
C3C100000000000000000030 /* Assets.xcassets */,
|
||||
C3C100000000000000000006 /* Info.plist */,
|
||||
);
|
||||
@@ -100,7 +103,7 @@
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1600;
|
||||
LastUpgradeCheck = 2620;
|
||||
LastUpgradeCheck = 2660;
|
||||
TargetAttributes = {
|
||||
C3C100000000000000000011 = {
|
||||
CreatedOnToolsVersion = 16.0;
|
||||
@@ -147,6 +150,7 @@
|
||||
files = (
|
||||
C3C100000000000000000009 /* ShoeGazeBuilderiOSApp.swift in Sources */,
|
||||
C3C10000000000000000000A /* ShoeGazeBuilderiOSAppModel.swift in Sources */,
|
||||
C3C1000000000000000000B1 /* SplashView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -163,7 +167,6 @@
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 7;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||
@@ -192,7 +195,6 @@
|
||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 7;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||
@@ -246,6 +248,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
@@ -308,6 +311,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = 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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "2620"
|
||||
LastUpgradeVersion = "2660"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
|
Before Width: | Height: | Size: 402 KiB After Width: | Height: | Size: 643 KiB |
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : { "red" : "0.080", "green" : "0.070", "blue" : "0.060", "alpha" : "1.000" }
|
||||
}
|
||||
}
|
||||
],
|
||||
"info" : { "author" : "xcode", "version" : 1 }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"images" : [
|
||||
{ "idiom" : "universal", "filename" : "splashlogo.png", "scale" : "1x" },
|
||||
{ "idiom" : "universal", "filename" : "splashlogo@2x.png", "scale" : "2x" },
|
||||
{ "idiom" : "universal", "filename" : "splashlogo@3x.png", "scale" : "3x" }
|
||||
],
|
||||
"info" : { "author" : "xcode", "version" : 1 }
|
||||
}
|
||||
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 420 KiB |
@@ -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>
|
||||
@@ -55,7 +59,10 @@
|
||||
<false/>
|
||||
</dict>
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<dict>
|
||||
<key>UIColorName</key>
|
||||
<string>LaunchBackground</string>
|
||||
</dict>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
|
||||
@@ -20,21 +20,30 @@ import LyrebirdShoeGazeUI
|
||||
struct ShoeGazeBuilderiOSApp: App {
|
||||
|
||||
@State private var model: ShoeGazeBuilderiOSAppModel = ShoeGazeBuilderiOSAppModel()
|
||||
@State private var showSplash: Bool = true
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
library: model.library,
|
||||
hardwareSampleRate: { model.hardwareSampleRate },
|
||||
onEnableLiveInput: { model.enableLiveInput() },
|
||||
midi: model.midi
|
||||
)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.task { await model.startLibrary() }
|
||||
.onDisappear { model.stop() }
|
||||
.onOpenURL { url in model.importDocument(at: url) }
|
||||
ZStack {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
library: model.library,
|
||||
hardwareSampleRate: { model.hardwareSampleRate },
|
||||
onEnableLiveInput: { model.enableLiveInput() },
|
||||
midi: model.midi
|
||||
)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.task { await model.startLibrary() }
|
||||
.onDisappear { model.stop() }
|
||||
.onOpenURL { url in model.importDocument(at: url) }
|
||||
|
||||
if showSplash {
|
||||
SplashView(isActive: $showSplash)
|
||||
.transition(.opacity)
|
||||
.zIndex(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: scenePhase) { _, phase in
|
||||
// Persist the rig whenever the app leaves the foreground.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
// SplashView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// Animated launch splash shown over the app on cold start.
|
||||
///
|
||||
/// The native launch screen (`UILaunchScreen` → `LaunchBackground`) paints an instant dark
|
||||
/// backdrop with no visible jump; this view then fades and scales the ShoeGaze pedal logo in,
|
||||
/// holds briefly, and fades the whole overlay away to reveal ``ShoeGazeBuilderView``. Colors match
|
||||
/// the app background so the hand-off is seamless. Respects Reduce Motion by skipping the scale.
|
||||
struct SplashView: View {
|
||||
|
||||
/// Background matching the builder's app background (`0.08, 0.07, 0.06`).
|
||||
private static let backgroundColor: Color = Color(red: 0.08, green: 0.07, blue: 0.06)
|
||||
|
||||
private static let logoSize: CGFloat = 200
|
||||
private static let logoCornerRadius: CGFloat = 44
|
||||
private static let logoStartScale: CGFloat = 0.86
|
||||
private static let wordmarkKerning: CGFloat = 4
|
||||
|
||||
private static let logoFadeInDuration: Double = 0.55
|
||||
private static let wordmarkFadeInDelay: Double = 0.30
|
||||
private static let wordmarkFadeInDuration: Double = 0.45
|
||||
private static let holdDuration: Double = 0.85
|
||||
private static let fadeOutDuration: Double = 0.45
|
||||
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
|
||||
/// Set false to fade the overlay out; parent removes it when the fade completes.
|
||||
@Binding var isActive: Bool
|
||||
|
||||
@State private var logoOpacity: Double = 0
|
||||
@State private var logoScale: CGFloat = SplashView.logoStartScale
|
||||
@State private var wordmarkOpacity: Double = 0
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
SplashView.backgroundColor
|
||||
.ignoresSafeArea()
|
||||
|
||||
VStack(spacing: 22) {
|
||||
Image("SplashLogo")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: SplashView.logoSize, height: SplashView.logoSize)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SplashView.logoCornerRadius,
|
||||
style: .continuous))
|
||||
.opacity(logoOpacity)
|
||||
.scaleEffect(logoScale)
|
||||
|
||||
Text("ShoeGaze")
|
||||
.font(.system(size: 34, weight: .semibold, design: .rounded))
|
||||
.kerning(SplashView.wordmarkKerning)
|
||||
.foregroundStyle(.white)
|
||||
.opacity(wordmarkOpacity)
|
||||
}
|
||||
}
|
||||
.onAppear { runSequence() }
|
||||
}
|
||||
|
||||
private func runSequence() {
|
||||
withAnimation(.easeOut(duration: SplashView.logoFadeInDuration)) {
|
||||
logoOpacity = 1
|
||||
if !reduceMotion { logoScale = 1 }
|
||||
}
|
||||
withAnimation(.easeOut(duration: SplashView.wordmarkFadeInDuration)
|
||||
.delay(SplashView.wordmarkFadeInDelay)) {
|
||||
wordmarkOpacity = 1
|
||||
}
|
||||
|
||||
let holdUntil: Double = SplashView.logoFadeInDuration + SplashView.holdDuration
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + holdUntil) {
|
||||
withAnimation(.easeIn(duration: SplashView.fadeOutDuration)) {
|
||||
isActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "8bbfcc5441e68d57cefd08aed960cbac3875af1e0f8b1d2d3fbdd4dadc0ac18c",
|
||||
"originHash" : "9365abc9e3bf41483a03dca1c6be0421a5ca41bff1a9db33c8ddc62b2de04ef1",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "linenoise-swift",
|
||||
@@ -15,8 +15,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||
"state" : {
|
||||
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
|
||||
"version" : "1.2.3"
|
||||
"revision" : "d6875da2cb6628c4274454dd55a632dd76212759",
|
||||
"version" : "1.6.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ let package = Package(
|
||||
.library(name: "LyrebirdShoeGazeUI", targets: ["LyrebirdShoeGazeUI"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.2.3"),
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.6.4"),
|
||||
],
|
||||
targets: [
|
||||
// The core target depends on LyrebirdUI as well as the synthesis core:
|
||||
|
||||
@@ -1,4 +1,38 @@
|
||||
# Releases
|
||||
## ShoeGaze 2.1.3
|
||||
|
||||
A tuner fix. Engaging the chromatic tuner could crackle or pop through the output — even
|
||||
with "Mute while tuning" on — until you played a steady note.
|
||||
|
||||
### Fixed
|
||||
- **Tuner no longer leaks into the output.** The pitch-detection stage was written to an
|
||||
audio output bus instead of its internal analysis bus, so the tracked frequency was
|
||||
summed onto an output channel — bypassing the rig mute and crackling while the pitch was
|
||||
unstable (it stopped once a note locked). The tuner now writes only to its analysis bus.
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "39c6a5f1535f779ef8a83b5ea2ab6f965ee3b28ad8419b94679e422a92f75603",
|
||||
"originHash" : "6963980dd14bc118dfae577e57517f2776cb0d010d7b4ae798bdb57e4f0d2cb7",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "linenoise-swift",
|
||||
@@ -15,8 +15,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||
"state" : {
|
||||
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
|
||||
"version" : "1.2.3"
|
||||
"revision" : "d6875da2cb6628c4274454dd55a632dd76212759",
|
||||
"version" : "1.6.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
// OversampledRingModulator.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import Darwin
|
||||
|
||||
/// Shared zero-fill fallback block, allocated once at module load. Returned when an upstream
|
||||
/// input yields no channel for a `_computeSamples` call, so the RT path never allocates.
|
||||
private let oversampledRingModZeroBlock: [Double] = makeSampleBuffer()
|
||||
|
||||
/// Ring modulator (`input × sine carrier`) evaluated at 2× or 4× the engine sample rate.
|
||||
///
|
||||
/// A ring modulator's product produces sum-and-difference sidebands at `f_in ± f_carrier`. The
|
||||
/// sum sideband can land above the engine Nyquist and fold back as an inharmonic alias —
|
||||
/// worst with a high carrier and bright input. Evaluating the multiply at an oversampled rate
|
||||
/// (the input upsampled through a halfband FIR, the carrier generated directly at the
|
||||
/// oversampled rate) pushes the sum term below the upsampled Nyquist, then the matching
|
||||
/// downsampler filters it out before returning to the engine rate.
|
||||
///
|
||||
/// Output is mono (channel 0 of the input is used).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - input: Signal to modulate.
|
||||
/// - freq: Carrier frequency in Hz. Read once per block. Defaults to `220.0`.
|
||||
/// - oversample: Oversampling factor — `2` or `4`. Defaults to `2`.
|
||||
public final class OversampledRingModulator: GeneratorBase, AudioGenerator {
|
||||
|
||||
/// Resolved input signal (classified once at `init`, never on the RT thread).
|
||||
private let inputSource: any ValidGeneratorInput
|
||||
|
||||
/// Resolved carrier-frequency control. Read once per block.
|
||||
private let freqInput: any ValidGeneratorInput
|
||||
|
||||
/// Oversampling factor — `2` or `4`, fixed at init.
|
||||
private let oversampleFactor: Int
|
||||
|
||||
/// Carrier phase in radians, advanced at the oversampled rate and wrapped to `[0, 2π)`.
|
||||
private var phase: Double = 0.0
|
||||
|
||||
/// 2× halfband oversampling state (used when `oversampleFactor == 2`).
|
||||
private var upsampler2x: HalfbandUpsampler2x
|
||||
private var downsampler2x: HalfbandDownsampler2x
|
||||
|
||||
/// 4× halfband oversampling state (used when `oversampleFactor == 4`).
|
||||
private var upsampler4x: HalfbandUpsampler4x
|
||||
private var downsampler4x: HalfbandDownsampler4x
|
||||
|
||||
private let twoPi: Double = 2.0 * Double.pi
|
||||
|
||||
/// Creates an oversampled ring modulator.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - input: Signal to modulate.
|
||||
/// - freq: Carrier frequency in Hz. Read once per block. Defaults to `220.0`.
|
||||
/// - oversample: Oversampling factor — `2` or `4`. Defaults to `2`.
|
||||
public init(
|
||||
_ input: any ValidGeneratorInput,
|
||||
freq: any ValidGeneratorInput = 220.0,
|
||||
oversample: Int = 2
|
||||
) {
|
||||
precondition(
|
||||
oversample == 2 || oversample == 4,
|
||||
"OversampledRingModulator: oversample must be 2 or 4"
|
||||
)
|
||||
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||
let resolvedFreq: any ValidGeneratorInput = freq._resolvedInput()
|
||||
inputSource = resolvedInput
|
||||
freqInput = resolvedFreq
|
||||
oversampleFactor = oversample
|
||||
upsampler2x = HalfbandUpsampler2x()
|
||||
downsampler2x = HalfbandDownsampler2x()
|
||||
upsampler4x = HalfbandUpsampler4x()
|
||||
downsampler4x = HalfbandDownsampler4x()
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func _computeSamples(
|
||||
graph: SynthGraph,
|
||||
count: Int
|
||||
) -> [[Double]] {
|
||||
_checkCount(count)
|
||||
guard count > 0 else { return _result }
|
||||
|
||||
let input: [Double] = inputSource.calculatedSamples(graph: graph, count: count).first
|
||||
?? oversampledRingModZeroBlock
|
||||
let sr: Double = graph.engine.sampleRate
|
||||
// A degenerate sample rate would make phaseInc NaN/Inf and latch NaN into the
|
||||
// persisted phase; zero-fill and bail, matching MoogLadder's guard.
|
||||
guard sr >= 1.0 else {
|
||||
_result[0].withUnsafeMutableBufferPointer { (dst: inout UnsafeMutableBufferPointer<Double>) in
|
||||
guard let dstP: UnsafeMutablePointer<Double> = dst.baseAddress else { return }
|
||||
for i: Int in 0..<count { dstP[i] = 0 }
|
||||
}
|
||||
return _result
|
||||
}
|
||||
let freq: Double = freqInput.floatValue(graph: graph)
|
||||
let inCount: Int = input.count
|
||||
let useFourX: Bool = oversampleFactor == 4
|
||||
// Phase increment per oversampled sample.
|
||||
let factor: Double = useFourX ? 4.0 : 2.0
|
||||
let phaseInc: Double = twoPi * freq / (sr * factor)
|
||||
|
||||
var localPhase: Double = phase
|
||||
_result[0].withUnsafeMutableBufferPointer { (dst: inout UnsafeMutableBufferPointer<Double>) in
|
||||
guard let dstP: UnsafeMutablePointer<Double> = dst.baseAddress else { return }
|
||||
if useFourX {
|
||||
for i: Int in 0..<count {
|
||||
let x: Double = i < inCount ? input[i] : 0
|
||||
let (a, b, c, d) = upsampler4x.process(x)
|
||||
let ya: Double = a * sin(localPhase); localPhase += phaseInc
|
||||
let yb: Double = b * sin(localPhase); localPhase += phaseInc
|
||||
let yc: Double = c * sin(localPhase); localPhase += phaseInc
|
||||
let yd: Double = d * sin(localPhase); localPhase += phaseInc
|
||||
// Wrap both directions — a negative carrier frequency drives phaseInc
|
||||
// negative, so an upward-only wrap would let the phase grow unbounded.
|
||||
if localPhase >= twoPi || localPhase < 0 {
|
||||
localPhase = localPhase.truncatingRemainder(dividingBy: twoPi)
|
||||
if localPhase < 0 { localPhase += twoPi }
|
||||
}
|
||||
dstP[i] = downsampler4x.process(ya, yb, yc, yd)
|
||||
}
|
||||
} else {
|
||||
for i: Int in 0..<count {
|
||||
let x: Double = i < inCount ? input[i] : 0
|
||||
let (a, b) = upsampler2x.process(x)
|
||||
let ya: Double = a * sin(localPhase); localPhase += phaseInc
|
||||
let yb: Double = b * sin(localPhase); localPhase += phaseInc
|
||||
// Wrap both directions (see 4× branch).
|
||||
if localPhase >= twoPi || localPhase < 0 {
|
||||
localPhase = localPhase.truncatingRemainder(dividingBy: twoPi)
|
||||
if localPhase < 0 { localPhase += twoPi }
|
||||
}
|
||||
dstP[i] = downsampler2x.process(ya, yb)
|
||||
}
|
||||
}
|
||||
}
|
||||
phase = localPhase
|
||||
return _result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// OversampledSaturator.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
|
||||
/// Shared zero-fill fallback block, allocated once at module load. Returned when an upstream
|
||||
/// input yields no channel for a `_computeSamples` call, so the RT path never allocates.
|
||||
private let oversampledSaturatorZeroBlock: [Double] = makeSampleBuffer()
|
||||
|
||||
/// A waveshaping saturator that evaluates its nonlinearity at 2× or 4× the engine sample
|
||||
/// rate to keep the harmonics it generates from folding back into the audible band as
|
||||
/// aliasing.
|
||||
///
|
||||
/// A hard or steep nonlinearity (`tanh` driven hard, a hard clipper) produces harmonics well
|
||||
/// above the engine Nyquist. Evaluated at the base rate those harmonics alias — an
|
||||
/// inharmonic, buzzy "crackle" that gets worse the louder and brighter the input and the
|
||||
/// harder the drive. This generator upsamples the input, applies the ``SaturationCurve``
|
||||
/// per oversampled sample, then downsamples with the matching halfband FIR, so the aliased
|
||||
/// content is filtered out before returning to the engine rate.
|
||||
///
|
||||
/// Linear stages (DC-block high-pass, tone low-pass, output trim) do **not** alias and should
|
||||
/// stay as ordinary graph nodes around this one — only the nonlinearity needs oversampling.
|
||||
///
|
||||
/// Output is mono (channel 0 of the input is used).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - input: Signal to saturate.
|
||||
/// - drive: Drive amount fed to the curve. Clamped to a small positive floor. Defaults to `1.0`.
|
||||
/// - curve: The ``SaturationCurve`` to apply per oversampled sample.
|
||||
/// - oversample: Oversampling factor — `2` or `4`. Use `4` for hard-clipping curves whose
|
||||
/// harmonics extend furthest; `2` is enough for `tanh`-family soft saturation. Defaults to `2`.
|
||||
public final class OversampledSaturator: GeneratorBase, AudioGenerator {
|
||||
|
||||
/// Resolved input signal (classified once at `init`, never on the RT thread).
|
||||
private let inputSource: any ValidGeneratorInput
|
||||
|
||||
/// Resolved drive control. Read once per block.
|
||||
private let driveInput: any ValidGeneratorInput
|
||||
|
||||
/// The waveshaping curve applied per oversampled sample.
|
||||
private let curve: SaturationCurve
|
||||
|
||||
/// Oversampling factor — `2` or `4`, fixed at init.
|
||||
private let oversampleFactor: Int
|
||||
|
||||
/// Lower bound on drive so `softClipNormalized`'s `tanh(drive)` denominator is never zero.
|
||||
private let minDrive: Double = 1.0e-4
|
||||
|
||||
/// 2× halfband oversampling state (used when `oversampleFactor == 2`).
|
||||
private var upsampler2x: HalfbandUpsampler2x
|
||||
private var downsampler2x: HalfbandDownsampler2x
|
||||
|
||||
/// 4× halfband oversampling state (used when `oversampleFactor == 4`).
|
||||
private var upsampler4x: HalfbandUpsampler4x
|
||||
private var downsampler4x: HalfbandDownsampler4x
|
||||
|
||||
/// Creates an oversampled saturator.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - input: Signal to saturate.
|
||||
/// - drive: Drive amount fed to the curve. Clamped to a small positive floor. Defaults to `1.0`.
|
||||
/// - curve: The ``SaturationCurve`` to apply per oversampled sample.
|
||||
/// - oversample: Oversampling factor — `2` or `4`. Defaults to `2`.
|
||||
public init(
|
||||
_ input: any ValidGeneratorInput,
|
||||
drive: any ValidGeneratorInput = 1.0,
|
||||
curve: SaturationCurve,
|
||||
oversample: Int = 2
|
||||
) {
|
||||
precondition(
|
||||
oversample == 2 || oversample == 4,
|
||||
"OversampledSaturator: oversample must be 2 or 4"
|
||||
)
|
||||
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||
let resolvedDrive: any ValidGeneratorInput = drive._resolvedInput()
|
||||
inputSource = resolvedInput
|
||||
driveInput = resolvedDrive
|
||||
self.curve = curve
|
||||
oversampleFactor = oversample
|
||||
upsampler2x = HalfbandUpsampler2x()
|
||||
downsampler2x = HalfbandDownsampler2x()
|
||||
upsampler4x = HalfbandUpsampler4x()
|
||||
downsampler4x = HalfbandDownsampler4x()
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func _computeSamples(
|
||||
graph: SynthGraph,
|
||||
count: Int
|
||||
) -> [[Double]] {
|
||||
_checkCount(count)
|
||||
guard count > 0 else { return _result }
|
||||
|
||||
let input: [Double] = inputSource.calculatedSamples(graph: graph, count: count).first
|
||||
?? oversampledSaturatorZeroBlock
|
||||
let driveRaw: Double = driveInput.floatValue(graph: graph)
|
||||
let drive: Double = Swift.max(minDrive, driveRaw)
|
||||
let inCount: Int = input.count
|
||||
let useFourX: Bool = oversampleFactor == 4
|
||||
|
||||
_result[0].withUnsafeMutableBufferPointer { (dst: inout UnsafeMutableBufferPointer<Double>) in
|
||||
guard let dstP: UnsafeMutablePointer<Double> = dst.baseAddress else { return }
|
||||
if useFourX {
|
||||
for i: Int in 0..<count {
|
||||
let x: Double = i < inCount ? input[i] : 0
|
||||
let (a, b, c, d) = upsampler4x.process(x)
|
||||
dstP[i] = downsampler4x.process(
|
||||
curve.apply(a, drive: drive),
|
||||
curve.apply(b, drive: drive),
|
||||
curve.apply(c, drive: drive),
|
||||
curve.apply(d, drive: drive)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
for i: Int in 0..<count {
|
||||
let x: Double = i < inCount ? input[i] : 0
|
||||
let (a, b) = upsampler2x.process(x)
|
||||
dstP[i] = downsampler2x.process(
|
||||
curve.apply(a, drive: drive),
|
||||
curve.apply(b, drive: drive)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// SaturationCurve.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Darwin
|
||||
|
||||
/// The waveshaping curve applied per (oversampled) sample by ``OversampledSaturator``.
|
||||
///
|
||||
/// Each case reproduces the nonlinearity a specific drive pedal used to build inline from
|
||||
/// stock generators, so moving that pedal onto the oversampled path is voicing-preserving:
|
||||
///
|
||||
/// - `tanhPreGain` — `tanh(drive · x)`. Symmetric soft saturation with the drive applied
|
||||
/// *before* the `tanh` (the fuzz voicing: hard pre-gain squares the wave off).
|
||||
/// - `softClipNormalized` — `tanh(drive · x) / tanh(drive)`. The same curve normalised so a
|
||||
/// unity-drive signal passes near-linearly (the overdrive voicing).
|
||||
/// - `tanhPostGainHardClip(low:high:)` — `clip(tanh(x) · drive, low, high)`. A gentle `tanh`
|
||||
/// stage, post-gained by drive into a hard clipper (the distortion voicing). The hard clip
|
||||
/// is the dominant harmonic source and the reason this curve wants the highest oversampling
|
||||
/// factor.
|
||||
public enum SaturationCurve: Sendable {
|
||||
case tanhPreGain
|
||||
case softClipNormalized
|
||||
case tanhPostGainHardClip(low: Double, high: Double)
|
||||
|
||||
/// Applies the curve to a single sample.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - x: Input sample (already at the oversampled rate).
|
||||
/// - drive: Drive amount. The caller clamps this to a small positive floor so
|
||||
/// `softClipNormalized`'s `tanh(drive)` denominator is never zero.
|
||||
/// - Returns: The shaped sample.
|
||||
@inline(__always)
|
||||
func apply(_ x: Double, drive: Double) -> Double {
|
||||
switch self {
|
||||
case .tanhPreGain:
|
||||
return tanh(drive * x)
|
||||
case .softClipNormalized:
|
||||
return tanh(drive * x) / tanh(drive)
|
||||
case .tanhPostGainHardClip(let low, let high):
|
||||
let shaped: Double = tanh(x) * drive
|
||||
return Swift.min(high, Swift.max(low, shaped))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -32,6 +32,12 @@ import LyrebirdUI
|
||||
/// compressed. Range `[-40, 0]` dB. Defaults to `-12.0`.
|
||||
/// - ratio: Compression ratio `≥ 1.0`. `1.0` = bypass, `4.0` = 4:1 compression.
|
||||
/// Range `[1, 20]`. Defaults to `4.0`.
|
||||
///
|
||||
/// A feed-forward compressor can overshoot on fast transients (its attack is non-zero),
|
||||
/// so a hot input plus makeup gain can push peaks past full scale and clip the output.
|
||||
/// The **Safety** switch inserts a brick-wall `LookAheadLimiter` after the compressor to
|
||||
/// catch those peaks; it is off by default (leave adding a limiter to the user) and adds
|
||||
/// a short look-ahead output delay when engaged.
|
||||
public final class CompressorPedal: Pedal {
|
||||
|
||||
/// One-line description shown in the picker and info panel.
|
||||
@@ -50,6 +56,10 @@ public final class CompressorPedal: Pedal {
|
||||
/// Compression ratio. Range [1, 20].
|
||||
@UIParam public var ratio: Double = 4.0
|
||||
|
||||
/// Safety limiter engage state. `0` = off (compressor may overshoot), `1` = on
|
||||
/// (brick-wall look-ahead limiter catches transient peaks).
|
||||
@UIParam public var safetyLimiter: Double = 0.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Default wet/dry blend — fully wet; the compressor is inserted in-line.
|
||||
@@ -71,6 +81,20 @@ public final class CompressorPedal: Pedal {
|
||||
/// Makeup gain in dB applied after compression to restore perceived loudness.
|
||||
private let makeupGainDB: Double = 4.0
|
||||
|
||||
/// Safety-limiter peak ceiling (linear amplitude), just below full scale.
|
||||
private let safetyCeiling: Double = 0.98
|
||||
|
||||
/// Safety-limiter look-ahead / output delay in seconds. Short enough to catch
|
||||
/// transients without smearing attack; only in circuit when Safety is engaged.
|
||||
private let safetyLookAheadTime: Double = 0.005
|
||||
|
||||
/// Safety-limiter gain-release time in seconds.
|
||||
private let safetyReleaseTime: Double = 0.05
|
||||
|
||||
/// Safety switch position values.
|
||||
private let safetyOffValue: Double = 0.0
|
||||
private let safetyOnValue: Double = 1.0
|
||||
|
||||
// MARK: - UI knobs
|
||||
|
||||
/// Input-gain knob range in dB.
|
||||
@@ -90,6 +114,19 @@ public final class CompressorPedal: Pedal {
|
||||
]
|
||||
}
|
||||
|
||||
public override var effectSwitches: [PedalSwitch] {
|
||||
[
|
||||
PedalSwitch(
|
||||
label: "Safety",
|
||||
node: $safetyLimiter,
|
||||
options: [
|
||||
PedalSwitch.Option(title: "Off", value: safetyOffValue),
|
||||
PedalSwitch.Option(title: "On", value: safetyOnValue),
|
||||
]
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a compressor pedal.
|
||||
@@ -121,7 +158,7 @@ public final class CompressorPedal: Pedal {
|
||||
// Convert the input-gain dB to a linear multiplier (10^(dB/20)) and apply before compression.
|
||||
let inputGainLinear: Exp.Audio = Exp.Audio($inputGain * dbToLinExpScale)
|
||||
let boosted: any ValidGeneratorInput = dry * inputGainLinear
|
||||
return Compressor.Audio(
|
||||
let compressed: Compressor.Audio = Compressor.Audio(
|
||||
in: boosted,
|
||||
threshold: $threshold,
|
||||
ratio: $ratio,
|
||||
@@ -130,5 +167,18 @@ public final class CompressorPedal: Pedal {
|
||||
kneeWidth: kneeWidth,
|
||||
makeupGain: makeupGainDB
|
||||
)
|
||||
// Brick-wall safety limiter after the compressor. Both branches are always built;
|
||||
// `Select` picks per the Safety switch (0 = compressor only, 1 = limited).
|
||||
let limited: LookAheadLimiter = LookAheadLimiter(
|
||||
in: compressed,
|
||||
maxAmplitude: safetyCeiling,
|
||||
lookAheadTime: safetyLookAheadTime,
|
||||
releaseTime: safetyReleaseTime,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
return Select.Audio(
|
||||
which: $safetyLimiter,
|
||||
inputs: [compressed, limited]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ import LyrebirdUI
|
||||
|
||||
/// Mid-gain distortion — more saturated than `OverdrivePedal`, more controlled than `FuzzPedal`.
|
||||
///
|
||||
/// A DC-blocking high-pass feeds a `tanh` soft-clipper driven hard by the `Drive` knob; a
|
||||
/// post-clip low-pass `Tone` control tames the harmonics, and a final hard clip guarantees the
|
||||
/// output stays bounded.
|
||||
/// A DC-blocking high-pass feeds a `tanh` stage that is post-gained by the `Drive` knob into a
|
||||
/// hard clipper — both evaluated at 4× oversampling so the clipper's harmonics don't alias. A
|
||||
/// post-clip low-pass `Tone` control tames the harmonics, and a final hard clip re-bounds the
|
||||
/// output (the tone low-pass can ring slightly past the ceiling on transients).
|
||||
///
|
||||
/// ## Knobs
|
||||
/// - `drive`: Pre-clip gain into the `tanh` stage. Range `[1, 50]`.
|
||||
@@ -87,12 +88,24 @@ public final class DistortionPedal: Pedal {
|
||||
freq: dcBlockFreq,
|
||||
q: filterQ
|
||||
)
|
||||
let driven: Tanh.Audio = Tanh.Audio(dcBlocked, mul: $drive)
|
||||
// tanh soft stage → post-gain by drive → hard clip, all evaluated at 4× so the hard
|
||||
// clipper's harmonics settle above the upsampled Nyquist instead of aliasing back.
|
||||
// The tone low-pass now follows the clip (standard clip→tone order), which also
|
||||
// filters any residual high-band content the downsampler leaves.
|
||||
let clipped: OversampledSaturator = OversampledSaturator(
|
||||
dcBlocked,
|
||||
drive: $drive,
|
||||
curve: .tanhPostGainHardClip(low: clipLow, high: clipHigh),
|
||||
oversample: 4
|
||||
)
|
||||
let toned: RBJLowPass.Audio = RBJLowPass.Audio(
|
||||
input: driven,
|
||||
input: clipped,
|
||||
freq: $tone,
|
||||
q: filterQ
|
||||
)
|
||||
// Final hard clip re-establishes the strict output bound: the tone low-pass is linear
|
||||
// and band-limited, so it can overshoot the ceiling slightly on transients, but
|
||||
// clipping its (already band-limited) output adds negligible new aliasing.
|
||||
return Clip.Audio(toned, lo: clipLow, hi: clipHigh)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,11 +105,17 @@ public final class FuzzPedal: Pedal {
|
||||
/// - Returns: Fuzzed and tone-shaped mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
// Pre-gain the signal hard, then saturate. `tanh` squares the waveform off as the
|
||||
// drive rises while keeping the level bounded — the hallmark of a fuzz.
|
||||
let driven: any ValidGeneratorInput = dry * $fuzz
|
||||
let saturated: Tanh.Audio = Tanh.Audio(driven, mul: outputTrim)
|
||||
// drive rises while keeping the level bounded — the hallmark of a fuzz. Evaluated at
|
||||
// 2× so the high harmonics the hard pre-gain generates don't fold back as aliasing.
|
||||
let saturated: OversampledSaturator = OversampledSaturator(
|
||||
dry,
|
||||
drive: $fuzz,
|
||||
curve: .tanhPreGain,
|
||||
oversample: 2
|
||||
)
|
||||
let trimmed: any ValidGeneratorInput = saturated * outputTrim
|
||||
return RBJLowPass.Audio(
|
||||
input: saturated,
|
||||
input: trimmed,
|
||||
freq: $tone,
|
||||
q: toneQ
|
||||
)
|
||||
|
||||
@@ -29,6 +29,9 @@ import LyrebirdUI
|
||||
/// drive harder into the limiter. Range `[1, 12]`. Defaults to `1.0`.
|
||||
/// - ceiling: Output peak ceiling as a linear amplitude in `[0, 1]`. The limited output
|
||||
/// never exceeds this absolute value. Range `[0.1, 1.0]`. Defaults to `0.95`.
|
||||
/// - release: Gain-release time in seconds. Too short a release modulates the gain
|
||||
/// within a waveform cycle and distorts low notes; longer is cleaner but lets the
|
||||
/// level swell back more slowly. Range `[0.01, 0.5]`. Defaults to `0.05`.
|
||||
public final class LimiterPedal: Pedal {
|
||||
|
||||
/// One-line description shown in the picker and info panel.
|
||||
@@ -44,6 +47,9 @@ public final class LimiterPedal: Pedal {
|
||||
/// Output peak ceiling (linear amplitude). Range [0.1, 1.0].
|
||||
@UIParam public var ceiling: Double = 0.95
|
||||
|
||||
/// Gain-release time in seconds. Range [0.01, 0.5].
|
||||
@UIParam public var release: Double = 0.05
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Default wet/dry blend — fully wet; the limiter sits in-line.
|
||||
@@ -61,10 +67,14 @@ public final class LimiterPedal: Pedal {
|
||||
/// Ceiling knob range (linear output peak).
|
||||
private let ceilingRange: ClosedRange<Double> = 0.1 ... 1.0
|
||||
|
||||
/// Release knob range in seconds.
|
||||
private let releaseRange: ClosedRange<Double> = 0.01 ... 0.5
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Boost", node: $boost, range: boostRange),
|
||||
PedalKnob(label: "Ceiling", node: $ceiling, range: ceilingRange),
|
||||
PedalKnob(label: "Release", node: $release, range: releaseRange),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -101,6 +111,7 @@ public final class LimiterPedal: Pedal {
|
||||
in: boosted,
|
||||
maxAmplitude: $ceiling,
|
||||
lookAheadTime: lookAheadTime,
|
||||
releaseTime: $release,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import LyrebirdUI
|
||||
///
|
||||
/// Signal chain (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry → SoftClip(drive:) → RBJLowPass(freq: tone, q: 0.707) → mono out
|
||||
/// dry → OversampledSaturator(curve: .softClipNormalized, drive:) → RBJLowPass(freq: tone, q: 0.707) → mono out
|
||||
/// ```
|
||||
///
|
||||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||
@@ -83,7 +83,14 @@ public final class OverdrivePedal: Pedal {
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: Saturated and tone-shaped mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let saturated: SoftClip.Audio = SoftClip.Audio(dry, drive: $drive)
|
||||
// Same normalised soft-clip curve as before (`tanh(drive·x) / tanh(drive)`), but
|
||||
// evaluated at 2× so high-drive harmonics don't alias.
|
||||
let saturated: OversampledSaturator = OversampledSaturator(
|
||||
dry,
|
||||
drive: $drive,
|
||||
curve: .softClipNormalized,
|
||||
oversample: 2
|
||||
)
|
||||
return RBJLowPass.Audio(
|
||||
input: saturated,
|
||||
freq: $tone,
|
||||
|
||||
@@ -15,7 +15,7 @@ import LyrebirdUI
|
||||
///
|
||||
/// Signal path (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry × OscSin(frequency) → wet
|
||||
/// dry → OversampledRingModulator(freq: frequency, oversample: 2) → wet
|
||||
/// ```
|
||||
///
|
||||
/// The wet/dry blend and bypass are handled by the `Pedal` base class.
|
||||
@@ -78,7 +78,8 @@ public final class RingModulatorPedal: Pedal {
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: The ring-modulated wet signal.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let carrier: OscSin.Audio = OscSin.Audio(freq: $frequency)
|
||||
return dry * carrier
|
||||
// Oversampled multiply: the sum sideband (f_in + f_carrier) can exceed Nyquist and
|
||||
// fold back as an inharmonic alias, so do the product at 2× and filter on the way down.
|
||||
return OversampledRingModulator(dry, freq: $frequency, oversample: 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,12 @@ import LyrebirdUI
|
||||
/// - sustain: Amount of sustain/compression. `0` = gentle, `10` = maximum squash and hold.
|
||||
/// Range `[0, 10]`. Defaults to `5.0`.
|
||||
/// - tone: Output low-pass cutoff in Hz. Range `[800, 8000]`. Defaults to `6000.0`.
|
||||
///
|
||||
/// At high sustain the compressor applies a low threshold, a high ratio, and up to +18 dB of
|
||||
/// makeup — a feed-forward compressor's non-zero attack lets transients overshoot before the
|
||||
/// gain clamps, so a hot pick can push the output past full scale and clip. The **Safety**
|
||||
/// switch inserts a brick-wall `LookAheadLimiter` after the compressor to catch those peaks;
|
||||
/// it is off by default and adds a short look-ahead output delay when engaged.
|
||||
public final class SustainerPedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
@@ -39,6 +45,10 @@ public final class SustainerPedal: Pedal {
|
||||
/// Output low-pass cutoff in Hz. Range [800, 8000].
|
||||
@UIParam public var tone: Double = 6000.0
|
||||
|
||||
/// Safety limiter engage state. `0` = off (compressor may overshoot), `1` = on
|
||||
/// (brick-wall look-ahead limiter catches transient peaks).
|
||||
@UIParam public var safetyLimiter: Double = 0.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private static let defaultMix: Double = 1.0
|
||||
@@ -69,6 +79,19 @@ public final class SustainerPedal: Pedal {
|
||||
private let makeupAtMin: Double = 0.0
|
||||
private let makeupAtMax: Double = 18.0
|
||||
|
||||
/// Safety-limiter peak ceiling (linear amplitude), just below full scale.
|
||||
private let safetyCeiling: Double = 0.98
|
||||
|
||||
/// Safety-limiter look-ahead / output delay in seconds. Only in circuit when Safety is on.
|
||||
private let safetyLookAheadTime: Double = 0.005
|
||||
|
||||
/// Safety-limiter gain-release time in seconds.
|
||||
private let safetyReleaseTime: Double = 0.05
|
||||
|
||||
/// Safety switch position values.
|
||||
private let safetyOffValue: Double = 0.0
|
||||
private let safetyOnValue: Double = 1.0
|
||||
|
||||
// MARK: - UI knobs
|
||||
|
||||
private let sustainRange: ClosedRange<Double> = 0.0 ... 10.0
|
||||
@@ -81,6 +104,19 @@ public final class SustainerPedal: Pedal {
|
||||
]
|
||||
}
|
||||
|
||||
public override var effectSwitches: [PedalSwitch] {
|
||||
[
|
||||
PedalSwitch(
|
||||
label: "Safety",
|
||||
node: $safetyLimiter,
|
||||
options: [
|
||||
PedalSwitch.Option(title: "Off", value: safetyOffValue),
|
||||
PedalSwitch.Option(title: "On", value: safetyOnValue),
|
||||
]
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a sustainer pedal.
|
||||
@@ -124,8 +160,22 @@ public final class SustainerPedal: Pedal {
|
||||
kneeWidth: kneeWidth,
|
||||
makeupGain: makeup
|
||||
)
|
||||
// Optional brick-wall safety limiter. Both branches are always built; `Select` picks
|
||||
// per the Safety switch (0 = compressor only, 1 = limited). Engaging it adds the
|
||||
// limiter's short look-ahead delay.
|
||||
let limited: LookAheadLimiter = LookAheadLimiter(
|
||||
in: compressed,
|
||||
maxAmplitude: safetyCeiling,
|
||||
lookAheadTime: safetyLookAheadTime,
|
||||
releaseTime: safetyReleaseTime,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
let guarded: Select.Audio = Select.Audio(
|
||||
which: $safetyLimiter,
|
||||
inputs: [compressed, limited]
|
||||
)
|
||||
return RBJLowPass.Audio(
|
||||
input: compressed,
|
||||
input: guarded,
|
||||
freq: $tone,
|
||||
q: toneQ
|
||||
)
|
||||
|
||||
@@ -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)")
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
@@ -55,6 +55,12 @@ final class TunerTap: SynthesizerBase {
|
||||
)
|
||||
let capture: TunerPitchCapture = TunerPitchCapture(input: filtered)
|
||||
pitchCapture = capture
|
||||
output(bus: scratchControlBus, source: capture)
|
||||
// Route through `controlOutput` (Out.Control → control-bus memory), NOT `output`
|
||||
// (Out.Audio → *audio*-bus memory at the same index). The scratch bus exists only to give
|
||||
// the engine a reason to evaluate the capture generator; writing the capture's pitch signal
|
||||
// to an audio bus at the control-bus index would land it on a hardware output channel (a low
|
||||
// control index collides with the output buses) — audible as crackle while the pitch is
|
||||
// unstable — and, because this tap runs after `mainGroup`, would bypass the rig mute.
|
||||
controlOutput(bus: scratchControlBus, source: capture)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ public struct BoardFlowView: View {
|
||||
private static let splitToggleWidth: CGFloat = 200
|
||||
private static let emptyLaneOpacity: Double = 0.4
|
||||
|
||||
/// Extra height the content may exceed the viewport by before vertical scrolling turns on, so a
|
||||
/// sub-pixel rounding difference doesn't flip the axis set on and off.
|
||||
private static let verticalScrollSlack: CGFloat = 1
|
||||
|
||||
/// Signal-path accent (the pink/magenta connector colour).
|
||||
private static let flowColor: Color = Color(red: 0.92, green: 0.32, blue: 0.70)
|
||||
|
||||
@@ -62,6 +66,10 @@ public struct BoardFlowView: View {
|
||||
/// Identifier of the lane/card currently hovered as a drop target, for highlight.
|
||||
@State private var dropTarget: String?
|
||||
|
||||
/// Measured height of the flow content, used to enable vertical scrolling only when the stacked
|
||||
/// lanes exceed the viewport height (tall parallel splits). Otherwise scrolling stays horizontal.
|
||||
@State private var contentHeight: CGFloat = 0
|
||||
|
||||
public init(shoeGaze: ShoeGaze, boardIndex: Int) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self.boardIndex = boardIndex
|
||||
@@ -81,19 +89,55 @@ public struct BoardFlowView: View {
|
||||
|
||||
private func flow(board: PedalBoard) -> some View {
|
||||
let stages: [StageModel] = stageModels(board: board)
|
||||
return ScrollView([.horizontal, .vertical], showsIndicators: true) {
|
||||
HStack(alignment: .center, spacing: BoardFlowView.stageSpacing) {
|
||||
endpoint("IN")
|
||||
ForEach(stages) { stage in
|
||||
connector(stereo: stage.stereoIn)
|
||||
stageView(stage)
|
||||
return GeometryReader { proxy in
|
||||
let viewportHeight: CGFloat = proxy.size.height
|
||||
// Lock to horizontal, adding the vertical axis only when the chain is taller than the
|
||||
// viewport (deep parallel splits) so it can be reached instead of clipped.
|
||||
let axes: Axis.Set = contentHeight > viewportHeight + BoardFlowView.verticalScrollSlack
|
||||
? [.horizontal, .vertical]
|
||||
: .horizontal
|
||||
ScrollView(axes, showsIndicators: true) {
|
||||
// The spacers centre the chain vertically when it is shorter than the viewport; when
|
||||
// it overflows, the min-height floor is already exceeded so they collapse to zero and
|
||||
// the chain scrolls. Pedals keep their intrinsic height either way — the window no
|
||||
// longer stretches them.
|
||||
VStack(spacing: 0) {
|
||||
Spacer(minLength: 0)
|
||||
chainRow(board: board, stages: stages)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
connector(stereo: board.width == 2)
|
||||
endpoint(board.width == 2 ? "OUT ⇒" : "OUT")
|
||||
.frame(minHeight: viewportHeight)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onPreferenceChange(BoardFlowContentHeightKey.self) { height in
|
||||
contentHeight = height
|
||||
}
|
||||
.padding(.vertical, BoardFlowView.regionPadding)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
|
||||
/// The left→right chain of endpoints, connectors and stage cards. Reports its own intrinsic
|
||||
/// height through `BoardFlowContentHeightKey` so `flow` can decide whether vertical scrolling is
|
||||
/// needed. Each pedal sizes to its own content, so the row is only as tall as its tallest card —
|
||||
/// a short pedal stays short next to a tall one.
|
||||
private func chainRow(board: PedalBoard, stages: [StageModel]) -> some View {
|
||||
HStack(alignment: .center, spacing: BoardFlowView.stageSpacing) {
|
||||
endpoint("IN")
|
||||
ForEach(stages) { stage in
|
||||
connector(stereo: stage.stereoIn)
|
||||
stageView(stage)
|
||||
}
|
||||
connector(stereo: board.width == 2)
|
||||
endpoint(board.width == 2 ? "OUT ⇒" : "OUT")
|
||||
}
|
||||
.padding(.vertical, BoardFlowView.regionPadding)
|
||||
.background(
|
||||
GeometryReader { contentProxy in
|
||||
Color.clear.preference(
|
||||
key: BoardFlowContentHeightKey.self,
|
||||
value: contentProxy.size.height
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Stage model
|
||||
@@ -531,3 +575,12 @@ private extension String {
|
||||
return String(dropFirst(prefix.count))
|
||||
}
|
||||
}
|
||||
|
||||
/// Carries the measured height of the flow content up to `BoardFlowView`, which compares it to the
|
||||
/// viewport height to decide whether the vertical scroll axis is needed.
|
||||
private struct BoardFlowContentHeightKey: PreferenceKey {
|
||||
static let defaultValue: CGFloat = 0
|
||||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
||||
value = max(value, nextValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -474,7 +474,20 @@ public struct PedalView: View {
|
||||
// the enclosure-width calculation consume the same array.
|
||||
let sliders: [PedalSlider] = pedal.effectSliders
|
||||
|
||||
ZStack(alignment: .topLeading) {
|
||||
// Content is the sizing layer so the enclosure hugs it vertically — a short pedal stays
|
||||
// short. The gradient fill and border/screw strokes are attached as background/overlay so
|
||||
// they conform to the content height instead of a greedy `RoundedRectangle` in a ZStack
|
||||
// dictating (and stretching) the height to fill the row.
|
||||
Group {
|
||||
if let looper: LooperPedal = pedal as? LooperPedal {
|
||||
looperColumnarContent(looper)
|
||||
} else {
|
||||
defaultContent(sliders: sliders)
|
||||
}
|
||||
}
|
||||
.padding(PedalView.enclosurePadding)
|
||||
.frame(width: enclosureWidth(for: sliders))
|
||||
.background(
|
||||
// Enclosure fill with top-to-bottom gradient
|
||||
RoundedRectangle(cornerRadius: PedalView.enclosureCornerRadius)
|
||||
.fill(
|
||||
@@ -484,38 +497,28 @@ public struct PedalView: View {
|
||||
endPoint: .bottom
|
||||
)
|
||||
)
|
||||
|
||||
// Outer border
|
||||
RoundedRectangle(cornerRadius: PedalView.enclosureCornerRadius)
|
||||
.stroke(Color.black.opacity(PedalView.outerBorderOpacity),
|
||||
lineWidth: PedalView.outerBorderLineWidth)
|
||||
|
||||
)
|
||||
.overlay(
|
||||
// Inner highlight rim (subtle bevel)
|
||||
RoundedRectangle(cornerRadius: PedalView.enclosureCornerRadius - PedalView.innerHighlightPadding)
|
||||
.stroke(Color.white.opacity(PedalView.innerHighlightOpacity),
|
||||
lineWidth: PedalView.innerHighlightLineWidth)
|
||||
.padding(PedalView.innerHighlightPadding)
|
||||
|
||||
// Content stack — the looper uses a wide, columnar layout to stay short; every other
|
||||
// pedal uses the default single-column section stack.
|
||||
Group {
|
||||
if let looper: LooperPedal = pedal as? LooperPedal {
|
||||
looperColumnarContent(looper)
|
||||
} else {
|
||||
defaultContent(sliders: sliders)
|
||||
}
|
||||
}
|
||||
.padding(PedalView.enclosurePadding)
|
||||
|
||||
// Corner screws — overlaid at the four corners
|
||||
screwCorners
|
||||
|
||||
// Info button, tucked just under the top-left corner screw.
|
||||
)
|
||||
.overlay(
|
||||
// Outer border
|
||||
RoundedRectangle(cornerRadius: PedalView.enclosureCornerRadius)
|
||||
.stroke(Color.black.opacity(PedalView.outerBorderOpacity),
|
||||
lineWidth: PedalView.outerBorderLineWidth)
|
||||
)
|
||||
// Corner screws — overlaid at the four corners.
|
||||
.overlay { screwCorners }
|
||||
// Info button, tucked just under the top-left corner screw.
|
||||
.overlay(alignment: .topLeading) {
|
||||
infoButton
|
||||
.padding(.leading, PedalView.infoButtonLeading)
|
||||
.padding(.top, PedalView.infoButtonTop)
|
||||
}
|
||||
.frame(width: enclosureWidth(for: sliders))
|
||||
.shadow(
|
||||
color: Color.black.opacity(PedalView.shadowOpacity),
|
||||
radius: PedalView.shadowRadius,
|
||||
@@ -543,7 +546,6 @@ public struct PedalView: View {
|
||||
.id(ObjectIdentifier(pedal))
|
||||
buttonRow
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
bottomControls
|
||||
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||
}
|
||||
@@ -579,7 +581,6 @@ public struct PedalView: View {
|
||||
looperTransportGrid(columns: 2)
|
||||
.id(ObjectIdentifier(pedal))
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,82 @@ struct CompressorPedalTests {
|
||||
#expect(labels == ["Input", "Threshold", "Ratio"])
|
||||
}
|
||||
|
||||
@Test func exposesSafetySwitch() throws {
|
||||
let pedal: CompressorPedal = CompressorPedal()
|
||||
let switchLabels: [String] = pedal.effectSwitches.map { $0.label }
|
||||
#expect(switchLabels == ["Safety"])
|
||||
let optionTitles: [String] = pedal.effectSwitches.first?.options.map { $0.title } ?? []
|
||||
#expect(optionTitles == ["Off", "On"])
|
||||
}
|
||||
|
||||
@Test func safetyLimiterCapsPeaks() throws {
|
||||
// Drive the compressor hard (hot input + makeup gain) so its non-zero attack lets
|
||||
// transients overshoot. With the safety limiter engaged the output peak must stay
|
||||
// near full scale; the two switch states must also produce different output.
|
||||
let renderDuration: Double = 0.1
|
||||
let sampleRate: Double = 44100.0
|
||||
|
||||
func render(safety: Double) throws -> [Float] {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(dstBus)
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: CompressorPedal = CompressorPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
pedal.sampleRate = sampleRate
|
||||
pedal.inputGain = 24.0
|
||||
pedal.threshold = -30.0
|
||||
pedal.ratio = 8.0
|
||||
pedal.safetyLimiter = safety
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
try engine.add(source)
|
||||
try engine.add(pedal, position: NodePosition.after(source))
|
||||
try engine.add(master, position: NodePosition.after(pedal))
|
||||
try engine.start()
|
||||
return readStereoCAF(url: url, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
let off: [Float] = try render(safety: 0.0)
|
||||
let on: [Float] = try render(safety: 1.0)
|
||||
|
||||
#expect(hasNonSilentOutput(off), "safety-off render was silent")
|
||||
#expect(hasNonSilentOutput(on), "safety-on render was silent")
|
||||
|
||||
// Skip the safety limiter's look-ahead fill window before measuring the peak.
|
||||
let lookAheadFillSamples: Int = 2048
|
||||
guard on.count > lookAheadFillSamples else { return }
|
||||
let onWindow: ArraySlice<Float> = on[lookAheadFillSamples...]
|
||||
let onPeak: Float = onWindow.reduce(0) { Swift.max($0, abs($1)) }
|
||||
|
||||
// Safety ceiling is just under full scale; downstream master only attenuates.
|
||||
let ceilingTolerance: Float = 0.05
|
||||
#expect(onPeak <= 1.0 + ceilingTolerance, "safety limiter failed to cap peak: \(onPeak)")
|
||||
|
||||
// The two switch positions must differ.
|
||||
let skip: Int = lookAheadFillSamples
|
||||
let window: Int = 2048
|
||||
guard off.count >= skip + window, on.count >= skip + window else { return }
|
||||
let offWindow: [Float] = Array(off[skip..<(skip + window)])
|
||||
let onWindow2: [Float] = Array(on[skip..<(skip + window)])
|
||||
let ssd: Double = zip(offWindow, onWindow2).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "safety switch had no effect on output")
|
||||
}
|
||||
|
||||
@Test func inputGainChangesOutput() throws {
|
||||
// The pre-compression input gain stage must alter the output: boosting the input
|
||||
// drives more of the signal past the threshold, changing the compressed result.
|
||||
|
||||
@@ -84,6 +84,16 @@ struct DistortionPedalTests {
|
||||
#expect(labels == ["Drive", "Tone"])
|
||||
}
|
||||
|
||||
@Test func outputStaysBoundedAtHighDrive() throws {
|
||||
// The final hard clip (after the tone low-pass) must re-establish the ±1 output bound
|
||||
// even at extreme drive, despite the oversampled clip sitting before the low-pass.
|
||||
let samples: [Float] = try render { pedal in pedal.drive = 50.0; pedal.tone = 6000.0 }
|
||||
let skip: Int = 2048
|
||||
guard samples.count > skip else { return }
|
||||
let peak: Float = samples[skip...].reduce(0) { Swift.max($0, abs($1)) }
|
||||
#expect(peak <= 1.05, "distortion output exceeded the clip ceiling: peak=\(peak)")
|
||||
}
|
||||
|
||||
@Test func registeredInBuiltInRegistry() throws {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: "Distortion")
|
||||
#expect(pedal is DistortionPedal)
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ struct LimiterPedalTests {
|
||||
private func render(
|
||||
boost: Double,
|
||||
ceiling: Double,
|
||||
release: Double = 0.05,
|
||||
sampleRate: Double = 44100.0
|
||||
) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
@@ -43,6 +44,7 @@ struct LimiterPedalTests {
|
||||
pedal.sampleRate = sampleRate
|
||||
pedal.boost = boost
|
||||
pedal.ceiling = ceiling
|
||||
pedal.release = release
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
|
||||
try engine.add(source)
|
||||
@@ -78,4 +80,32 @@ struct LimiterPedalTests {
|
||||
let tolerance: Float = 0.05
|
||||
#expect(peak <= Float(ceiling) + tolerance, "Limiter overshot ceiling: peak=\(peak)")
|
||||
}
|
||||
|
||||
@Test func exposesBoostCeilingReleaseKnobs() throws {
|
||||
let pedal: LimiterPedal = LimiterPedal()
|
||||
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(labels == ["Boost", "Ceiling", "Release"])
|
||||
}
|
||||
|
||||
@Test func releaseChangesOutput() throws {
|
||||
// Same drive and ceiling, different release times: the gain recovers between peaks
|
||||
// at different rates, so the limited output differs. Ceiling still holds for both.
|
||||
let ceiling: Double = 0.4
|
||||
let fast: [Float] = try render(boost: 12.0, ceiling: ceiling, release: 0.01)
|
||||
let slow: [Float] = try render(boost: 12.0, ceiling: ceiling, release: 0.5)
|
||||
|
||||
#expect(hasNonSilentOutput(fast), "fast-release render was silent")
|
||||
#expect(hasNonSilentOutput(slow), "slow-release render was silent")
|
||||
|
||||
let skip: Int = 2048
|
||||
let window: Int = 2048
|
||||
guard fast.count >= skip + window, slow.count >= skip + window else { return }
|
||||
let fastWindow: [Float] = Array(fast[skip..<(skip + window)])
|
||||
let slowWindow: [Float] = Array(slow[skip..<(skip + window)])
|
||||
let ssd: Double = zip(fastWindow, slowWindow).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "release time had no effect on limiter output")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
// OversampledRingModulatorTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("OversampledRingModulator")
|
||||
struct OversampledRingModulatorTests {
|
||||
|
||||
private let sampleRate: Double = 44100.0
|
||||
|
||||
/// Minimal synth: a sine through an `OversampledRingModulator`, written to a mono bus.
|
||||
private final class RingSynth: SynthesizerBase {
|
||||
private let inFreq: Double
|
||||
private let carrierFreq: Double
|
||||
private let factor: Int
|
||||
private let outBus: Int
|
||||
|
||||
init(inFreq: Double, carrierFreq: Double, factor: Int, outBus: Int) {
|
||||
self.inFreq = inFreq
|
||||
self.carrierFreq = carrierFreq
|
||||
self.factor = factor
|
||||
self.outBus = outBus
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func build() {
|
||||
let osc: OscSin.Audio = OscSin.Audio(freq: inFreq)
|
||||
output(bus: outBus, source: OversampledRingModulator(
|
||||
osc, freq: carrierFreq, oversample: factor))
|
||||
}
|
||||
}
|
||||
|
||||
private func render(inFreq: Double, carrierFreq: Double, factor: Int) throws -> [Float] {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.15, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
defer { engine.busAllocator.releaseAudioBus(dstBus) }
|
||||
let synth: RingSynth = RingSynth(
|
||||
inFreq: inFreq, carrierFreq: carrierFreq, factor: factor, outBus: dstBus.index)
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
try engine.add(synth)
|
||||
try engine.add(master, position: NodePosition.after(synth))
|
||||
try engine.start()
|
||||
return readStereoCAF(url: url, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
private func leftChannel(_ samples: [Float], skip: Int) -> [Double] {
|
||||
var out: [Double] = []
|
||||
var i: Int = skip * 2
|
||||
while i < samples.count {
|
||||
out.append(Double(samples[i]))
|
||||
i += 2
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
private func goertzelMagnitude(_ x: [Double], cyclesPerSample: Double) -> Double {
|
||||
let omega: Double = 2.0 * Double.pi * cyclesPerSample
|
||||
let cosine: Double = cos(omega)
|
||||
let sine: Double = sin(omega)
|
||||
let coeff: Double = 2.0 * cosine
|
||||
var s1: Double = 0.0
|
||||
var s2: Double = 0.0
|
||||
for v: Double in x {
|
||||
let s0: Double = v + coeff * s1 - s2
|
||||
s2 = s1
|
||||
s1 = s0
|
||||
}
|
||||
let real: Double = s1 - s2 * cosine
|
||||
let imag: Double = s2 * sine
|
||||
return (real * real + imag * imag).squareRoot()
|
||||
}
|
||||
|
||||
private func naiveRingMod(inFreq: Double, carrierFreq: Double, count: Int) -> [Double] {
|
||||
let inCps: Double = inFreq / sampleRate
|
||||
let cCps: Double = carrierFreq / sampleRate
|
||||
var out: [Double] = []
|
||||
out.reserveCapacity(count)
|
||||
for n: Int in 0..<count {
|
||||
let x: Double = sin(2.0 * Double.pi * inCps * Double(n))
|
||||
let c: Double = sin(2.0 * Double.pi * cCps * Double(n))
|
||||
out.append(x * c)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@Test func reducesSumSidebandAliasVersusNaive() throws {
|
||||
// in = 0.20·Fs, carrier = 0.35·Fs. Difference sideband = 0.15·Fs (legit, below Nyquist);
|
||||
// sum sideband = 0.55·Fs, which folds to a 0.45·Fs alias at the base rate. Measure the
|
||||
// alias relative to the legit difference sideband (self-normalising).
|
||||
let inHz: Double = 0.20 * sampleRate
|
||||
let carrierHz: Double = 0.35 * sampleRate
|
||||
let diffBin: Double = 0.15 // |0.35 − 0.20|
|
||||
let aliasBin: Double = 0.45 // |1 − 0.55|
|
||||
|
||||
let os: [Float] = try render(inFreq: inHz, carrierFreq: carrierHz, factor: 2)
|
||||
let osLeft: [Double] = leftChannel(os, skip: 2048)
|
||||
#expect(osLeft.count > 2048)
|
||||
|
||||
let osDiff: Double = goertzelMagnitude(osLeft, cyclesPerSample: diffBin)
|
||||
let osAlias: Double = goertzelMagnitude(osLeft, cyclesPerSample: aliasBin)
|
||||
let osRatio: Double = osAlias / osDiff
|
||||
|
||||
let naive: [Double] = naiveRingMod(inFreq: inHz, carrierFreq: carrierHz, count: osLeft.count)
|
||||
let nDiff: Double = goertzelMagnitude(naive, cyclesPerSample: diffBin)
|
||||
let nAlias: Double = goertzelMagnitude(naive, cyclesPerSample: aliasBin)
|
||||
let naiveRatio: Double = nAlias / nDiff
|
||||
|
||||
#expect(naiveRatio > 0.05, "baseline did not alias as expected (ratio=\(naiveRatio))")
|
||||
#expect(
|
||||
osRatio < naiveRatio * 0.5,
|
||||
"oversampling did not reduce ring-mod aliasing: os=\(osRatio) naive=\(naiveRatio)"
|
||||
)
|
||||
}
|
||||
|
||||
@Test func producesNonSilentOutput() throws {
|
||||
let os: [Float] = try render(inFreq: 440.0, carrierFreq: 220.0, factor: 2)
|
||||
#expect(hasNonSilentOutput(os), "ring modulator produced silence")
|
||||
}
|
||||
|
||||
@Test func negativeCarrierStaysFiniteAndBounded() throws {
|
||||
// A negative carrier frequency drives the phase increment negative; the phase must wrap
|
||||
// both directions rather than growing unbounded and pushing sin() out of accurate range.
|
||||
let os: [Float] = try render(inFreq: 440.0, carrierFreq: -220.0, factor: 2)
|
||||
let left: [Double] = leftChannel(os, skip: 1024)
|
||||
#expect(!left.isEmpty)
|
||||
#expect(left.allSatisfy { $0.isFinite }, "negative carrier produced non-finite output")
|
||||
let peak: Double = left.map { abs($0) }.max() ?? 0
|
||||
#expect(peak <= 1.2, "negative carrier output was not bounded: peak=\(peak)")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// OversampledSaturatorTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("OversampledSaturator")
|
||||
struct OversampledSaturatorTests {
|
||||
|
||||
private let sampleRate: Double = 44100.0
|
||||
|
||||
/// Minimal synth: a sine through an `OversampledSaturator`, written to a mono bus.
|
||||
private final class SaturatorSynth: SynthesizerBase {
|
||||
private let freq: Double
|
||||
private let drive: Double
|
||||
private let curve: SaturationCurve
|
||||
private let factor: Int
|
||||
private let outBus: Int
|
||||
|
||||
init(freq: Double, drive: Double, curve: SaturationCurve, factor: Int, outBus: Int) {
|
||||
self.freq = freq
|
||||
self.drive = drive
|
||||
self.curve = curve
|
||||
self.factor = factor
|
||||
self.outBus = outBus
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func build() {
|
||||
let osc: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
output(bus: outBus, source: OversampledSaturator(
|
||||
osc, drive: drive, curve: curve, oversample: factor))
|
||||
}
|
||||
}
|
||||
|
||||
private func render(
|
||||
freq: Double,
|
||||
drive: Double,
|
||||
curve: SaturationCurve,
|
||||
factor: Int
|
||||
) throws -> [Float] {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.15, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
defer { engine.busAllocator.releaseAudioBus(dstBus) }
|
||||
let synth: SaturatorSynth = SaturatorSynth(
|
||||
freq: freq, drive: drive, curve: curve, factor: factor, outBus: dstBus.index)
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
try engine.add(synth)
|
||||
try engine.add(master, position: NodePosition.after(synth))
|
||||
try engine.start()
|
||||
return readStereoCAF(url: url, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
/// Left channel (interleaved stereo), warm-up frames skipped.
|
||||
private func leftChannel(_ samples: [Float], skip: Int) -> [Double] {
|
||||
var out: [Double] = []
|
||||
var i: Int = skip * 2
|
||||
while i < samples.count {
|
||||
out.append(Double(samples[i]))
|
||||
i += 2
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/// Goertzel magnitude at normalised frequency `cyclesPerSample`.
|
||||
private func goertzelMagnitude(_ x: [Double], cyclesPerSample: Double) -> Double {
|
||||
let omega: Double = 2.0 * Double.pi * cyclesPerSample
|
||||
let cosine: Double = cos(omega)
|
||||
let sine: Double = sin(omega)
|
||||
let coeff: Double = 2.0 * cosine
|
||||
var s1: Double = 0.0
|
||||
var s2: Double = 0.0
|
||||
for v: Double in x {
|
||||
let s0: Double = v + coeff * s1 - s2
|
||||
s2 = s1
|
||||
s1 = s0
|
||||
}
|
||||
let real: Double = s1 - s2 * cosine
|
||||
let imag: Double = s2 * sine
|
||||
return (real * real + imag * imag).squareRoot()
|
||||
}
|
||||
|
||||
/// A naive base-rate hard clipper on the same sine — the alias-generating baseline the
|
||||
/// oversampled path is meant to beat.
|
||||
private func naiveHardClip(
|
||||
freq: Double,
|
||||
drive: Double,
|
||||
low: Double,
|
||||
high: Double,
|
||||
count: Int
|
||||
) -> [Double] {
|
||||
let cyclesPerSample: Double = freq / sampleRate
|
||||
var out: [Double] = []
|
||||
out.reserveCapacity(count)
|
||||
for n: Int in 0..<count {
|
||||
let x: Double = sin(2.0 * Double.pi * cyclesPerSample * Double(n))
|
||||
let shaped: Double = tanh(x) * drive
|
||||
out.append(Swift.min(high, Swift.max(low, shaped)))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@Test func reducesAliasingVersusNaiveHardClip() throws {
|
||||
// 13230 Hz = 0.3·Fs. A symmetric clipper's dominant 3rd harmonic lands at 0.9·Fs,
|
||||
// which folds to a 0.1·Fs (4410 Hz) alias at the base rate. Measure the alias energy
|
||||
// RELATIVE to the fundamental (self-normalising, so downstream routing gain cancels).
|
||||
let fundamentalHz: Double = 0.3 * sampleRate
|
||||
let aliasHz: Double = 0.1 * sampleRate // |3·0.3 − 1|·Fs
|
||||
let drive: Double = 5.0
|
||||
let low: Double = -1.0
|
||||
let high: Double = 1.0
|
||||
|
||||
let os: [Float] = try render(
|
||||
freq: fundamentalHz, drive: drive,
|
||||
curve: .tanhPostGainHardClip(low: low, high: high), factor: 4)
|
||||
let osLeft: [Double] = leftChannel(os, skip: 2048)
|
||||
#expect(osLeft.count > 2048)
|
||||
|
||||
let fundamentalBin: Double = fundamentalHz / sampleRate
|
||||
let aliasBin: Double = aliasHz / sampleRate
|
||||
|
||||
let osFund: Double = goertzelMagnitude(osLeft, cyclesPerSample: fundamentalBin)
|
||||
let osAlias: Double = goertzelMagnitude(osLeft, cyclesPerSample: aliasBin)
|
||||
let osRatio: Double = osAlias / osFund
|
||||
|
||||
let naive: [Double] = naiveHardClip(
|
||||
freq: fundamentalHz, drive: drive, low: low, high: high, count: osLeft.count)
|
||||
let nFund: Double = goertzelMagnitude(naive, cyclesPerSample: fundamentalBin)
|
||||
let nAlias: Double = goertzelMagnitude(naive, cyclesPerSample: aliasBin)
|
||||
let naiveRatio: Double = nAlias / nFund
|
||||
|
||||
// The naive clipper must actually alias (sanity), and oversampling must cut the
|
||||
// alias-to-fundamental ratio by at least half. In practice the 4× halfband path
|
||||
// attenuates it far more; 0.5 is a conservative, non-flaky bound.
|
||||
#expect(naiveRatio > 0.05, "baseline did not alias as expected (ratio=\(naiveRatio))")
|
||||
#expect(
|
||||
osRatio < naiveRatio * 0.5,
|
||||
"oversampling did not reduce aliasing: os=\(osRatio) naive=\(naiveRatio)"
|
||||
)
|
||||
}
|
||||
|
||||
@Test func hardClipCurveRespectsBounds() throws {
|
||||
// With a hard-clip curve the output must stay within [low, high] (plus a small margin
|
||||
// for halfband ripple / routing) regardless of how hard it is driven.
|
||||
let low: Double = -0.5
|
||||
let high: Double = 0.5
|
||||
let samples: [Float] = try render(
|
||||
freq: 2000.0, drive: 10.0,
|
||||
curve: .tanhPostGainHardClip(low: low, high: high), factor: 4)
|
||||
let left: [Double] = leftChannel(samples, skip: 2048)
|
||||
#expect(!left.isEmpty)
|
||||
let peak: Double = left.map { abs($0) }.max() ?? 0
|
||||
let margin: Double = 0.1
|
||||
#expect(peak <= high + margin, "hard-clip curve exceeded its ceiling: peak=\(peak)")
|
||||
}
|
||||
|
||||
@Test func softCurvesStayBounded() throws {
|
||||
// tanh-family curves saturate toward ±1; output must stay bounded well under runaway.
|
||||
let samples: [Float] = try render(
|
||||
freq: 2000.0, drive: 30.0, curve: .tanhPreGain, factor: 2)
|
||||
let left: [Double] = leftChannel(samples, skip: 2048)
|
||||
#expect(!left.isEmpty)
|
||||
let peak: Double = left.map { abs($0) }.max() ?? 0
|
||||
#expect(peak <= 1.2, "tanh saturator output was not bounded near ±1: peak=\(peak)")
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -61,4 +61,35 @@ struct SustainerPedalTests {
|
||||
}
|
||||
#expect(ssd > 0, "sustain knob had no effect on output")
|
||||
}
|
||||
|
||||
@Test func exposesSafetySwitch() throws {
|
||||
let pedal: SustainerPedal = SustainerPedal()
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Safety"])
|
||||
#expect(pedal.effectSwitches.first?.options.map { $0.title } == ["Off", "On"])
|
||||
}
|
||||
|
||||
@Test func safetyLimiterCapsPeaks() throws {
|
||||
// Max sustain drives a low threshold, high ratio, and +18 dB makeup — the compressor's
|
||||
// non-zero attack lets transients overshoot. With Safety on, the output peak must stay
|
||||
// near full scale, and the two switch states must differ.
|
||||
let off: [Float] = try render {
|
||||
$0.sampleRate = 44100.0; $0.sustain = 10.0; $0.safetyLimiter = 0.0
|
||||
}
|
||||
let on: [Float] = try render {
|
||||
$0.sampleRate = 44100.0; $0.sustain = 10.0; $0.safetyLimiter = 1.0
|
||||
}
|
||||
#expect(hasNonSilentOutput(off) && hasNonSilentOutput(on))
|
||||
|
||||
let fill: Int = 2048
|
||||
guard on.count > fill else { return }
|
||||
let onPeak: Float = on[fill...].reduce(0) { Swift.max($0, abs($1)) }
|
||||
#expect(onPeak <= 1.05, "safety limiter failed to cap peak: \(onPeak)")
|
||||
|
||||
let window: Int = 2048
|
||||
guard off.count >= fill + window, on.count >= fill + window else { return }
|
||||
let ssd: Double = zip(off[fill..<(fill + window)], on[fill..<(fill + window)]).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||
}
|
||||
#expect(ssd > 0, "safety switch had no effect on output")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,45 @@ struct TunerTests {
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.rigMuted, "Second engageTuner() call while already engaged must be a no-op")
|
||||
}
|
||||
|
||||
/// With the rig muted, an engaged tuner must leave the audio output silent. Guards against the
|
||||
/// tuner's pitch-capture signal leaking into a hardware output channel: its scratch bus is a
|
||||
/// *control* bus, but writing it through the audio-rate `output(bus:)` helper would treat that
|
||||
/// index as an *audio* bus (colliding with the low output-bus indices) and, since the tap runs
|
||||
/// after `mainGroup`, bypass the rig mute — audible as crackle while the pitch is unstable.
|
||||
@Test func engagedTunerDoesNotLeakIntoOutput() throws {
|
||||
let renderDuration: Double = 0.4
|
||||
let sampleRate: Double = 44100.0
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine, inputSource: .testLoop)
|
||||
|
||||
try withExtendedLifetime(shoeGaze) {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
// Feed the test-loop signal so the pitch tracker produces a real (non-zero) estimate —
|
||||
// the value that would leak if the scratch write hit an audio bus.
|
||||
shoeGaze.setInputMuted(false)
|
||||
shoeGaze.tunerMutesRig = true
|
||||
shoeGaze.engageTuner()
|
||||
#expect(shoeGaze.rigMuted)
|
||||
|
||||
try engine.start()
|
||||
let samples: [Float] = readStereoCAF(url: url, sampleRate: sampleRate)
|
||||
|
||||
// Ignore the opening window: the rig-mute gain ramps up over its first blocks (a separate,
|
||||
// pre-existing BoardOutputMaster behaviour), briefly passing the test-loop signal. Once it
|
||||
// settles the output must be exactly silent — the tuner leak, if present, persists for the
|
||||
// whole render (it bypasses the mute), so the settled tail catches it.
|
||||
let channels: Int = 2
|
||||
let settleSeconds: Double = 0.15
|
||||
let tailStart: Int = Int(settleSeconds * sampleRate) * channels
|
||||
let tail: [Float] = Array(samples[min(tailStart, samples.count)...])
|
||||
#expect(!tail.isEmpty)
|
||||
#expect(!hasNonSilentOutput(tail),
|
||||
"once the rig mute settles, an engaged tuner must not leak its pitch signal into the output")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`.
|
||||