Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5040ea1518 | |||
| 21b9123a87 | |||
| 24ce4564e8 | |||
| b1303a25ae | |||
| 21fda7067d | |||
| 8c601e2029 | |||
| 5a07a6d4b4 | |||
| 475dd392e6 | |||
| dff58175f1 | |||
| 42268b65a1 | |||
| 2c36de5c0d | |||
| f19dc2c1b3 | |||
| 6ad813601f | |||
| 652a5a76ca | |||
| 9b31be7921 | |||
| 705b4ed534 | |||
| 4627b3b800 | |||
| c25d783b71 | |||
| b4b2f58762 | |||
| c0605d295d |
@@ -163,7 +163,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
@@ -176,7 +176,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 0.9;
|
||||
MARKETING_VERSION = 0.91;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -194,7 +194,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@@ -206,7 +206,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 0.9;
|
||||
MARKETING_VERSION = 0.91;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
|
||||
@@ -46,7 +46,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private static let heightFraction: CGFloat = 0.88
|
||||
|
||||
/// The default pedal the seed board comes up with, so audio is audible immediately on Start.
|
||||
private static let seedPedalType: String = "Overdrive"
|
||||
private static let seedPedalType: PedalType = .overdrive
|
||||
|
||||
// MARK: - Owned objects
|
||||
|
||||
@@ -92,7 +92,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
created = board
|
||||
try shoeGaze.appendPedal(type: AppDelegate.seedPedalType, to: board)
|
||||
try shoeGaze.appendPedal(AppDelegate.seedPedalType, to: board)
|
||||
} catch {
|
||||
if let board: PedalBoard = created { shoeGaze.removeBoard(board) }
|
||||
print("[ShoeGazeBuilder] seed board failed: \(error)")
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 6.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
TARGETED_DEVICE_FAMILY = 2;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -200,7 +200,7 @@
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 6.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
TARGETED_DEVICE_FAMILY = 2;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -29,16 +29,15 @@
|
||||
</dict>
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
|
||||
@@ -25,7 +25,8 @@ struct ShoeGazeBuilderiOSApp: App {
|
||||
NavigationStack {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
hardwareSampleRate: { model.hardwareSampleRate }
|
||||
hardwareSampleRate: { model.hardwareSampleRate },
|
||||
onEnableLiveInput: { model.enableLiveInput() }
|
||||
)
|
||||
.navigationTitle("ShoeGaze Builder")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
||||
@@ -24,16 +24,29 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
|
||||
private static let blockSize: Int = 512
|
||||
private static let outputChannels: Int = 2
|
||||
// Default to one input channel so live input is available immediately. The trade-off is
|
||||
// that the iOS driver runs a `.playAndRecord` session with the RemoteIO input element
|
||||
// enabled, so iOS prompts for microphone access at the first Start even while the input
|
||||
// still defaults to `.testLoop`. (The permission-gated `enableLiveInput()` rebuild remains
|
||||
// available for any future build that starts input-less.)
|
||||
private static let inputChannels: Int = 1
|
||||
private static let numAudioBuses: Int = 256
|
||||
private static let seedPedalType: String = "Overdrive"
|
||||
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.
|
||||
/// The active ShoeGaze builder session. Swapped out when live input is enabled (the engine
|
||||
/// is rebuilt with an input channel); the `@Observable` change re-binds the hosting view.
|
||||
private(set) var shoeGaze: ShoeGaze
|
||||
|
||||
private let engine: SynthesisEngine
|
||||
private let iosDriver: iOSAudioDriver
|
||||
private var engine: SynthesisEngine
|
||||
private var iosDriver: iOSAudioDriver
|
||||
|
||||
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
||||
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
||||
@@ -41,6 +54,28 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
// MARK: - Init
|
||||
|
||||
init() {
|
||||
ShoeGazeBuilderiOSAppModel.configureAudioSession()
|
||||
let built: (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) =
|
||||
ShoeGazeBuilderiOSAppModel.buildEngine(inputChannels: ShoeGazeBuilderiOSAppModel.inputChannels)
|
||||
self.engine = built.engine
|
||||
self.iosDriver = built.driver
|
||||
self.shoeGaze = built.shoeGaze
|
||||
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
board.label = "Board 1"
|
||||
try shoeGaze.appendPedal(ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] seed board failed: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Audio session / engine construction
|
||||
|
||||
/// Activates the play-and-record audio session once. Idempotent; safe to call before each
|
||||
/// engine build. Activating the session does not by itself prompt for microphone access —
|
||||
/// the prompt only fires when an input-enabled engine first starts.
|
||||
private static func configureAudioSession() {
|
||||
let session: AVAudioSession = AVAudioSession.sharedInstance()
|
||||
do {
|
||||
try session.setCategory(.playAndRecord,
|
||||
@@ -48,31 +83,108 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
options: [.defaultToSpeaker, .allowBluetoothHFP])
|
||||
try session.setActive(true)
|
||||
} catch {
|
||||
// Surface the failure: the engine is built from `session.sampleRate` below, which may
|
||||
// report a stale/default rate if activation failed.
|
||||
print("[ShoeGazeBuilderiOS] AVAudioSession setup failed: \(error)")
|
||||
}
|
||||
let sampleRate: Double = session.sampleRate
|
||||
}
|
||||
|
||||
/// Builds a fresh engine + driver + empty `ShoeGaze` with the given input-channel count.
|
||||
private static func buildEngine(
|
||||
inputChannels: Int
|
||||
) -> (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) {
|
||||
let sampleRate: Double = AVAudioSession.sharedInstance().sampleRate
|
||||
let driver: iOSAudioDriver = iOSAudioDriver()
|
||||
let eng: SynthesisEngine = SynthesisEngine(
|
||||
let engine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
|
||||
sampleRate: sampleRate,
|
||||
numOutputChannels: ShoeGazeBuilderiOSAppModel.outputChannels,
|
||||
numInputChannels: 0,
|
||||
numInputChannels: inputChannels,
|
||||
numAudioBuses: ShoeGazeBuilderiOSAppModel.numAudioBuses,
|
||||
driver: driver
|
||||
)
|
||||
self.iosDriver = driver
|
||||
self.engine = eng
|
||||
self.shoeGaze = ShoeGaze(engine: eng)
|
||||
return (engine, driver, ShoeGaze(engine: engine))
|
||||
}
|
||||
|
||||
// MARK: - Live input
|
||||
|
||||
/// Enables live input on iOS: requests microphone access, then (on grant) rebuilds the
|
||||
/// engine with one input channel — preserving the current rig — and selects live input.
|
||||
///
|
||||
/// The rebuild is required because the input-channel count is fixed at engine construction,
|
||||
/// and constructing with an input channel up-front would make iOS prompt for the microphone
|
||||
/// at the first Start even in test-loop mode. Gating the rebuild behind an explicit request
|
||||
/// keeps the prompt where the user expects it.
|
||||
func enableLiveInput() {
|
||||
MicrophonePermission.request { [weak self] granted in
|
||||
guard let self, granted else { return }
|
||||
self.rebuildWithLiveInput()
|
||||
}
|
||||
}
|
||||
|
||||
/// Snapshots the rig, rebuilds the engine with one input channel, restores the rig, and
|
||||
/// selects live input on channel 0. No-op if the engine already has an input channel.
|
||||
private func rebuildWithLiveInput() {
|
||||
guard engine.numInputChannels == 0 else {
|
||||
// Engine already has an input channel: just select live input, no rebuild.
|
||||
selectLiveInputAndPersist()
|
||||
return
|
||||
}
|
||||
|
||||
let wasRunning: Bool = engine.isRunning
|
||||
|
||||
// Snapshot the rig BEFORE any teardown. If this fails, abort the rebuild rather than
|
||||
// tear the engine down and lose the rig — the user stays on the current engine.
|
||||
let snapshot: Data
|
||||
do {
|
||||
snapshot = try shoeGaze.rigData()
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] rig snapshot failed; aborting live-input rebuild: \(error)")
|
||||
return
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
shoeGaze.teardown()
|
||||
|
||||
ShoeGazeBuilderiOSAppModel.configureAudioSession()
|
||||
let rebuilt: (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) =
|
||||
ShoeGazeBuilderiOSAppModel.buildEngine(inputChannels: 1)
|
||||
self.engine = rebuilt.engine
|
||||
self.iosDriver = rebuilt.driver
|
||||
self.shoeGaze = rebuilt.shoeGaze
|
||||
|
||||
do {
|
||||
// Teardown already happened, so a restore failure can only recover by seeding.
|
||||
try shoeGaze.loadRig(from: snapshot)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] rig restore after rebuild failed: \(error)")
|
||||
seedFallbackBoard()
|
||||
}
|
||||
|
||||
selectLiveInputAndPersist()
|
||||
|
||||
if wasRunning { try? engine.start() }
|
||||
}
|
||||
|
||||
/// Selects live input on channel 0 and persists the choice for restore-on-relaunch.
|
||||
private func selectLiveInputAndPersist() {
|
||||
do {
|
||||
try shoeGaze.setInputSource(.liveInput(channel: 0))
|
||||
UserDefaults.standard.set(
|
||||
ShoeGazeBuilderiOSAppModel.liveInputChannelZeroTag,
|
||||
forKey: ShoeGazeBuilderiOSAppModel.inputSelectionDefaultsKey
|
||||
)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] selecting live input failed: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Seeds a single default board so the rig is never empty after a failed restore.
|
||||
private func seedFallbackBoard() {
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
board.label = "Board 1"
|
||||
try shoeGaze.appendPedal(type: ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
|
||||
try shoeGaze.appendPedal(ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] seed board failed: \(error)")
|
||||
print("[ShoeGazeBuilderiOS] fallback seed board failed: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ final class ShoeGazeDemoController {
|
||||
///
|
||||
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
||||
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
||||
/// Board 3: Mu-Tron → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
||||
/// Board 3: Mutant → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
||||
private func buildBoards() {
|
||||
do {
|
||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||
@@ -269,7 +269,7 @@ final class ShoeGazeDemoController {
|
||||
|
||||
let board3: PedalBoard = try shoeGaze.addBoard()
|
||||
board3.label = "Board 3"
|
||||
try board3.add(MuTronPedal())
|
||||
try board3.add(MutantPedal())
|
||||
try board3.add(AutoWahPedal())
|
||||
try board3.add(FeedbackDelayPedal())
|
||||
try board3.add(MultiTapDelayPedal())
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 6.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
TARGETED_DEVICE_FAMILY = 2;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -198,7 +198,7 @@
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 6.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
TARGETED_DEVICE_FAMILY = 2;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -29,16 +29,15 @@
|
||||
</dict>
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
|
||||
@@ -1,3 +1,117 @@
|
||||
# ShoeGaze
|
||||
|
||||
A package depenedent on Lyrebird for creating and storing virtual Guitar Pedal Boards
|
||||
**A virtual guitar-pedalboard framework for macOS and iPadOS, built on [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird).**
|
||||
|
||||
ShoeGaze turns Lyrebird's real-time synthesis engine into a stompbox rig: chain modeled
|
||||
guitar pedals into one or more signal-flow boards, tweak them live with knobs and switches,
|
||||
mix or switch between boards, and save the whole rig to disk. Run it on a synthesized test
|
||||
signal (no hardware needed) or on live guitar through an audio input.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- **18 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and
|
||||
pitch — see the catalog below.
|
||||
- **Multi-board rigs** — build several boards and a board-mixer bar to **Solo** one (amp-channel
|
||||
style) or **Blend** any subset, each with its own level and a click-free crossfade.
|
||||
- **Signal-flow editor** — drag pedals in from the palette; reorder, split into parallel or
|
||||
stereo lanes, and merge back to mono.
|
||||
- **Save / load rigs** as JSON, on both platforms.
|
||||
- **Recording** — capture your output to timestamped files.
|
||||
- **Test signal or live input** — a built-in arpeggiated test loop (shared across all boards so
|
||||
they stay phase-locked) or a hardware input channel.
|
||||
- **SwiftUI views** — a complete stompbox UI (`LyrebirdShoeGazeUI`) or just the headless
|
||||
framework (`LyrebirdShoeGaze`) to drive your own interface.
|
||||
|
||||
## Pedal catalog
|
||||
|
||||
| Category | Pedals |
|
||||
|---|---|
|
||||
| Drive & dynamics | Overdrive, Fuzz, Compressor, Limiter, Noise Gate |
|
||||
| EQ & filter | Graphic EQ, Auto-Wah, Mutant, Phaser |
|
||||
| Modulation | Tremolo, Modulation |
|
||||
| Delay & reverb | Delay, Feedback Delay, Multi-Tap Delay, Ping-Pong, Reverb |
|
||||
| Pitch & octave | Octave Splitter, Bass Octaver |
|
||||
|
||||
Every pedal exposes its parameters as knobs/switches and round-trips through the rig save format.
|
||||
|
||||
## Requirements
|
||||
|
||||
- macOS 15+ / iPadOS 18+ (iPad, landscape)
|
||||
- Swift 6.0 toolchain / Xcode 16+
|
||||
- [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird) 1.2.0+
|
||||
|
||||
## Packages
|
||||
|
||||
Two library products:
|
||||
|
||||
- **`LyrebirdShoeGaze`** — the core pedal/board framework (no SwiftUI).
|
||||
- **`LyrebirdShoeGazeUI`** — SwiftUI pedalboard views (knobs, switches, faders, board mixer).
|
||||
|
||||
Add the dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
.package(url: "https://realizedsound.mooo.com/josh/ShoeGaze", from: "1.0.0"),
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
Build a board and start the engine (macOS):
|
||||
|
||||
```swift
|
||||
import Lyrebird
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
let driver = CoreAudioDriver()
|
||||
let engine = SynthesisEngine(
|
||||
blockSize: 512, sampleRate: 48_000,
|
||||
numOutputChannels: 2, numInputChannels: 1,
|
||||
numAudioBuses: 256, driver: driver
|
||||
)
|
||||
|
||||
let shoeGaze = ShoeGaze(engine: engine) // defaults to the test-loop signal
|
||||
let board = try shoeGaze.addBoard()
|
||||
try shoeGaze.appendPedal(.overdrive, to: board)
|
||||
try shoeGaze.appendPedal(.delay, to: board)
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
try engine.start()
|
||||
```
|
||||
|
||||
Drop in the full builder UI:
|
||||
|
||||
```swift
|
||||
import SwiftUI
|
||||
import LyrebirdShoeGazeUI
|
||||
|
||||
struct ContentView: View {
|
||||
let shoeGaze: ShoeGaze
|
||||
var body: some View {
|
||||
ShoeGazeBuilderView(shoeGaze: shoeGaze)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Demo apps
|
||||
|
||||
Open `ShoeGaze.xcworkspace` in Xcode and run a scheme from `Demo/`:
|
||||
|
||||
- **ShoeGazeBuilder** (macOS) / **ShoeGazeBuilderiOS** (iPad) — the full palette + board builder.
|
||||
- **ShoeGazeDemo** / **ShoeGazeiOSDemo** — a minimal player view.
|
||||
|
||||
## Screenshots
|
||||
|
||||
| macOS builder | Board mixer |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
## Built on Lyrebird
|
||||
|
||||
ShoeGaze is a sample project for [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird), a
|
||||
native Swift audio-synthesis framework. Pedals are Lyrebird `Synthesizer` graphs of `Generator`
|
||||
nodes; the board/engine plumbing handles real-time-safe signal routing and scheduling.
|
||||
|
||||
## License
|
||||
|
||||
MIT — see [LICENSE](LICENSE).
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// TestLoopTap.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
|
||||
/// Internal synthesizer that copies the shared global test-loop bus to a board head bus.
|
||||
///
|
||||
/// In `.testLoop` mode every board reads the **same** global ``TestLoopSource`` (so all boards
|
||||
/// stay phase-locked instead of each running an independently-phased arpeggio). A `TestLoopTap`
|
||||
/// per board reads the global test bus at `inputBusIndex` and writes it to the board's head bus
|
||||
/// at `outputBusIndex`, so the first pedal still reads from a board-owned bus.
|
||||
///
|
||||
/// Added `.after(_:)` the global source so it evaluates once the source has written the test bus
|
||||
/// for the current block.
|
||||
///
|
||||
/// - Note: Must be removed from the engine before the board's `teardown()` releases the head bus.
|
||||
final class TestLoopTap: SynthesizerBase {
|
||||
|
||||
// MARK: - Routing
|
||||
|
||||
/// Index of the shared global test-loop bus to read from.
|
||||
private let inputBusIndex: Int
|
||||
|
||||
/// Index of the board head bus to write to.
|
||||
private let outputBusIndex: Int
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a tap that copies `inputBusIndex` (the global test bus) to `outputBusIndex`
|
||||
/// (a board head bus).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - inputBusIndex: Shared global test-loop bus index to read from.
|
||||
/// - outputBusIndex: Board head bus index to write to.
|
||||
init(inputBusIndex: Int, outputBusIndex: Int) {
|
||||
self.inputBusIndex = inputBusIndex
|
||||
self.outputBusIndex = outputBusIndex
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Build
|
||||
|
||||
override func build() {
|
||||
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// PedalType.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/// A type-safe identifier for a pedal type, used by the board-edit API instead of a raw string.
|
||||
///
|
||||
/// `PedalType` is an extensible token (the `RawRepresentable` struct pattern, à la
|
||||
/// `Notification.Name`): the built-in pedals are exposed as static members for discoverable,
|
||||
/// autocompleting call sites —
|
||||
///
|
||||
/// ```swift
|
||||
/// try shoeGaze.appendPedal(.overdrive, to: board)
|
||||
/// ```
|
||||
///
|
||||
/// — while staying open for custom pedals, since any `PedalType("My Pedal")` is valid and a
|
||||
/// third party can add their own static members in an extension.
|
||||
///
|
||||
/// `rawValue` is the pedal's `displayName`, which is exactly what the rig save format stores
|
||||
/// (`PedalState.type`) and what ``PedalRegistry`` keys on. `PedalType` therefore changes only the
|
||||
/// authoring call site — the JSON format and load path are unchanged.
|
||||
///
|
||||
/// > Note: named `PedalType` rather than `PedalKind` to avoid colliding with Lyrebird's
|
||||
/// > score-notation `PedalKind` enum, which is visible whenever both modules are imported.
|
||||
public struct PedalType: RawRepresentable, Hashable, Sendable {
|
||||
|
||||
/// The pedal's `displayName`; the key used by ``PedalRegistry`` and stored in saved rigs.
|
||||
public let rawValue: String
|
||||
|
||||
/// Creates a type from a raw `displayName` string.
|
||||
public init(rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
/// Creates a type from a raw `displayName` string.
|
||||
public init(_ rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Built-in pedals
|
||||
|
||||
public extension PedalType {
|
||||
|
||||
// Drive & dynamics
|
||||
static let overdrive = PedalType("Overdrive")
|
||||
static let fuzz = PedalType("Fuzz")
|
||||
static let compressor = PedalType("Compressor")
|
||||
static let limiter = PedalType("Limiter")
|
||||
static let noiseGate = PedalType("Noise Gate")
|
||||
|
||||
// EQ & filter
|
||||
static let graphicEQ = PedalType("Graphic EQ")
|
||||
static let autoWah = PedalType("Auto-Wah")
|
||||
static let mutant = PedalType("Mutant")
|
||||
static let phaser = PedalType("Phaser")
|
||||
|
||||
// Modulation
|
||||
static let tremolo = PedalType("Tremolo")
|
||||
static let modulation = PedalType("Modulation")
|
||||
|
||||
// Delay & reverb
|
||||
static let delay = PedalType("Delay")
|
||||
static let feedbackDelay = PedalType("Feedback Delay")
|
||||
static let multiTapDelay = PedalType("Multi-Tap Delay")
|
||||
static let pingPong = PedalType("Ping-Pong")
|
||||
static let reverb = PedalType("Reverb")
|
||||
|
||||
// Pitch & octave
|
||||
static let octaveSplitter = PedalType("Octave Splitter")
|
||||
static let bassOctaver = PedalType("Bass Octaver")
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import LyrebirdUI
|
||||
|
||||
/// Amplitude-tracked auto-wah pedal built from discrete tracking + filter stages.
|
||||
///
|
||||
/// Unlike `MuTronPedal` (which wraps the single fused `MuTronIII` generator), this pedal
|
||||
/// Unlike `MutantPedal` (which wraps the single fused `MuTronIII` generator), this pedal
|
||||
/// wires the envelope path explicitly: an `AmplitudeFollower` tracks the dry signal level,
|
||||
/// the envelope is scaled by `sensitivity` and clamped to `[0, 1]`, then mapped through an
|
||||
/// exponential `LinExp` curve to a cutoff frequency that sweeps a resonant `SVF` bandpass.
|
||||
|
||||
@@ -11,11 +11,13 @@ import LyrebirdUI
|
||||
///
|
||||
/// Signal chain (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry → Compressor.Audio(threshold:, ratio:, attack:, release:, makeupGain:) → mono out
|
||||
/// dry → × inputGain → Compressor.Audio(threshold:, ratio:, attack:, release:, makeupGain:) → mono out
|
||||
/// ```
|
||||
///
|
||||
/// Attack, release, knee, and makeup gain are fixed at musically sensible defaults.
|
||||
/// Knobs expose the two most-musical parameters: threshold and ratio.
|
||||
/// An input gain stage boosts (or cuts) the signal *before* compression, so driving the
|
||||
/// input harder pushes more of the signal past the threshold. Attack, release, knee, and
|
||||
/// makeup gain are fixed at musically sensible defaults; knobs expose input gain, threshold,
|
||||
/// and ratio.
|
||||
///
|
||||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||
///
|
||||
@@ -24,6 +26,8 @@ import LyrebirdUI
|
||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - inputGain: Pre-compression input gain in dB. `0` = unity. Range `[-12, 24]`.
|
||||
/// Defaults to `0.0`.
|
||||
/// - threshold: Gain-reduction threshold in dB. Signals above this level are
|
||||
/// compressed. Range `[-40, 0]` dB. Defaults to `-12.0`.
|
||||
/// - ratio: Compression ratio `≥ 1.0`. `1.0` = bypass, `4.0` = 4:1 compression.
|
||||
@@ -32,6 +36,9 @@ public final class CompressorPedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Pre-compression input gain in dB. Range [-12, 24]. `0` = unity.
|
||||
@UIParam public var inputGain: Double = 0.0
|
||||
|
||||
/// Compression threshold in dB. Range [-40, 0].
|
||||
@UIParam public var threshold: Double = -12.0
|
||||
|
||||
@@ -43,6 +50,10 @@ public final class CompressorPedal: Pedal {
|
||||
/// Default wet/dry blend — fully wet; the compressor is inserted in-line.
|
||||
private static let defaultMix: Double = 1.0
|
||||
|
||||
/// dB → natural-exponent scale, `ln(10) / 20`. `exp(dB · scale) == 10^(dB/20)`, the
|
||||
/// linear amplitude multiplier for a dB gain. Applied to the input-gain stage.
|
||||
private let dbToLinExpScale: Double = 0.115_129_254_649_702_28
|
||||
|
||||
/// Attack time constant in seconds — time to reach full gain reduction on a transient.
|
||||
private let attackTime: Double = 0.01
|
||||
|
||||
@@ -57,6 +68,9 @@ public final class CompressorPedal: Pedal {
|
||||
|
||||
// MARK: - UI knobs
|
||||
|
||||
/// Input-gain knob range in dB.
|
||||
private let inputGainRange: ClosedRange<Double> = -12.0 ... 24.0
|
||||
|
||||
/// Threshold knob range in dB.
|
||||
private let thresholdRange: ClosedRange<Double> = -40.0 ... 0.0
|
||||
|
||||
@@ -65,6 +79,7 @@ public final class CompressorPedal: Pedal {
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Input", node: $inputGain, range: inputGainRange),
|
||||
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
||||
PedalKnob(label: "Ratio", node: $ratio, range: ratioRange),
|
||||
]
|
||||
@@ -91,15 +106,18 @@ public final class CompressorPedal: Pedal {
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Applies feed-forward dynamic range compression.
|
||||
/// Boosts the input by `inputGain` dB, then applies feed-forward dynamic range compression.
|
||||
///
|
||||
/// Output is mono.
|
||||
///
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: Compressed mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
Compressor.Audio(
|
||||
in: dry,
|
||||
// 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(
|
||||
in: boosted,
|
||||
threshold: $threshold,
|
||||
ratio: $ratio,
|
||||
attack: attackTime,
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class DelayPedal: Pedal {
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class FeedbackDelayPedal: Pedal {
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
||||
]
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
// MuTronPedal.swift
|
||||
// MutantPedal.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
@@ -7,7 +7,7 @@
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Envelope-following filter pedal modeled on the Musitronics Mu-Tron III.
|
||||
/// Envelope-following auto-wah / funk-filter pedal.
|
||||
///
|
||||
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
|
||||
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
|
||||
@@ -24,7 +24,7 @@ import LyrebirdUI
|
||||
/// ## Switches
|
||||
/// - `direction` (two-state): `0` = Down (louder closes the filter), `1` = Up (louder opens it).
|
||||
/// - `mode` (three-state): `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass.
|
||||
public final class MuTronPedal: Pedal {
|
||||
public final class MutantPedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
@@ -107,10 +107,10 @@ public final class MuTronPedal: Pedal {
|
||||
|
||||
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||
super.init(
|
||||
name: "Mu-Tron",
|
||||
name: "Mutant",
|
||||
inputBus: inputBus,
|
||||
outputBus: outputBus,
|
||||
initialMix: MuTronPedal.defaultMix
|
||||
initialMix: MutantPedal.defaultMix
|
||||
)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public final class PingPongDelayPedal: Pedal {
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
||||
/// and merging it before calling `loadRig`. The built-in registry covers the factory
|
||||
/// pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser, Compressor,
|
||||
/// Mu-Tron, Auto-Wah, Feedback Delay, Multi-Tap Delay, Octave Splitter, and Ping-Pong.
|
||||
/// Mutant, Auto-Wah, Feedback Delay, Multi-Tap Delay, Octave Splitter, and Ping-Pong.
|
||||
///
|
||||
/// > Note: A saved rig captures each board's *linear* pedal chain only (see `BoardState`).
|
||||
/// > When a registered widener (e.g. Octave Splitter) or stereo-native pedal (e.g.
|
||||
@@ -39,7 +39,7 @@ public enum PedalRegistry {
|
||||
"Tremolo": { TremoloPedal() },
|
||||
"Phaser": { PhaserPedal() },
|
||||
"Compressor": { CompressorPedal() },
|
||||
"Mu-Tron": { MuTronPedal() },
|
||||
"Mutant": { MutantPedal() },
|
||||
"Auto-Wah": { AutoWahPedal() },
|
||||
"Feedback Delay": { FeedbackDelayPedal() },
|
||||
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||
|
||||
@@ -21,7 +21,8 @@ extension ShoeGaze {
|
||||
/// running engine with at most one block of glitch (see ``rebuildBoard(_:from:)``).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: The pedal's `displayName`, e.g. `"Overdrive"`. Must be a key in `PedalRegistry.builtIn`.
|
||||
/// - kind: The pedal type, e.g. ``PedalType/overdrive``. Its `rawValue` must be a key in
|
||||
/// `PedalRegistry.builtIn`.
|
||||
/// - board: The board to edit. Must have been returned by `addBoard()` on this instance.
|
||||
/// - lane: Where to append. Defaults to ``PedalLane/main``.
|
||||
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||
@@ -29,10 +30,11 @@ extension ShoeGaze {
|
||||
/// any error from ``rebuildBoard(_:from:)``.
|
||||
@discardableResult
|
||||
public func appendPedal(
|
||||
type: String,
|
||||
_ kind: PedalType,
|
||||
to board: PedalBoard,
|
||||
lane: PedalLane = .main
|
||||
) throws -> PedalBoard {
|
||||
let type: String = kind.rawValue
|
||||
guard PedalRegistry.builtIn[type] != nil else {
|
||||
throw ShoeGazeError.unknownPedalType(type)
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ import LyrebirdUI
|
||||
///
|
||||
/// ## Input routing
|
||||
///
|
||||
/// When `inputSource == .testLoop`, a `TestLoopSource` is added to the engine
|
||||
/// **before** the first pedal on each board (plain `engine.add` places it at the
|
||||
/// head of `mainGroup`, so it evaluates first).
|
||||
/// When `inputSource == .testLoop`, a **single** shared `TestLoopSource` writes a global
|
||||
/// test bus, and each board gets a `TestLoopTap` (added `.after(_:)` the source) copying that
|
||||
/// bus into the board's head bus. One shared source keeps every board phase-locked and survives
|
||||
/// board add/remove, so the arpeggio never restarts into a polyrhythm.
|
||||
///
|
||||
/// When `inputSource == .liveInput(channel:)`, a `HardwareInputPassThrough` synthesizer
|
||||
/// copies hardware input `channel` (engine bus `numOutputChannels + channel`) to the
|
||||
@@ -96,7 +97,14 @@ public final class ShoeGaze {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var testLoopSources: [TestLoopSource] = []
|
||||
/// The single shared test-loop source feeding every board in `.testLoop` mode, and the bus
|
||||
/// it writes. One global source keeps all boards phase-locked (no per-board polyrhythm) and
|
||||
/// survives board add/remove so its arpeggio never restarts. `nil` outside `.testLoop` mode.
|
||||
private var globalTestSource: TestLoopSource?
|
||||
private var globalTestBus: AudioBus?
|
||||
|
||||
/// Per-board taps copying the global test bus into each board's head bus.
|
||||
private var testLoopTaps: [TestLoopTap] = []
|
||||
private var inputPassThroughs: [HardwareInputPassThrough] = []
|
||||
private var outputMasters: [BoardOutputMaster] = []
|
||||
|
||||
@@ -149,16 +157,19 @@ public final class ShoeGaze {
|
||||
// Route the input source to the board head bus.
|
||||
switch inputSource {
|
||||
case .testLoop:
|
||||
let source: TestLoopSource = TestLoopSource(
|
||||
targetBus: board.headBus.index,
|
||||
sampleRate: engine.sampleRate
|
||||
// All boards share one global test source so they stay phase-locked. Each board
|
||||
// gets a tap copying the shared test bus into its head bus, added `.after(_:)` the
|
||||
// source so it sees the source's output for the current block.
|
||||
let (source, testBus): (TestLoopSource, AudioBus) = try ensureGlobalTestSource()
|
||||
let tap: TestLoopTap = TestLoopTap(
|
||||
inputBusIndex: testBus.index,
|
||||
outputBusIndex: board.headBus.index
|
||||
)
|
||||
// Plain add → head of mainGroup (evaluates before any pedal).
|
||||
try engine.add(source)
|
||||
testLoopSources.append(source)
|
||||
// Record the source as the head input node so PedalBoard.add(_:) can chain
|
||||
// the first pedal after it automatically (without needing an explicit `after:`).
|
||||
board.headInputNode = source
|
||||
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
|
||||
// pedal after it automatically (without needing an explicit `after:`).
|
||||
board.headInputNode = tap
|
||||
|
||||
case .liveInput(let channel):
|
||||
// Hardware input channel `channel` lives at bus numOutputChannels + channel.
|
||||
@@ -181,6 +192,36 @@ public final class ShoeGaze {
|
||||
return board
|
||||
}
|
||||
|
||||
/// Lazily creates the single shared test-loop source and its bus, returning both.
|
||||
///
|
||||
/// Created once per `.testLoop` session and reused by every board's tap, so the arpeggio
|
||||
/// phase is continuous across board add/remove (no per-board polyrhythm). Torn down by
|
||||
/// ``teardown()`` (and thus by ``setInputSource(_:)`` when leaving test-loop mode).
|
||||
///
|
||||
/// The source and bus are committed to `globalTestSource` / `globalTestBus` only after the
|
||||
/// engine add succeeds — if `engine.add` throws, the freshly allocated bus is released so it
|
||||
/// is never orphaned.
|
||||
private func ensureGlobalTestSource() throws -> (source: TestLoopSource, bus: AudioBus) {
|
||||
if let source: TestLoopSource = globalTestSource, let bus: AudioBus = globalTestBus {
|
||||
return (source, bus)
|
||||
}
|
||||
let testBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let source: TestLoopSource = TestLoopSource(
|
||||
targetBus: testBus.index,
|
||||
sampleRate: engine.sampleRate
|
||||
)
|
||||
do {
|
||||
// Plain add → head of mainGroup (evaluates before its taps and any pedal).
|
||||
try engine.add(source)
|
||||
} catch {
|
||||
engine.busAllocator.releaseAudioBus(testBus)
|
||||
throw error
|
||||
}
|
||||
globalTestBus = testBus
|
||||
globalTestSource = source
|
||||
return (source, testBus)
|
||||
}
|
||||
|
||||
/// Connects the output master for a previously prepared board and adds it to the engine.
|
||||
///
|
||||
/// Call this after all pedals have been added to the board via `board.add(_:)`.
|
||||
@@ -261,6 +302,52 @@ public final class ShoeGaze {
|
||||
activeBoardIndex = nil
|
||||
}
|
||||
|
||||
/// Solos `board` exclusively — identical to ``selectBoard(_:crossfadeSeconds:)``.
|
||||
///
|
||||
/// Provided as the "Solo" verb alongside ``setBoard(_:audible:crossfadeSeconds:)`` so
|
||||
/// callers can express *make only this board audible* without conflating it with the
|
||||
/// independent per-board enable used by Blend-style mixing.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - board: The board to solo. No-op if not managed by this instance.
|
||||
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
|
||||
public func soloBoard(_ board: PedalBoard, crossfadeSeconds: Double) {
|
||||
selectBoard(board, crossfadeSeconds: crossfadeSeconds)
|
||||
}
|
||||
|
||||
/// Sets a single board audible or silent **without** disturbing the others.
|
||||
///
|
||||
/// Unlike ``selectBoard(_:crossfadeSeconds:)`` (which is exclusive), this toggles one
|
||||
/// board's select-gain in place, so arbitrary subsets of boards can play at once — the
|
||||
/// "Blend" mixing model. Because the audible set is no longer a single soloed board,
|
||||
/// ``activeBoardIndex`` is cleared to `nil`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - board: The board to enable or silence. No-op if not managed by this instance.
|
||||
/// - audible: `true` to fade the board in, `false` to fade it out.
|
||||
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
|
||||
public func setBoard(_ board: PedalBoard, audible: Bool, crossfadeSeconds: Double) {
|
||||
guard boards.contains(where: { $0 === board }) else { return }
|
||||
board.crossfadeTimeNode?.update(crossfadeSeconds)
|
||||
board.selectGainNode?.update(audible ? 1.0 : 0.0)
|
||||
activeBoardIndex = nil
|
||||
}
|
||||
|
||||
/// Whether `board`'s output is currently audible (its select-gain target is on).
|
||||
///
|
||||
/// Reads the live select-gain target, so it reflects the latest
|
||||
/// ``selectBoard(_:crossfadeSeconds:)`` / ``setBoard(_:audible:crossfadeSeconds:)`` /
|
||||
/// ``selectAllBoards(crossfadeSeconds:)`` call (the value the crossfade is ramping
|
||||
/// toward), independent of where the crossfade currently sits.
|
||||
///
|
||||
/// - Parameter board: A board managed by this instance.
|
||||
/// - Returns: `true` when the board's select-gain target is on; `false` when silenced
|
||||
/// or when the board has no output master yet.
|
||||
public func isBoardAudible(_ board: PedalBoard) -> Bool {
|
||||
let selectGainOnThreshold: Double = 0.5
|
||||
return (board.selectGainNode?.value ?? 0.0) > selectGainOnThreshold
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
@@ -287,10 +374,12 @@ public final class ShoeGaze {
|
||||
outputMasters.removeAll { $0 === master }
|
||||
}
|
||||
|
||||
// Remove the board's input source (writer of the head bus).
|
||||
if let testLoop: TestLoopSource = board.headInputNode as? TestLoopSource {
|
||||
engine.remove(testLoop)
|
||||
testLoopSources.removeAll { $0 === testLoop }
|
||||
// Remove the board's input node (writer of the head bus). In `.testLoop` mode this is a
|
||||
// tap; the shared global source is left running so the remaining boards keep their
|
||||
// phase-locked test signal.
|
||||
if let tap: TestLoopTap = board.headInputNode as? TestLoopTap {
|
||||
engine.remove(tap)
|
||||
testLoopTaps.removeAll { $0 === tap }
|
||||
} else if let passThrough: HardwareInputPassThrough = board.headInputNode as? HardwareInputPassThrough {
|
||||
engine.remove(passThrough)
|
||||
inputPassThroughs.removeAll { $0 === passThrough }
|
||||
@@ -299,6 +388,16 @@ public final class ShoeGaze {
|
||||
// Remove the pedals and release the board's buses.
|
||||
board.teardown()
|
||||
boards.remove(at: index)
|
||||
|
||||
// Keep the soloed-board index valid: clear it if the soloed board was removed,
|
||||
// otherwise shift it down when a board before it was removed.
|
||||
if let active: Int = activeBoardIndex {
|
||||
if active == index {
|
||||
activeBoardIndex = nil
|
||||
} else if active > index {
|
||||
activeBoardIndex = active - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Chain router
|
||||
@@ -321,6 +420,13 @@ public final class ShoeGaze {
|
||||
/// try engine.start()
|
||||
/// ```
|
||||
///
|
||||
/// > Note: In `.testLoop` mode a `ChainRouter` allocates **its own** test source (shared by
|
||||
/// > the router's two boards via the splitter, so those two stay phase-locked to each other).
|
||||
/// > That source is independent of the global test source used by ``addBoard()``-created
|
||||
/// > boards, so a router's boards are *not* phase-locked to the main board list. Routers are
|
||||
/// > a separate multi-board path (not used by the standard builder UI); unifying them onto the
|
||||
/// > global source is intentionally out of scope here.
|
||||
///
|
||||
/// - Returns: A ``ChainRouter`` with both boards ready to receive pedals.
|
||||
/// - Throws:
|
||||
/// - `ShoeGazeError.liveInputRequiresInputChannels` when `inputSource == .liveInput`
|
||||
@@ -339,18 +445,26 @@ public final class ShoeGaze {
|
||||
/// Moves `board` to `targetIndex` within `boards`, locating it by identity.
|
||||
///
|
||||
/// This is an internal helper that mutates `boards` directly — valid only because
|
||||
/// `ShoeGaze` is `@MainActor` (no concurrent access). The method is `internal` rather than
|
||||
/// `public` so callers outside the ShoeGaze module cannot disrupt board ordering.
|
||||
/// `ShoeGaze` is `@MainActor` (no concurrent access). Reordering only permutes the
|
||||
/// `boards` array; it does not touch the engine graph, so it is safe to call while the
|
||||
/// engine is running.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - board: The `PedalBoard` to reposition. No-op if not found in `boards`.
|
||||
/// - index: The desired destination index. Clamped to `boards.count` after removal
|
||||
/// so it is always a valid insertion point.
|
||||
internal func moveBoard(_ board: PedalBoard, to index: Int) {
|
||||
public func moveBoard(_ board: PedalBoard, to index: Int) {
|
||||
guard let sourceIndex: Int = boards.firstIndex(where: { $0 === board }) else { return }
|
||||
// Track the soloed board by identity so its index follows the reorder.
|
||||
let soloedBoard: PedalBoard? = activeBoardIndex.flatMap { idx in
|
||||
idx < boards.count ? boards[idx] : nil
|
||||
}
|
||||
let removed: PedalBoard = boards.remove(at: sourceIndex)
|
||||
let destination: Int = min(index, boards.count)
|
||||
boards.insert(removed, at: destination)
|
||||
if let soloedBoard {
|
||||
activeBoardIndex = boards.firstIndex(where: { $0 === soloedBoard })
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Teardown
|
||||
@@ -376,10 +490,21 @@ public final class ShoeGaze {
|
||||
|
||||
// Step 1: Remove all engine nodes that write to board buses.
|
||||
// Order within this step does not matter; all must finish before bus release.
|
||||
for source: TestLoopSource in testLoopSources {
|
||||
for tap: TestLoopTap in testLoopTaps {
|
||||
engine.remove(tap)
|
||||
}
|
||||
testLoopTaps.removeAll()
|
||||
|
||||
// Remove the shared global test source and release its bus (after its taps are removed,
|
||||
// preserving remove-before-release ordering).
|
||||
if let source: TestLoopSource = globalTestSource {
|
||||
engine.remove(source)
|
||||
}
|
||||
testLoopSources.removeAll()
|
||||
globalTestSource = nil
|
||||
if let testBus: AudioBus = globalTestBus {
|
||||
engine.busAllocator.releaseAudioBus(testBus)
|
||||
}
|
||||
globalTestBus = nil
|
||||
|
||||
for passThrough: HardwareInputPassThrough in inputPassThroughs {
|
||||
engine.remove(passThrough)
|
||||
|
||||
@@ -48,8 +48,8 @@ public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable {
|
||||
/// Narrow the chain with `mergeToMono()` before adding another widener.
|
||||
case stereoWidthExceeded
|
||||
|
||||
/// Thrown by the linear pedal-edit API (`appendPedal(type:to:)`) when `type` is not a
|
||||
/// known pedal in `PedalRegistry.builtIn`. The associated value is the requested type string.
|
||||
/// Thrown by the linear pedal-edit API (`appendPedal(_:to:)`) when the kind's `rawValue` is
|
||||
/// not a known pedal in `PedalRegistry.builtIn`. The associated value is the requested type string.
|
||||
case unknownPedalType(String)
|
||||
|
||||
/// Thrown by `removePedal(at:from:)` / `movePedal(from:to:in:)` when a linear pedal index is
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
// BoardBarView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
import LyrebirdUI
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
/// A horizontal board-mixer strip for switching between, or blending, multiple `PedalBoard`s.
|
||||
///
|
||||
/// Each board is a channel cell with an audible LED, a Solo button, and a level fader (the
|
||||
/// board's master gain). A leading **Solo / Blend** mode switch chooses the interaction:
|
||||
///
|
||||
/// - **Solo** — tapping a cell's LED makes that board the only audible one
|
||||
/// (``ShoeGaze/soloBoard(_:crossfadeSeconds:)``); the **All** button returns to the
|
||||
/// summed state (``ShoeGaze/selectAllBoards(crossfadeSeconds:)``). Amp-channel feel.
|
||||
/// - **Blend** — tapping a cell's LED toggles that board in or out of the mix
|
||||
/// independently (``ShoeGaze/setBoard(_:audible:crossfadeSeconds:)``), so any subset can
|
||||
/// play at once — the default summed behaviour, now controllable per board.
|
||||
///
|
||||
/// Tapping a cell's **name** selects it as the edit target (`editingBoardIndex`), which is
|
||||
/// independent of what is audible — you can audition one board while editing another. A
|
||||
/// cell's context menu deletes the board.
|
||||
///
|
||||
/// The same view serves macOS and iOS; on iOS the cell row scrolls horizontally and the
|
||||
/// context-menu delete is reached by long-press.
|
||||
public struct BoardBarView: View {
|
||||
|
||||
// MARK: - Play mode
|
||||
|
||||
/// How a cell's LED tap maps to board audibility.
|
||||
private enum PlayMode: Hashable {
|
||||
/// Tapping a board solos it exclusively.
|
||||
case solo
|
||||
/// Tapping a board toggles it independently in/out of the mix.
|
||||
case blend
|
||||
}
|
||||
|
||||
// MARK: - Layout constants
|
||||
|
||||
private static let barSpacing: CGFloat = 10
|
||||
private static let barHeight: CGFloat = 92
|
||||
private static let cellSpacing: CGFloat = 8
|
||||
private static let cellWidth: CGFloat = 104
|
||||
private static let cellInnerSpacing: CGFloat = 5
|
||||
private static let cellPadding: CGFloat = 7
|
||||
private static let cellCornerRadius: CGFloat = 8
|
||||
private static let controlColumnWidth: CGFloat = 188
|
||||
private static let modePickerWidth: CGFloat = 104
|
||||
private static let crossfadeSliderMinWidth: CGFloat = 64
|
||||
private static let ledDiameter: CGFloat = 12
|
||||
private static let ledGlowRadius: CGFloat = 6
|
||||
private static let ledGlowOpacity: Double = 0.75
|
||||
private static let ledDimBrightness: Double = 0.16
|
||||
private static let ledRimOpacity: Double = 0.30
|
||||
private static let soloButtonSize: CGFloat = 22
|
||||
private static let editingBorderWidth: CGFloat = 2
|
||||
private static let idleBorderOpacity: Double = 0.18
|
||||
private static let cellBackgroundBrightness: Double = 0.14
|
||||
private static let labelOpacity: Double = 0.65
|
||||
private static let nameFontSize: CGFloat = 12
|
||||
private static let maxCrossfadeSeconds: Double = 10.0
|
||||
private static let crossfadeStep: Double = 0.1
|
||||
private static let addButtonSize: CGFloat = 30
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let shoeGaze: ShoeGaze
|
||||
@Binding private var editingBoardIndex: Int
|
||||
@Binding private var crossfadeSeconds: Double
|
||||
private let onAddBoard: () -> Void
|
||||
|
||||
@State private var mode: PlayMode = .solo
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a board-mixer bar.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - shoeGaze: The manager whose `boards` are switched / blended.
|
||||
/// - editingBoardIndex: The index of the board currently being edited (a cell's name
|
||||
/// tap writes this).
|
||||
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
|
||||
/// - onAddBoard: Called when the trailing **+** button is tapped.
|
||||
public init(
|
||||
shoeGaze: ShoeGaze,
|
||||
editingBoardIndex: Binding<Int>,
|
||||
crossfadeSeconds: Binding<Double>,
|
||||
onAddBoard: @escaping () -> Void
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self._editingBoardIndex = editingBoardIndex
|
||||
self._crossfadeSeconds = crossfadeSeconds
|
||||
self.onAddBoard = onAddBoard
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
// One horizontal scroll group so the whole bar hugs its content and stays a short,
|
||||
// fixed-height band — leaving the canvas below for the pedals.
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .center, spacing: BoardBarView.barSpacing) {
|
||||
controlColumn
|
||||
Divider().overlay(Color.white.opacity(BoardBarView.idleBorderOpacity))
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||
boardCell(index: pair.offset, board: pair.element)
|
||||
}
|
||||
addButton
|
||||
}
|
||||
.frame(height: BoardBarView.barHeight)
|
||||
}
|
||||
.frame(height: BoardBarView.barHeight)
|
||||
}
|
||||
|
||||
// MARK: - Control column
|
||||
|
||||
private var controlColumn: some View {
|
||||
VStack(alignment: .leading, spacing: BoardBarView.cellInnerSpacing) {
|
||||
HStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||
Picker("Mode", selection: $mode) {
|
||||
Text("Solo").tag(PlayMode.solo)
|
||||
Text("Blend").tag(PlayMode.blend)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
.frame(width: BoardBarView.modePickerWidth)
|
||||
|
||||
Button("All") {
|
||||
shoeGaze.selectAllBoards(crossfadeSeconds: clampedCrossfade)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(.orange)
|
||||
.help("Play all boards (summed)")
|
||||
}
|
||||
|
||||
HStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||
Text("XFade")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||
Slider(
|
||||
value: $crossfadeSeconds,
|
||||
in: 0 ... BoardBarView.maxCrossfadeSeconds,
|
||||
step: BoardBarView.crossfadeStep
|
||||
)
|
||||
.frame(minWidth: BoardBarView.crossfadeSliderMinWidth)
|
||||
Text(String(format: "%.1fs", clampedCrossfade))
|
||||
.font(.caption2)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||
}
|
||||
}
|
||||
.frame(width: BoardBarView.controlColumnWidth)
|
||||
}
|
||||
|
||||
// MARK: - Board cell
|
||||
|
||||
@ViewBuilder
|
||||
private func boardCell(index: Int, board: PedalBoard) -> some View {
|
||||
let isEditing: Bool = index == editingBoardIndex
|
||||
let isAudible: Bool = shoeGaze.isBoardAudible(board)
|
||||
let isSoloed: Bool = shoeGaze.activeBoardIndex == index
|
||||
|
||||
VStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||
Text(boardLabel(index: index, board: board))
|
||||
.font(.system(size: BoardBarView.nameFontSize, weight: .semibold))
|
||||
.foregroundStyle(Color.white)
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: .infinity)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { editingBoardIndex = index }
|
||||
|
||||
HStack(spacing: BoardBarView.cellSpacing) {
|
||||
ledButton(board: board, isAudible: isAudible)
|
||||
soloButton(board: board, isSoloed: isSoloed)
|
||||
}
|
||||
|
||||
levelFader(board: board)
|
||||
}
|
||||
.padding(BoardBarView.cellPadding)
|
||||
.frame(width: BoardBarView.cellWidth)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||
.fill(Color(white: BoardBarView.cellBackgroundBrightness))
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||
.stroke(
|
||||
isEditing ? Color.orange : Color.white.opacity(BoardBarView.idleBorderOpacity),
|
||||
lineWidth: isEditing ? BoardBarView.editingBorderWidth : 1
|
||||
)
|
||||
)
|
||||
.contextMenu {
|
||||
Button("Edit This Board") { editingBoardIndex = index }
|
||||
Button(isAudible ? "Silence" : "Enable") {
|
||||
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||
}
|
||||
Divider()
|
||||
Button("Delete Board", role: .destructive) {
|
||||
shoeGaze.removeBoard(board)
|
||||
clampEditingIndex()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The audible LED — tap behaviour depends on the current ``PlayMode``.
|
||||
private func ledButton(board: PedalBoard, isAudible: Bool) -> some View {
|
||||
Button {
|
||||
switch mode {
|
||||
case .solo:
|
||||
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||
case .blend:
|
||||
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||
}
|
||||
} label: {
|
||||
ZStack {
|
||||
if isAudible {
|
||||
Circle()
|
||||
.fill(Color.green.opacity(BoardBarView.ledGlowOpacity))
|
||||
.frame(
|
||||
width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
|
||||
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius
|
||||
)
|
||||
.blur(radius: BoardBarView.ledGlowRadius / 2)
|
||||
}
|
||||
Circle()
|
||||
.fill(isAudible ? Color.green : Color(white: BoardBarView.ledDimBrightness))
|
||||
.frame(width: BoardBarView.ledDiameter, height: BoardBarView.ledDiameter)
|
||||
.overlay(
|
||||
Circle().stroke(Color.white.opacity(BoardBarView.ledRimOpacity), lineWidth: 0.5)
|
||||
)
|
||||
}
|
||||
.frame(width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
|
||||
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help(mode == .solo ? "Solo this board" : (isAudible ? "Silence this board" : "Add this board to the mix"))
|
||||
}
|
||||
|
||||
/// Exclusive solo button — lit when this board is the soloed one.
|
||||
private func soloButton(board: PedalBoard, isSoloed: Bool) -> some View {
|
||||
Button {
|
||||
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||
} label: {
|
||||
Text("S")
|
||||
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
|
||||
.foregroundStyle(isSoloed ? Color.black : Color.white)
|
||||
.frame(width: BoardBarView.soloButtonSize, height: BoardBarView.soloButtonSize)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 4)
|
||||
.fill(isSoloed ? Color.yellow : Color(white: BoardBarView.ledDimBrightness))
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help("Solo this board (exclusive)")
|
||||
}
|
||||
|
||||
/// Board master-gain fader. Hidden until the board's output master is connected.
|
||||
@ViewBuilder
|
||||
private func levelFader(board: PedalBoard) -> some View {
|
||||
if let gainNode: UIParamNode = board.masterGainNode {
|
||||
Slider(
|
||||
value: Binding(
|
||||
get: { gainNode.value },
|
||||
set: { gainNode.update($0) }
|
||||
),
|
||||
in: 0.0 ... 1.0
|
||||
)
|
||||
.controlSize(.mini)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Add button
|
||||
|
||||
private var addButton: some View {
|
||||
Button(action: onAddBoard) {
|
||||
Image(systemName: "plus")
|
||||
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
|
||||
.foregroundStyle(Color.white)
|
||||
.frame(width: BoardBarView.addButtonSize, height: BoardBarView.addButtonSize)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||
.stroke(Color.white.opacity(BoardBarView.idleBorderOpacity), lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help("Add a board")
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
/// Display label for a board, falling back to a 1-based position when unnamed.
|
||||
private func boardLabel(index: Int, board: PedalBoard) -> String {
|
||||
board.label.isEmpty ? "Board \(index + 1)" : board.label
|
||||
}
|
||||
|
||||
/// `crossfadeSeconds` clamped to the supported range.
|
||||
private var clampedCrossfade: Double {
|
||||
min(max(crossfadeSeconds, 0.0), BoardBarView.maxCrossfadeSeconds)
|
||||
}
|
||||
|
||||
/// Keeps the edit target valid after a delete.
|
||||
private func clampEditingIndex() {
|
||||
let count: Int = shoeGaze.boards.count
|
||||
guard count > 0 else { editingBoardIndex = 0; return }
|
||||
editingBoardIndex = min(editingBoardIndex, count - 1)
|
||||
}
|
||||
}
|
||||
@@ -443,7 +443,7 @@ public struct BoardFlowView: View {
|
||||
|
||||
private func append(type: String, lane: PedalLane) {
|
||||
guard let board: PedalBoard = board else { return }
|
||||
do { _ = try shoeGaze.appendPedal(type: type, to: board, lane: lane) }
|
||||
do { _ = try shoeGaze.appendPedal(PedalType(type), to: board, lane: lane) }
|
||||
catch { print("[BoardFlowView] appendPedal failed: \(error)") }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
// BoardsSheetView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
import LyrebirdUI
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
/// A full board manager presented as a sheet — the richer companion to the inline
|
||||
/// ``BoardBarView``.
|
||||
///
|
||||
/// Each board is a `List` row with an audible toggle, a Solo button, a master-gain fader, an
|
||||
/// inline rename field, and an "Edit" action that selects it as the builder's edit target and
|
||||
/// dismisses. Rows reorder by drag (`.onMove`) and delete by swipe (`.onDelete`). A header
|
||||
/// pairs the **Solo / Blend** mode switch with the crossfade slider, mirroring the board bar.
|
||||
///
|
||||
/// Primarily used on iOS/iPadOS (presented with `.presentationDetents`) where the inline bar
|
||||
/// has no room for rename / reorder, but the view is platform-neutral.
|
||||
public struct BoardsSheetView: View {
|
||||
|
||||
// MARK: - Play mode
|
||||
|
||||
private enum PlayMode: Hashable {
|
||||
case solo
|
||||
case blend
|
||||
}
|
||||
|
||||
// MARK: - Layout constants
|
||||
|
||||
private static let rowSpacing: CGFloat = 12
|
||||
private static let faderWidth: CGFloat = 120
|
||||
private static let soloButtonSize: CGFloat = 28
|
||||
private static let ledDiameter: CGFloat = 14
|
||||
private static let ledDimBrightness: Double = 0.16
|
||||
private static let ledRimOpacity: Double = 0.30
|
||||
private static let maxCrossfadeSeconds: Double = 10.0
|
||||
private static let crossfadeStep: Double = 0.1
|
||||
private static let headerSpacing: CGFloat = 10
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let shoeGaze: ShoeGaze
|
||||
@Binding private var editingBoardIndex: Int
|
||||
@Binding private var crossfadeSeconds: Double
|
||||
private let onAddBoard: () -> Void
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var mode: PlayMode = .solo
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a board-manager sheet.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - shoeGaze: The manager whose `boards` are edited.
|
||||
/// - editingBoardIndex: The builder's edit target; a row's "Edit" action sets this.
|
||||
/// - crossfadeSeconds: Crossfade duration applied to switches / toggles.
|
||||
/// - onAddBoard: Called when the **Add Board** button is tapped.
|
||||
public init(
|
||||
shoeGaze: ShoeGaze,
|
||||
editingBoardIndex: Binding<Int>,
|
||||
crossfadeSeconds: Binding<Double>,
|
||||
onAddBoard: @escaping () -> Void
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self._editingBoardIndex = editingBoardIndex
|
||||
self._crossfadeSeconds = crossfadeSeconds
|
||||
self.onAddBoard = onAddBoard
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
NavigationStack {
|
||||
VStack(spacing: BoardsSheetView.headerSpacing) {
|
||||
header
|
||||
List {
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||
boardRow(index: pair.offset, board: pair.element)
|
||||
}
|
||||
.onMove(perform: moveBoards)
|
||||
.onDelete(perform: deleteBoards)
|
||||
}
|
||||
}
|
||||
.padding(.top, BoardsSheetView.headerSpacing)
|
||||
.navigationTitle("Boards")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Done") { dismiss() }
|
||||
}
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Button {
|
||||
onAddBoard()
|
||||
} label: {
|
||||
Label("Add Board", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Header
|
||||
|
||||
private var header: some View {
|
||||
HStack(spacing: BoardsSheetView.headerSpacing) {
|
||||
Picker("Mode", selection: $mode) {
|
||||
Text("Solo").tag(PlayMode.solo)
|
||||
Text("Blend").tag(PlayMode.blend)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.frame(maxWidth: 180)
|
||||
|
||||
Button("All") {
|
||||
shoeGaze.selectAllBoards(crossfadeSeconds: clampedCrossfade)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("XFade")
|
||||
Slider(
|
||||
value: $crossfadeSeconds,
|
||||
in: 0 ... BoardsSheetView.maxCrossfadeSeconds,
|
||||
step: BoardsSheetView.crossfadeStep
|
||||
)
|
||||
.frame(width: BoardsSheetView.faderWidth)
|
||||
Text(String(format: "%.1fs", clampedCrossfade))
|
||||
.monospacedDigit()
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
// MARK: - Board row
|
||||
|
||||
@ViewBuilder
|
||||
private func boardRow(index: Int, board: PedalBoard) -> some View {
|
||||
let isAudible: Bool = shoeGaze.isBoardAudible(board)
|
||||
let isSoloed: Bool = shoeGaze.activeBoardIndex == index
|
||||
|
||||
HStack(spacing: BoardsSheetView.rowSpacing) {
|
||||
ledButton(board: board, isAudible: isAudible)
|
||||
soloButton(board: board, isSoloed: isSoloed)
|
||||
|
||||
TextField(
|
||||
"Board \(index + 1)",
|
||||
text: Binding(
|
||||
get: { board.label },
|
||||
set: { board.label = $0 }
|
||||
)
|
||||
)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
|
||||
if let gainNode: UIParamNode = board.masterGainNode {
|
||||
Slider(
|
||||
value: Binding(
|
||||
get: { gainNode.value },
|
||||
set: { gainNode.update($0) }
|
||||
),
|
||||
in: 0.0 ... 1.0
|
||||
)
|
||||
.frame(width: BoardsSheetView.faderWidth)
|
||||
}
|
||||
|
||||
Button("Edit") {
|
||||
editingBoardIndex = index
|
||||
dismiss()
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
|
||||
private func ledButton(board: PedalBoard, isAudible: Bool) -> some View {
|
||||
Button {
|
||||
switch mode {
|
||||
case .solo:
|
||||
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||
case .blend:
|
||||
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||
}
|
||||
} label: {
|
||||
Circle()
|
||||
.fill(isAudible ? Color.green : Color(white: BoardsSheetView.ledDimBrightness))
|
||||
.frame(width: BoardsSheetView.ledDiameter, height: BoardsSheetView.ledDiameter)
|
||||
.overlay(
|
||||
Circle().stroke(Color.white.opacity(BoardsSheetView.ledRimOpacity), lineWidth: 0.5)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func soloButton(board: PedalBoard, isSoloed: Bool) -> some View {
|
||||
Button {
|
||||
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||
} label: {
|
||||
Text("S")
|
||||
.font(.system(size: 13, weight: .bold))
|
||||
.foregroundStyle(isSoloed ? Color.black : Color.primary)
|
||||
.frame(width: BoardsSheetView.soloButtonSize, height: BoardsSheetView.soloButtonSize)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 5)
|
||||
.fill(isSoloed ? Color.yellow : Color.secondary.opacity(0.2))
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
// MARK: - Mutations
|
||||
|
||||
/// Reorders boards, translating SwiftUI's `onMove` offsets to `ShoeGaze.moveBoard`.
|
||||
private func moveBoards(from source: IndexSet, to destination: Int) {
|
||||
// List drag delivers a single source row; ignore any multi-selection move so a
|
||||
// dropped row can never desync `shoeGaze.boards` from the displayed order.
|
||||
guard source.count == 1, let sourceIndex: Int = source.first else { return }
|
||||
let board: PedalBoard = shoeGaze.boards[sourceIndex]
|
||||
// SwiftUI's destination is the insertion point in the pre-move list; moveBoard
|
||||
// removes first, so shift down by one when moving forward.
|
||||
let target: Int = destination > sourceIndex ? destination - 1 : destination
|
||||
shoeGaze.moveBoard(board, to: target)
|
||||
clampEditingIndex()
|
||||
}
|
||||
|
||||
private func deleteBoards(_ offsets: IndexSet) {
|
||||
for index: Int in offsets.sorted(by: >) where index < shoeGaze.boards.count {
|
||||
shoeGaze.removeBoard(shoeGaze.boards[index])
|
||||
}
|
||||
clampEditingIndex()
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private var clampedCrossfade: Double {
|
||||
min(max(crossfadeSeconds, 0.0), BoardsSheetView.maxCrossfadeSeconds)
|
||||
}
|
||||
|
||||
private func clampEditingIndex() {
|
||||
let count: Int = shoeGaze.boards.count
|
||||
guard count > 0 else { editingBoardIndex = 0; return }
|
||||
editingBoardIndex = min(editingBoardIndex, count - 1)
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,16 @@ public struct EngineConfigView: View {
|
||||
} message: {
|
||||
Text(alertText)
|
||||
}
|
||||
// Resync the pending fields whenever the engine is rebuilt out from under this view (e.g.
|
||||
// the iOS live-input rebuild swaps in a new engine with a different input-channel count).
|
||||
// Keyed on the engine's object identity so it re-runs on every swap; the @State initial
|
||||
// values are seeded only once, so without this the stepper would keep showing the old
|
||||
// engine's channel counts even though audio reads the new one.
|
||||
.task(id: ObjectIdentifier(shoeGaze.engine)) {
|
||||
pendingSampleRate = shoeGaze.engine.sampleRate
|
||||
pendingInputs = shoeGaze.engine.numInputChannels
|
||||
pendingOutputs = shoeGaze.engine.numOutputChannels
|
||||
}
|
||||
}
|
||||
|
||||
private func label(_ text: String) -> some View {
|
||||
|
||||
@@ -11,7 +11,7 @@ import LyrebirdShoeGaze
|
||||
/// options, sized to sit in a narrow left sidebar.
|
||||
///
|
||||
/// The pedal rows are tappable: selecting one invokes `onAdd(type)` with the pedal's
|
||||
/// `displayName`, which the host wires to `ShoeGaze.appendPedal(type:to:)`. The routing cards
|
||||
/// `displayName`, which the host wraps in a `PedalType` for `ShoeGaze.appendPedal(_:to:)`. The routing cards
|
||||
/// (Parallel split, Stereo split, Chain router, Merge to mono) are informational only — they
|
||||
/// describe the topologies the engine supports, which are built programmatically rather than via
|
||||
/// linear add (see ``BoardBuilderView`` for the read-only display of existing branches).
|
||||
@@ -20,7 +20,7 @@ import LyrebirdShoeGaze
|
||||
///
|
||||
/// ```swift
|
||||
/// PedalPaletteView { type in
|
||||
/// try? shoeGaze.appendPedal(type: type, to: board)
|
||||
/// try? shoeGaze.appendPedal(PedalType(type), to: board)
|
||||
/// }
|
||||
/// ```
|
||||
public struct PedalPaletteView: View {
|
||||
@@ -47,7 +47,7 @@ public struct PedalPaletteView: View {
|
||||
private static let preferredOrder: [String] = [
|
||||
"Overdrive", "Compressor", "Limiter", "Noise Gate", "Fuzz",
|
||||
"Graphic EQ", "Tremolo", "Phaser", "Modulation",
|
||||
"Auto-Wah", "Mu-Tron", "Bass Octaver", "Octave Splitter",
|
||||
"Auto-Wah", "Mutant", "Bass Octaver", "Octave Splitter",
|
||||
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
||||
]
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ private func enclosureColor(for displayName: String) -> Color {
|
||||
case "Tremolo": return Color(red: 0.20, green: 0.38, blue: 0.72) // cobalt blue
|
||||
case "Phaser": return Color(red: 0.60, green: 0.22, blue: 0.62) // violet
|
||||
case "Compressor": return Color(red: 0.18, green: 0.42, blue: 0.32) // forest green
|
||||
case "Mu-Tron": return Color(red: 0.70, green: 0.12, blue: 0.48) // magenta / plum
|
||||
case "Mutant": return Color(red: 0.70, green: 0.12, blue: 0.48) // magenta / plum
|
||||
case "Auto-Wah": return Color(red: 0.80, green: 0.62, blue: 0.10) // gold
|
||||
case "Feedback Delay": return Color(red: 0.48, green: 0.30, blue: 0.14) // tape sepia
|
||||
case "Multi-Tap Delay": return Color(red: 0.08, green: 0.48, blue: 0.68) // cyan
|
||||
@@ -187,6 +187,9 @@ public struct PedalView: View {
|
||||
private static let screwInset: CGFloat = 6
|
||||
private static let knobColumnCount: Int = 3
|
||||
private static let knobSpacing: CGFloat = 10
|
||||
/// Horizontal gap between knobs within a row. Wider than `knobSpacing` so centred
|
||||
/// rows keep a comfortable, touch-friendly gap between adjacent knobs.
|
||||
private static let knobRowItemSpacing: CGFloat = 24
|
||||
/// Horizontal gap between adjacent vertical faders in the slider bank.
|
||||
private static let sliderBankSpacing: CGFloat = 4
|
||||
/// Approximate per-fader footprint (matches `VerticalParameterSlider.controlWidth`),
|
||||
@@ -313,18 +316,22 @@ public struct PedalView: View {
|
||||
return VStack(spacing: PedalView.knobSpacing) {
|
||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||
let row: [PedalKnob] = rowPair.element
|
||||
HStack(spacing: PedalView.knobSpacing) {
|
||||
// Centre each row: a short row (one or two knobs) sits centred in the
|
||||
// enclosure rather than left-aligned. Symmetric spacers also centre a full
|
||||
// three-knob row, so every row stays horizontally centred.
|
||||
// A full three-knob row keeps the tight spacing so it fits the enclosure;
|
||||
// shorter centred rows use a wider, touch-friendly gap.
|
||||
let rowItemSpacing: CGFloat = row.count >= PedalView.knobColumnCount
|
||||
? PedalView.knobSpacing
|
||||
: PedalView.knobRowItemSpacing
|
||||
HStack(spacing: rowItemSpacing) {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
||||
let knob: PedalKnob = knobPair.element
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
// Pad short rows so knobs stay aligned in their columns.
|
||||
if row.count < PedalView.knobColumnCount {
|
||||
ForEach(0 ..< (PedalView.knobColumnCount - row.count), id: \.self) { _ in
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,12 @@ 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.
|
||||
private static let maxBoardShortcuts: Int = 9
|
||||
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||
private static let recordDotSize: CGFloat = 9
|
||||
private static let folderLabelOpacity: Double = 0.55
|
||||
@@ -57,15 +63,30 @@ public struct ShoeGazeBuilderView: View {
|
||||
private let shoeGaze: ShoeGaze
|
||||
private let hardwareSampleRate: () -> Double?
|
||||
|
||||
/// Host hook to enable live input when the current engine has no input channel (iOS).
|
||||
/// The host requests microphone access and rebuilds the engine with one input channel,
|
||||
/// preserving the rig, then swaps in a new `ShoeGaze`. `nil` on platforms (macOS) whose
|
||||
/// engine already exposes an input channel, where live input is selected directly.
|
||||
private let onEnableLiveInput: (() -> Void)?
|
||||
|
||||
/// Index of the board currently being edited.
|
||||
@State private var selectedBoardIndex: Int = 0
|
||||
|
||||
/// Crossfade duration (seconds) applied to board switches in the board bar.
|
||||
@State private var crossfadeSeconds: Double = 0.3
|
||||
|
||||
/// Bumped on transport/edit actions to force a re-read of `engine.isRunning`.
|
||||
@State private var transportTick: Bool = false
|
||||
|
||||
/// Shown when live input is selected but microphone access is denied/restricted.
|
||||
@State private var showMicDeniedAlert: Bool = false
|
||||
|
||||
/// Guards the one-time input-source restore in `.onAppear`.
|
||||
@State private var didRestoreInput: Bool = false
|
||||
|
||||
/// Presentation flag for the board-manager sheet (rename / reorder / delete).
|
||||
@State private var showBoardsSheet: Bool = false
|
||||
|
||||
#if !os(macOS)
|
||||
/// iOS file-dialog presentation flags + the document to export. (macOS uses the File menu.)
|
||||
@State private var showImporter: Bool = false
|
||||
@@ -84,12 +105,19 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// create at least one board before presenting this view.
|
||||
/// - hardwareSampleRate: Returns the actual hardware/session sample rate (or `nil`), used by
|
||||
/// the engine-config Start to warn on a mismatch. Defaults to `nil`.
|
||||
/// - onEnableLiveInput: Host hook invoked when the user requests live input but the engine
|
||||
/// has no input channel (iOS). The host should request microphone access, rebuild the
|
||||
/// engine with one input channel (preserving the rig), and select live input. Defaults to
|
||||
/// `nil` — on macOS the engine already has an input channel, so live input is selected
|
||||
/// directly without a rebuild.
|
||||
public init(
|
||||
shoeGaze: ShoeGaze,
|
||||
hardwareSampleRate: @escaping () -> Double? = { nil }
|
||||
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||
onEnableLiveInput: (() -> Void)? = nil
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self.hardwareSampleRate = hardwareSampleRate
|
||||
self.onEnableLiveInput = onEnableLiveInput
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
@@ -102,14 +130,24 @@ public struct ShoeGazeBuilderView: View {
|
||||
recordingRow
|
||||
#endif
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
BoardBarView(
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
)
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
|
||||
paletteSidebar
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
boardArea
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
// Scope + CPU meters sit under the pedal palette, matching its width.
|
||||
ShoeGazeScopeView(shoeGaze: shoeGaze)
|
||||
.frame(width: ShoeGazeBuilderView.sidebarWidth, alignment: .leading)
|
||||
LyrebirdStatusView(engine: shoeGaze.engine)
|
||||
.frame(width: ShoeGazeBuilderView.sidebarWidth, alignment: .leading)
|
||||
}
|
||||
.padding(ShoeGazeBuilderView.outerPadding)
|
||||
.frame(minWidth: ShoeGazeBuilderView.minWidth, minHeight: ShoeGazeBuilderView.minHeight)
|
||||
@@ -120,6 +158,12 @@ public struct ShoeGazeBuilderView: View {
|
||||
blue: ShoeGazeBuilderView.backgroundBlue
|
||||
)
|
||||
)
|
||||
.background(boardSwitchShortcuts)
|
||||
.onAppear { restoreInputSelection() }
|
||||
// Each presentation (sheet / importers / exporter / alert) lives on its own anchor
|
||||
// node. SwiftUI reliably drives only one presentation per view node, so stacking them
|
||||
// all on the root view silently swallowed some (e.g. the iOS Load file importer).
|
||||
.background(boardsSheetAnchor)
|
||||
.alert("Microphone Access Needed", isPresented: $showMicDeniedAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
} message: {
|
||||
@@ -127,25 +171,62 @@ public struct ShoeGazeBuilderView: View {
|
||||
+ "Security › Microphone, then select the input again.")
|
||||
}
|
||||
#if !os(macOS)
|
||||
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.json]) { result in
|
||||
handleImport(result)
|
||||
}
|
||||
.fileImporter(isPresented: $showRecordingFolderImporter, allowedContentTypes: [.folder]) { result in
|
||||
handleRecordingFolderImport(result)
|
||||
}
|
||||
.fileExporter(
|
||||
isPresented: $showExporter,
|
||||
document: exportDocument,
|
||||
contentType: .json,
|
||||
defaultFilename: ShoeGazeBuilderView.defaultRigFileName
|
||||
) { result in
|
||||
if case .failure(let error) = result {
|
||||
print("[ShoeGazeBuilderView] export failed: \(error)")
|
||||
}
|
||||
}
|
||||
.background(rigImportAnchor)
|
||||
.background(recordingFolderImportAnchor)
|
||||
.background(rigExportAnchor)
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - Presentation anchors
|
||||
|
||||
/// Hosts the board-manager sheet on its own node so it does not collide with the file
|
||||
/// importers / exporter (one presentation per view node).
|
||||
private var boardsSheetAnchor: some View {
|
||||
Color.clear
|
||||
.sheet(isPresented: $showBoardsSheet) {
|
||||
BoardsSheetView(
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
)
|
||||
.presentationDetents([.medium, .large])
|
||||
}
|
||||
}
|
||||
|
||||
#if !os(macOS)
|
||||
/// Hosts the rig-load (`.json`) importer on its own node.
|
||||
private var rigImportAnchor: some View {
|
||||
Color.clear
|
||||
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.json]) { result in
|
||||
handleImport(result)
|
||||
}
|
||||
}
|
||||
|
||||
/// Hosts the recording-folder importer on its own node.
|
||||
private var recordingFolderImportAnchor: some View {
|
||||
Color.clear
|
||||
.fileImporter(isPresented: $showRecordingFolderImporter, allowedContentTypes: [.folder]) { result in
|
||||
handleRecordingFolderImport(result)
|
||||
}
|
||||
}
|
||||
|
||||
/// Hosts the rig-save (`.json`) exporter on its own node.
|
||||
private var rigExportAnchor: some View {
|
||||
Color.clear
|
||||
.fileExporter(
|
||||
isPresented: $showExporter,
|
||||
document: exportDocument,
|
||||
contentType: .json,
|
||||
defaultFilename: ShoeGazeBuilderView.defaultRigFileName
|
||||
) { result in
|
||||
if case .failure(let error) = result {
|
||||
print("[ShoeGazeBuilderView] export failed: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// MARK: - Transport row
|
||||
|
||||
private var transportRow: some View {
|
||||
@@ -184,29 +265,22 @@ public struct ShoeGazeBuilderView: View {
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
|
||||
Picker("Input", selection: inputBinding) {
|
||||
Text("Test Loop").tag(ShoeGazeBuilderView.testLoopTag)
|
||||
ForEach(Array(0..<max(0, shoeGaze.engine.numInputChannels)), id: \.self) { channel in
|
||||
Text("In \(channel)").tag(channel)
|
||||
if shoeGaze.engine.numInputChannels > 0 {
|
||||
ForEach(Array(0..<shoeGaze.engine.numInputChannels), id: \.self) { channel in
|
||||
Text("In \(channel)").tag(channel)
|
||||
}
|
||||
} else if onEnableLiveInput != nil {
|
||||
// No input channel yet: offer live input; selecting it asks the host to
|
||||
// request mic access and rebuild the engine with one (channel 0).
|
||||
Text("Live Input").tag(0)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
|
||||
Text("Board:")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
|
||||
Picker("Board", selection: $selectedBoardIndex) {
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||
let label: String = pair.element.label.isEmpty
|
||||
? "Board \(pair.offset + 1)"
|
||||
: pair.element.label
|
||||
Text(label).tag(pair.offset)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
|
||||
Button("Add Board") { addBoard() }
|
||||
Button("Boards…") { showBoardsSheet = true }
|
||||
.buttonStyle(.bordered).tint(.orange)
|
||||
.help("Rename, reorder, or delete boards")
|
||||
|
||||
Spacer()
|
||||
|
||||
@@ -280,10 +354,15 @@ public struct ShoeGazeBuilderView: View {
|
||||
}
|
||||
},
|
||||
set: { newValue in
|
||||
let source: InputSource = newValue == ShoeGazeBuilderView.testLoopTag
|
||||
? .testLoop
|
||||
: .liveInput(channel: newValue)
|
||||
switchInput(to: source)
|
||||
if newValue == ShoeGazeBuilderView.testLoopTag {
|
||||
switchInput(to: .testLoop)
|
||||
} else if newValue < shoeGaze.engine.numInputChannels {
|
||||
switchInput(to: .liveInput(channel: newValue))
|
||||
} else if let onEnableLiveInput {
|
||||
// Requested a channel the current engine doesn't have (iOS, 0 channels):
|
||||
// hand off to the host to grant mic + rebuild with an input channel.
|
||||
onEnableLiveInput()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -294,7 +373,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
guard !shoeGaze.boards.isEmpty else { return }
|
||||
let board: PedalBoard = shoeGaze.boards[clampedBoardIndex]
|
||||
do {
|
||||
_ = try shoeGaze.appendPedal(type: type, to: board)
|
||||
_ = try shoeGaze.appendPedal(PedalType(type), to: board)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderView] appendPedal failed: \(error)")
|
||||
}
|
||||
@@ -335,6 +414,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
if wasRunning { shoeGaze.engine.stop() }
|
||||
do {
|
||||
try shoeGaze.setInputSource(source)
|
||||
persistInputSelection(source)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderView] setInputSource failed: \(error)")
|
||||
}
|
||||
@@ -344,6 +424,70 @@ public struct ShoeGazeBuilderView: View {
|
||||
transportTick.toggle()
|
||||
}
|
||||
|
||||
// MARK: - Input persistence
|
||||
|
||||
/// 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:)`.
|
||||
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()
|
||||
}
|
||||
// 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))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Board-switch shortcuts
|
||||
|
||||
/// Hidden ⌘1…⌘9 buttons that solo (live-switch to) the matching board and select it as the
|
||||
/// edit target. Kept at zero opacity so the shortcuts stay active without showing chrome.
|
||||
private var boardSwitchShortcuts: some View {
|
||||
ZStack {
|
||||
ForEach(0 ..< min(ShoeGazeBuilderView.maxBoardShortcuts, shoeGaze.boards.count), id: \.self) { index in
|
||||
Button("") { switchToBoard(index) }
|
||||
.keyboardShortcut(KeyEquivalent(Character("\(index + 1)")), modifiers: .command)
|
||||
}
|
||||
}
|
||||
.opacity(0)
|
||||
.frame(width: 0, height: 0)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
|
||||
/// Solos board `index` (a live amp-channel-style switch) and makes it the edit target.
|
||||
private func switchToBoard(_ index: Int) {
|
||||
guard index < shoeGaze.boards.count else { return }
|
||||
selectedBoardIndex = index
|
||||
let seconds: Double = min(max(crossfadeSeconds, 0.0), ShoeGazeBuilderView.maxCrossfadeSeconds)
|
||||
shoeGaze.soloBoard(shoeGaze.boards[index], crossfadeSeconds: seconds)
|
||||
}
|
||||
|
||||
// MARK: - Save / Load (iOS)
|
||||
|
||||
// On macOS, Save/Load are driven from the app's File menu (the app shell owns the
|
||||
|
||||
@@ -79,6 +79,10 @@ public struct ShoeGazeView: View {
|
||||
/// Crossfade duration used for the next board-select transition.
|
||||
@State private var crossfadeSeconds: Double = ShoeGazeView.defaultCrossfadeSeconds
|
||||
|
||||
/// Highlighted board in the board bar (the bar's edit-target binding). The player shows
|
||||
/// every board strip, so this only drives the bar's selection outline.
|
||||
@State private var selectedBoardIndex: Int = 0
|
||||
|
||||
/// Controls presentation of the iOS `.fileImporter` directory picker.
|
||||
/// On macOS the picker is opened imperatively via `NSOpenPanel`; this flag is
|
||||
/// only meaningful on iOS / non-macOS targets.
|
||||
@@ -108,7 +112,12 @@ public struct ShoeGazeView: View {
|
||||
recordingRow
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
boardSelectRow
|
||||
BoardBarView(
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
)
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
boardList
|
||||
@@ -230,77 +239,6 @@ public struct ShoeGazeView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// A `Binding<Int>` that maps between the Picker's integer tag and `ShoeGaze` select API.
|
||||
///
|
||||
/// Tag `-1` represents "All boards audible" (`activeBoardIndex == nil`).
|
||||
/// Tags `0 ..< boards.count` represent the soloed board at that index.
|
||||
/// Setting the binding calls `selectBoard(_:crossfadeSeconds:)` or
|
||||
/// `selectAllBoards(crossfadeSeconds:)` with the current `crossfadeSeconds` value.
|
||||
private var boardSelectBinding: Binding<Int> {
|
||||
Binding(
|
||||
get: { shoeGaze.activeBoardIndex ?? -1 },
|
||||
set: { newValue in
|
||||
// Clamp here so a value typed into the crossfade text field (which has no
|
||||
// built-in bounds) can never pass a negative or oversized lag time.
|
||||
let seconds: Double = min(max(crossfadeSeconds, 0.0), ShoeGazeView.maxCrossfadeSeconds)
|
||||
if newValue == -1 {
|
||||
shoeGaze.selectAllBoards(crossfadeSeconds: seconds)
|
||||
} else if newValue >= 0, newValue < shoeGaze.boards.count {
|
||||
shoeGaze.selectBoard(shoeGaze.boards[newValue], crossfadeSeconds: seconds)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Board-select row: an "Active" Picker to solo a board (or hear all), a crossfade-
|
||||
/// seconds text field, and a companion Stepper for convenient adjustment.
|
||||
///
|
||||
/// The row is always visible. When `boards.count <= 1` the Picker has only one or two
|
||||
/// options, which is still useful for the "All" / single-board toggle.
|
||||
private var boardSelectRow: some View {
|
||||
HStack(spacing: ShoeGazeView.boardSelectSpacing) {
|
||||
Text("Active:")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeView.labelOpacity))
|
||||
|
||||
Picker("Active", selection: boardSelectBinding) {
|
||||
Text("All").tag(-1)
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||
let label: String = pair.element.label.isEmpty
|
||||
? "Board \(pair.offset + 1)"
|
||||
: pair.element.label
|
||||
Text(label).tag(pair.offset)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("Crossfade (s):")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeView.labelOpacity))
|
||||
|
||||
TextField(
|
||||
"s",
|
||||
value: $crossfadeSeconds,
|
||||
format: .number.precision(.fractionLength(1))
|
||||
)
|
||||
.frame(width: ShoeGazeView.crossfadeFieldWidth)
|
||||
#if os(macOS)
|
||||
.textFieldStyle(.squareBorder)
|
||||
#endif
|
||||
|
||||
Stepper(
|
||||
"",
|
||||
value: $crossfadeSeconds,
|
||||
in: 0...ShoeGazeView.maxCrossfadeSeconds,
|
||||
step: ShoeGazeView.crossfadeStepIncrement
|
||||
)
|
||||
.labelsHidden()
|
||||
}
|
||||
}
|
||||
|
||||
/// Vertically scrollable list of board strips.
|
||||
///
|
||||
/// Keyed by `\.offset` on an enumerated snapshot; see the doc-comment on
|
||||
|
||||
@@ -50,7 +50,7 @@ struct BoardEditAPITests {
|
||||
try makeRig(pedals: ["Overdrive", "Delay"])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let edited: PedalBoard = try sg.appendPedal(type: "Reverb", to: board)
|
||||
let edited: PedalBoard = try sg.appendPedal(.reverb, to: board)
|
||||
#expect(names(edited) == ["Overdrive", "Delay", "Reverb"])
|
||||
#expect(sg.boards.count == 1, "append should not change board count")
|
||||
|
||||
@@ -64,7 +64,7 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
#expect(throws: ShoeGazeError.unknownPedalType("Nope")) {
|
||||
try sg.appendPedal(type: "Nope", to: board)
|
||||
try sg.appendPedal(PedalType("Nope"), to: board)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ struct BoardEditAPITests {
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
// Append a linear pedal; the stereo split region must survive untouched.
|
||||
let edited: PedalBoard = try sg.appendPedal(type: "Fuzz", to: board)
|
||||
let edited: PedalBoard = try sg.appendPedal(.fuzz, to: board)
|
||||
#expect(names(edited).contains("Fuzz"), "appended linear pedal should be present")
|
||||
|
||||
let after: BoardState = edited.captureState()
|
||||
@@ -215,8 +215,8 @@ struct BoardEditAPITests {
|
||||
var live: PedalBoard = try sg.appendStereoSplit(to: board)
|
||||
// The split region is the second top-level segment (after the Overdrive pedal).
|
||||
let region: Int = 1
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: region))
|
||||
live = try sg.appendPedal(type: "Reverb", to: live, lane: .right(region: region))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: region))
|
||||
live = try sg.appendPedal(.reverb, to: live, lane: .right(region: region))
|
||||
|
||||
guard let state: StereoSplitState = stereoState(live) else {
|
||||
Issue.record("No stereo split segment after building one")
|
||||
@@ -236,8 +236,8 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
var live: PedalBoard = try sg.appendStereoSplit(to: board)
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(type: "Fuzz", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.fuzz, to: live, lane: .left(region: 1))
|
||||
live = try sg.removePedal(at: 0, from: live, lane: .left(region: 1))
|
||||
|
||||
#expect(stereoState(live)?.left.map { $0.type } == ["Fuzz"], "left lane should drop Delay")
|
||||
@@ -249,7 +249,7 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
// Octave Splitter is a widener → board becomes stereo; a second split is then invalid.
|
||||
let live: PedalBoard = try sg.appendPedal(type: "Octave Splitter", to: board)
|
||||
let live: PedalBoard = try sg.appendPedal(.octaveSplitter, to: board)
|
||||
#expect(live.width == 2, "widener should make the board stereo")
|
||||
#expect(throws: ShoeGazeError.cannotSplitStereoChain) {
|
||||
try sg.appendStereoSplit(to: live)
|
||||
@@ -262,7 +262,7 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
var live: PedalBoard = try sg.appendStereoSplit(to: board)
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: 1))
|
||||
#expect(stereoState(live) != nil, "split region present before removal")
|
||||
|
||||
live = try sg.removeSegment(at: 1, from: live)
|
||||
@@ -319,8 +319,8 @@ struct BoardEditAPITests {
|
||||
var live: PedalBoard = try sg.insertStereoUnzip(afterSegment: 0, in: board)
|
||||
#expect(sg.isStereoUnzip(afterSegment: 0, in: live), "toggle should report unzip present")
|
||||
|
||||
live = try sg.appendPedal(type: "Fuzz", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(type: "Reverb", to: live, lane: .right(region: 1))
|
||||
live = try sg.appendPedal(.fuzz, to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.reverb, to: live, lane: .right(region: 1))
|
||||
|
||||
guard let state: StereoUnzipState = unzipState(live) else {
|
||||
Issue.record("No stereo unzip segment")
|
||||
@@ -375,8 +375,8 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
var live: PedalBoard = try sg.insertStereoUnzip(afterSegment: 0, in: board)
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(type: "Reverb", to: live, lane: .right(region: 1))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.reverb, to: live, lane: .right(region: 1))
|
||||
if let section: StereoSplitSection = live.stereoUnzipSections.first {
|
||||
section.route = .rightOnly
|
||||
}
|
||||
@@ -410,8 +410,8 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
var live: PedalBoard = try sg.appendParallelSplit(to: board)
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(type: "Fuzz", to: live, lane: .right(region: 1))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.fuzz, to: live, lane: .right(region: 1))
|
||||
|
||||
var foundParallel: Bool = false
|
||||
for segment: BoardSegmentState in live.captureState().segments {
|
||||
@@ -528,7 +528,7 @@ struct BoardEditAPITests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
var live: PedalBoard = try sg.appendStereoSplit(to: board)
|
||||
live = try sg.appendPedal(type: "Delay", to: live, lane: .left(region: 1))
|
||||
live = try sg.appendPedal(.delay, to: live, lane: .left(region: 1))
|
||||
|
||||
// Edit the branch pedal's first knob via the node path.
|
||||
guard let stereo: StereoSplitSection = live.stereoSplitSections.first,
|
||||
@@ -562,7 +562,7 @@ struct BoardEditAPITests {
|
||||
try makeRig(pedals: ["Overdrive", "Delay"])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
try sg.appendPedal(type: "Reverb", to: board)
|
||||
try sg.appendPedal(.reverb, to: board)
|
||||
try sg.removePedal(at: 0, from: sg.boards[0]) // drop Overdrive → [Delay, Reverb]
|
||||
|
||||
let preset: URL = FileManager.default.temporaryDirectory
|
||||
|
||||
@@ -98,4 +98,64 @@ struct CompressorPedalTests {
|
||||
}
|
||||
#expect(ssd > 0, "ratio=1 and ratio=20 produced identical output — ratio knob has no effect")
|
||||
}
|
||||
|
||||
@Test func exposesInputThresholdRatioKnobs() throws {
|
||||
let pedal: CompressorPedal = CompressorPedal()
|
||||
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(labels == ["Input", "Threshold", "Ratio"])
|
||||
}
|
||||
|
||||
@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.
|
||||
let renderDuration: Double = 0.1
|
||||
let numAudioBuses: Int = 64
|
||||
|
||||
func renderWithInputGain(_ gainDB: Double) throws -> [Float] {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: numAudioBuses
|
||||
)
|
||||
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.inputGain = gainDB
|
||||
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)
|
||||
}
|
||||
|
||||
let unitySamples: [Float] = try renderWithInputGain(0.0)
|
||||
let boostedSamples: [Float] = try renderWithInputGain(24.0)
|
||||
|
||||
#expect(hasNonSilentOutput(unitySamples), "0 dB input-gain render was silent")
|
||||
#expect(hasNonSilentOutput(boostedSamples), "+24 dB input-gain render was silent")
|
||||
|
||||
let skipSamples: Int = 1024
|
||||
let windowSize: Int = 2048
|
||||
guard unitySamples.count >= skipSamples + windowSize,
|
||||
boostedSamples.count >= skipSamples + windowSize else { return }
|
||||
|
||||
let unityWindow: [Float] = Array(unitySamples[skipSamples..<(skipSamples + windowSize)])
|
||||
let boostedWindow: [Float] = Array(boostedSamples[skipSamples..<(skipSamples + windowSize)])
|
||||
let ssd: Double = zip(unityWindow, boostedWindow).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "input gain 0 dB and +24 dB produced identical output — input gain has no effect")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,9 +97,9 @@ struct FeedbackDelayPedalTests {
|
||||
#expect(ssd > 0, "short and long feedback produced identical output")
|
||||
}
|
||||
|
||||
@Test func exposesTimeFeedbackAndToneKnobs() throws {
|
||||
@Test func exposesTimeDecayAndToneKnobs() throws {
|
||||
let pedal: FeedbackDelayPedal = FeedbackDelayPedal()
|
||||
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(labels == ["Time", "Feedback", "Tone"])
|
||||
#expect(labels == ["Time", "Decay Time", "Tone"])
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,4 +1,4 @@
|
||||
// MuTronPedalTests.swift
|
||||
// MutantPedalTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
@@ -11,8 +11,8 @@ import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("MuTronPedal")
|
||||
struct MuTronPedalTests {
|
||||
@Suite("MutantPedal")
|
||||
struct MutantPedalTests {
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let renderDuration: Double = 0.1
|
||||
@@ -27,7 +27,7 @@ struct MuTronPedalTests {
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: MuTronPedal = MuTronPedal(
|
||||
let pedal: MutantPedal = MutantPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
@@ -40,7 +40,7 @@ struct MuTronPedalTests {
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "MuTronPedal produced silence")
|
||||
#expect(hasNonSilentOutput(samples), "MutantPedal produced silence")
|
||||
}
|
||||
|
||||
@Test func filterModesProduceDifferentOutput() throws {
|
||||
@@ -62,7 +62,7 @@ struct MuTronPedalTests {
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: MuTronPedal = MuTronPedal(
|
||||
let pedal: MutantPedal = MutantPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
@@ -96,27 +96,27 @@ struct MuTronPedalTests {
|
||||
}
|
||||
|
||||
@Test func presetRoundTripPreservesSwitchPositions() throws {
|
||||
let pedal: MuTronPedal = MuTronPedal()
|
||||
let pedal: MutantPedal = MutantPedal()
|
||||
pedal.mode = 2.0 // highpass
|
||||
pedal.direction = 0.0 // down
|
||||
|
||||
let state: PedalState = pedal.captureState()
|
||||
#expect(state.switchValues == [0.0, 2.0]) // [direction, mode]
|
||||
|
||||
let restored: MuTronPedal = MuTronPedal()
|
||||
let restored: MutantPedal = MutantPedal()
|
||||
restored.applyState(state)
|
||||
#expect(restored.mode == 2.0)
|
||||
#expect(restored.direction == 0.0)
|
||||
}
|
||||
|
||||
@Test func exposesSensitivityAndResonanceKnobs() throws {
|
||||
let pedal: MuTronPedal = MuTronPedal()
|
||||
let pedal: MutantPedal = MutantPedal()
|
||||
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(labels == ["Sensitivity", "Resonance"])
|
||||
}
|
||||
|
||||
@Test func exposesTwoStateSweepAndThreeStateModeSwitches() throws {
|
||||
let pedal: MuTronPedal = MuTronPedal()
|
||||
let pedal: MutantPedal = MutantPedal()
|
||||
let switches: [PedalSwitch] = pedal.effectSwitches
|
||||
#expect(switches.map { $0.label } == ["Sweep", "Mode"])
|
||||
// Two-state sweep (Down/Up), three-state mode (LP/BP/HP).
|
||||
@@ -143,7 +143,7 @@ struct MuTronPedalTests {
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: MuTronPedal = MuTronPedal(
|
||||
let pedal: MutantPedal = MutantPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
@@ -423,9 +423,12 @@ struct PresetTests {
|
||||
// Apply the captured state (lightweight recall — no graph rebuild).
|
||||
sg.applyState(captured)
|
||||
|
||||
// threshold is the first effectKnob; applyState calls knob.node.update(value)
|
||||
// which sets the UIParamNode. The UIParamNode.value should now reflect the restored value.
|
||||
let thresholdKnobValue: Double = compressor.knobs[0].node.value
|
||||
// applyState calls knob.node.update(value) on each knob; the Threshold knob's
|
||||
// UIParamNode.value should now reflect the restored value. Look up by label rather
|
||||
// than position so the test is robust to knob additions.
|
||||
let thresholdKnobValue: Double = try #require(
|
||||
compressor.knobs.first(where: { $0.label == "Threshold" })?.node.value
|
||||
)
|
||||
#expect(
|
||||
abs(thresholdKnobValue - knownThreshold) < 1e-9,
|
||||
"threshold knob should be \(knownThreshold) after applyState, got \(thresholdKnobValue)"
|
||||
|
||||
@@ -39,6 +39,236 @@ struct ShoeGazeMultiBoardTests {
|
||||
#expect(shoeGaze.boards.count == 2)
|
||||
}
|
||||
|
||||
@Test func rigSnapshotRestoresAcrossEnginesWithInputChannel() throws {
|
||||
// Backs the iOS "enable live input" rebuild: a rig captured on a 0-input engine must
|
||||
// restore onto a freshly built 1-input engine, and live input must then be selectable.
|
||||
let renderDuration: Double = 0.05
|
||||
|
||||
// Source engine: no input channels (the iOS default before live input is enabled).
|
||||
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numInputChannels: 0,
|
||||
numAudioBuses: 64
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: urlA) }
|
||||
|
||||
let shoeGazeA: ShoeGaze = ShoeGaze(engine: engineA)
|
||||
let board1: PedalBoard = try shoeGazeA.addBoard()
|
||||
board1.label = "Lead"
|
||||
try shoeGazeA.appendPedal(.overdrive, to: board1)
|
||||
try shoeGazeA.finalizeBoard(board1)
|
||||
let board2: PedalBoard = try shoeGazeA.addBoard()
|
||||
board2.label = "Clean"
|
||||
try shoeGazeA.appendPedal(.graphicEQ, to: board2)
|
||||
try shoeGazeA.finalizeBoard(board2)
|
||||
|
||||
let snapshot: Data = try shoeGazeA.rigData()
|
||||
|
||||
// Destination engine: one input channel (the rebuilt engine for live input).
|
||||
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numInputChannels: 1,
|
||||
numAudioBuses: 64
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: urlB) }
|
||||
|
||||
let shoeGazeB: ShoeGaze = ShoeGaze(engine: engineB)
|
||||
try shoeGazeB.loadRig(from: snapshot)
|
||||
|
||||
// The rig round-trips: same board count and labels.
|
||||
#expect(shoeGazeB.boards.count == 2)
|
||||
#expect(shoeGazeB.boards.first?.label == "Lead")
|
||||
#expect(shoeGazeB.boards.last?.label == "Clean")
|
||||
|
||||
// Live input is now selectable on the rebuilt engine.
|
||||
#expect(throws: Never.self) {
|
||||
try shoeGazeB.setInputSource(.liveInput(channel: 0))
|
||||
}
|
||||
}
|
||||
|
||||
@Test func testLoopBoardsShareGlobalSourceViaTaps() throws {
|
||||
// In .testLoop mode every board reads one shared global source through a TestLoopTap,
|
||||
// rather than owning an independently-phased TestLoopSource — this is what keeps the
|
||||
// boards phase-locked. Verify the head input node of each board is a tap, and that a
|
||||
// board removal leaves the others (and their signal) intact.
|
||||
let renderDuration: Double = 0.05
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: 64
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
|
||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||
try board1.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board1)
|
||||
let board2: PedalBoard = try shoeGaze.addBoard()
|
||||
try board2.add(DelayPedal())
|
||||
try shoeGaze.finalizeBoard(board2)
|
||||
|
||||
// Both boards feed from a shared tap, not their own source.
|
||||
#expect(board1.headInputNode != nil)
|
||||
#expect(board1.headInputNode is TestLoopTap)
|
||||
#expect(board2.headInputNode is TestLoopTap)
|
||||
#expect(!(board1.headInputNode is TestLoopSource))
|
||||
|
||||
// Removing one board does not disturb the other's input node.
|
||||
shoeGaze.removeBoard(board1)
|
||||
#expect(shoeGaze.boards.count == 1)
|
||||
#expect(board2.headInputNode is TestLoopTap)
|
||||
}
|
||||
|
||||
@Test func teardownReleasesGlobalTestBusForReuse() throws {
|
||||
// teardown() must remove the global source AND release its bus, so a later addBoard()
|
||||
// can re-allocate cleanly (guards against the global test bus being leaked).
|
||||
let renderDuration: Double = 0.05
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: 16
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
// Repeatedly build a board then tear the whole rig down. With a small bus pool, a leaked
|
||||
// global test bus on each cycle would eventually exhaust the allocator and throw.
|
||||
for _ in 0 ..< 8 {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
try board.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
#expect(board.headInputNode is TestLoopTap)
|
||||
shoeGaze.teardown()
|
||||
#expect(shoeGaze.boards.isEmpty)
|
||||
}
|
||||
|
||||
// Still able to build after all the teardown cycles.
|
||||
let finalBoard: PedalBoard = try shoeGaze.addBoard()
|
||||
#expect(finalBoard.headInputNode is TestLoopTap)
|
||||
}
|
||||
|
||||
@Test func activeBoardIndexTracksReorderAndRemoval() throws {
|
||||
let renderDuration: Double = 0.05
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: 64
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
|
||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||
try board1.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board1)
|
||||
let board2: PedalBoard = try shoeGaze.addBoard()
|
||||
try board2.add(DelayPedal())
|
||||
try shoeGaze.finalizeBoard(board2)
|
||||
let board3: PedalBoard = try shoeGaze.addBoard()
|
||||
try board3.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board3)
|
||||
|
||||
// Solo board3 (index 2), then move it to the front — index must follow the board.
|
||||
shoeGaze.soloBoard(board3, crossfadeSeconds: 0.0)
|
||||
#expect(shoeGaze.activeBoardIndex == 2)
|
||||
shoeGaze.moveBoard(board3, to: 0)
|
||||
#expect(shoeGaze.boards.first === board3)
|
||||
#expect(shoeGaze.activeBoardIndex == 0)
|
||||
|
||||
// Now order is [board3, board1, board2], soloed index 0. Removing a later board
|
||||
// leaves the soloed index unchanged.
|
||||
shoeGaze.removeBoard(board2)
|
||||
#expect(shoeGaze.activeBoardIndex == 0)
|
||||
|
||||
// Re-solo board1 (now index 1), then remove the earlier board3 (index 0):
|
||||
// the soloed index shifts down to 0.
|
||||
shoeGaze.soloBoard(board1, crossfadeSeconds: 0.0)
|
||||
#expect(shoeGaze.activeBoardIndex == 1)
|
||||
shoeGaze.removeBoard(board3)
|
||||
#expect(shoeGaze.activeBoardIndex == 0)
|
||||
|
||||
// Removing the soloed board clears the index.
|
||||
shoeGaze.removeBoard(board1)
|
||||
#expect(shoeGaze.activeBoardIndex == nil)
|
||||
}
|
||||
|
||||
@Test func soloBlendAndAllControlBoardAudibility() throws {
|
||||
let renderDuration: Double = 0.05
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: 64
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||
try board1.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board1)
|
||||
let board2: PedalBoard = try shoeGaze.addBoard()
|
||||
try board2.add(DelayPedal())
|
||||
try shoeGaze.finalizeBoard(board2)
|
||||
let board3: PedalBoard = try shoeGaze.addBoard()
|
||||
try board3.add(OverdrivePedal())
|
||||
try shoeGaze.finalizeBoard(board3)
|
||||
|
||||
let instantCrossfade: Double = 0.0
|
||||
|
||||
// Default: every board audible, no solo.
|
||||
#expect(shoeGaze.isBoardAudible(board1))
|
||||
#expect(shoeGaze.isBoardAudible(board2))
|
||||
#expect(shoeGaze.isBoardAudible(board3))
|
||||
#expect(shoeGaze.activeBoardIndex == nil)
|
||||
|
||||
// Solo board2 — exclusive.
|
||||
shoeGaze.soloBoard(board2, crossfadeSeconds: instantCrossfade)
|
||||
#expect(!shoeGaze.isBoardAudible(board1))
|
||||
#expect(shoeGaze.isBoardAudible(board2))
|
||||
#expect(!shoeGaze.isBoardAudible(board3))
|
||||
#expect(shoeGaze.activeBoardIndex == 1)
|
||||
|
||||
// Blend: re-enable board1 without disturbing the others, and clear the solo index.
|
||||
shoeGaze.setBoard(board1, audible: true, crossfadeSeconds: instantCrossfade)
|
||||
#expect(shoeGaze.isBoardAudible(board1))
|
||||
#expect(shoeGaze.isBoardAudible(board2))
|
||||
#expect(!shoeGaze.isBoardAudible(board3))
|
||||
#expect(shoeGaze.activeBoardIndex == nil)
|
||||
|
||||
// Silence a single board.
|
||||
shoeGaze.setBoard(board1, audible: false, crossfadeSeconds: instantCrossfade)
|
||||
#expect(!shoeGaze.isBoardAudible(board1))
|
||||
#expect(shoeGaze.isBoardAudible(board2))
|
||||
|
||||
// All back to summed.
|
||||
shoeGaze.selectAllBoards(crossfadeSeconds: instantCrossfade)
|
||||
#expect(shoeGaze.isBoardAudible(board1))
|
||||
#expect(shoeGaze.isBoardAudible(board2))
|
||||
#expect(shoeGaze.isBoardAudible(board3))
|
||||
#expect(shoeGaze.activeBoardIndex == nil)
|
||||
}
|
||||
|
||||
@Test func setBoardIgnoresUnmanagedBoard() throws {
|
||||
let renderDuration: Double = 0.05
|
||||
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: urlA)
|
||||
try? FileManager.default.removeItem(at: urlB)
|
||||
}
|
||||
|
||||
let shoeGazeA: ShoeGaze = ShoeGaze(engine: engineA)
|
||||
let shoeGazeB: ShoeGaze = ShoeGaze(engine: engineB)
|
||||
|
||||
let boardA: PedalBoard = try shoeGazeA.addBoard()
|
||||
try boardA.add(OverdrivePedal())
|
||||
try shoeGazeA.finalizeBoard(boardA)
|
||||
let boardB: PedalBoard = try shoeGazeB.addBoard()
|
||||
try boardB.add(DelayPedal())
|
||||
try shoeGazeB.finalizeBoard(boardB)
|
||||
|
||||
// Toggling a board not owned by this manager is a no-op and must not change state.
|
||||
shoeGazeA.setBoard(boardB, audible: false, crossfadeSeconds: 0.0)
|
||||
#expect(shoeGazeA.isBoardAudible(boardA))
|
||||
#expect(shoeGazeB.isBoardAudible(boardB))
|
||||
}
|
||||
|
||||
@Test func removeBoardLeavesOtherBoards() throws {
|
||||
let renderDuration: Double = 0.05
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Screenshots
|
||||
|
||||
Place README screenshots here as PNG:
|
||||
|
||||
- `builder-macos.png` — the macOS builder
|
||||
- `board-mixer.png` — the multi-board mixer bar
|
||||
|
||||
Referenced by `README.md` via relative paths.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 884 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
Reference in New Issue
Block a user