Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 393fb47a78 | |||
| 9cf431d8ee | |||
| cb28ea8c7d | |||
| c28e7cac90 |
+20
@@ -0,0 +1,20 @@
|
|||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Swift Package Manager
|
||||||
|
.build/
|
||||||
|
.swiftpm/
|
||||||
|
Package.pins
|
||||||
|
*.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/
|
||||||
|
|
||||||
|
# Xcode — user-specific state (never share)
|
||||||
|
xcuserdata/
|
||||||
|
*.xcuserstate
|
||||||
|
*.xcuserdatad/
|
||||||
|
|
||||||
|
# Build / derived
|
||||||
|
DerivedData/
|
||||||
|
*.o
|
||||||
|
*.swiftmodule
|
||||||
|
|
||||||
|
# Note: Package.resolved is intentionally tracked to pin the Lyrebird dependency.
|
||||||
@@ -180,10 +180,11 @@ final class ShoeGazeDemoController {
|
|||||||
|
|
||||||
// MARK: - Mode builders
|
// MARK: - Mode builders
|
||||||
|
|
||||||
/// `.boards` — two full boards covering all eight pedal types.
|
/// `.boards` — three full boards covering all twelve pedal types.
|
||||||
///
|
///
|
||||||
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
||||||
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
||||||
|
/// Board 3: Mu-Tron → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
||||||
private func buildBoards() {
|
private func buildBoards() {
|
||||||
do {
|
do {
|
||||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||||
@@ -201,6 +202,14 @@ final class ShoeGazeDemoController {
|
|||||||
try board2.add(PhaserPedal())
|
try board2.add(PhaserPedal())
|
||||||
try board2.add(CompressorPedal())
|
try board2.add(CompressorPedal())
|
||||||
try shoeGaze.finalizeBoard(board2)
|
try shoeGaze.finalizeBoard(board2)
|
||||||
|
|
||||||
|
let board3: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
board3.label = "Board 3"
|
||||||
|
try board3.add(MuTronPedal())
|
||||||
|
try board3.add(AutoWahPedal())
|
||||||
|
try board3.add(FeedbackDelayPedal())
|
||||||
|
try board3.add(MultiTapDelayPedal())
|
||||||
|
try shoeGaze.finalizeBoard(board3)
|
||||||
} catch {
|
} catch {
|
||||||
print("[ShoeGazeDemoController] buildBoards failed: \(error)")
|
print("[ShoeGazeDemoController] buildBoards failed: \(error)")
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "34b5d439cb0aa8023e4d055198b63d5bcb210c30e370037d88c4bb2b45c9e486",
|
"originHash" : "b8327204b102b429067129b94b6ba77dcfa78570af3b9d11cae4d7eb252e388c",
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "linenoise-swift",
|
"identity" : "linenoise-swift",
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "73191c958f0d6e355897717b34317e40fdf158f9",
|
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
||||||
"version" : "1.1.1"
|
"version" : "1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,6 +118,15 @@ open class Pedal: SynthesizerBase {
|
|||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Effect-specific discrete switches for this pedal, rendered as a row of segmented
|
||||||
|
/// controls beneath the knob grid.
|
||||||
|
///
|
||||||
|
/// Override in subclasses to publish each discrete `@UIParam` parameter as a two- or
|
||||||
|
/// three-state ``PedalSwitch`` (sweep direction, filter mode, …). Defaults to empty.
|
||||||
|
open var effectSwitches: [PedalSwitch] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
||||||
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
||||||
/// surfaced separately as a header toggle, not as a knob.
|
/// surfaced separately as a header toggle, not as a knob.
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// PedalSwitch.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// A UI-agnostic description of one multi-position pedal switch.
|
||||||
|
///
|
||||||
|
/// Where ``PedalKnob`` describes a continuous rotary control, `PedalSwitch` describes a
|
||||||
|
/// discrete segmented switch with a fixed set of labelled positions — a two-state toggle
|
||||||
|
/// (e.g. sweep Up / Down) or a three-state selector (e.g. filter LP / BP / HP). A `Pedal`
|
||||||
|
/// publishes an array of these via ``Pedal/effectSwitches`` so a generic pedalboard UI can
|
||||||
|
/// render a segmented control per discrete parameter without knowing the concrete type.
|
||||||
|
///
|
||||||
|
/// Each option pairs a short caption with the exact `Double` written to the live
|
||||||
|
/// ``UIParamNode`` when that position is selected; the currently-lit segment is the option
|
||||||
|
/// whose `value` is nearest the node's current value.
|
||||||
|
public struct PedalSwitch {
|
||||||
|
|
||||||
|
/// One labelled position of a ``PedalSwitch``.
|
||||||
|
public struct Option {
|
||||||
|
|
||||||
|
/// Short caption shown inside the segment (e.g. "Up", "BP").
|
||||||
|
public let title: String
|
||||||
|
|
||||||
|
/// Value written to the switch's node when this position is selected.
|
||||||
|
public let value: Double
|
||||||
|
|
||||||
|
/// Creates a switch position.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - title: Short caption shown inside the segment.
|
||||||
|
/// - value: Value written to the node when this position is selected.
|
||||||
|
public init(title: String, value: Double) {
|
||||||
|
self.title = title
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Short label shown beneath the segmented control (e.g. "Mode", "Sweep").
|
||||||
|
public let label: String
|
||||||
|
|
||||||
|
/// The live parameter node the switch reads and writes. Pass `pedal.$paramName`.
|
||||||
|
public let node: UIParamNode
|
||||||
|
|
||||||
|
/// Ordered positions, left to right. Two entries make a two-state switch, three a
|
||||||
|
/// three-state switch. Must contain at least two options.
|
||||||
|
public let options: [Option]
|
||||||
|
|
||||||
|
/// Creates a switch descriptor.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - label: Short label shown beneath the segmented control.
|
||||||
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
||||||
|
/// (`pedal.$mode`, `pedal.$direction`, …).
|
||||||
|
/// - options: Ordered switch positions, left to right. At least two.
|
||||||
|
public init(
|
||||||
|
label: String,
|
||||||
|
node: UIParamNode,
|
||||||
|
options: [Option]
|
||||||
|
) {
|
||||||
|
precondition(options.count >= 2, "PedalSwitch requires at least two options")
|
||||||
|
self.label = label
|
||||||
|
self.node = node
|
||||||
|
self.options = options
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
// AutoWahPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Amplitude-tracked auto-wah pedal built from discrete tracking + filter stages.
|
||||||
|
///
|
||||||
|
/// Unlike `MuTronPedal` (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.
|
||||||
|
/// Louder playing opens the filter — the classic "wah" vowel that follows your picking.
|
||||||
|
///
|
||||||
|
/// ## Signal path
|
||||||
|
/// ```
|
||||||
|
/// dry → AmplitudeFollower → ×sensitivity → Clip[0,1] → LinExp(freqLo…range) → SVF.bandpass
|
||||||
|
/// ↑freq
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `sensitivity`: How hard the envelope drives the sweep; higher reaches the top of the range sooner.
|
||||||
|
/// - `resonance`: Bandpass Q. Higher values sharpen the vowel and add emphasis.
|
||||||
|
/// - `range`: Upper cutoff in Hz reached at full envelope. Sets the sweep span over `freqLo`.
|
||||||
|
public final class AutoWahPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Envelope drive into the cutoff sweep. Higher values open the filter on quieter input.
|
||||||
|
@UIParam public var sensitivity: Double = 2.0
|
||||||
|
|
||||||
|
/// Bandpass resonance (SVF quality factor). Higher values sharpen the wah vowel.
|
||||||
|
@UIParam public var resonance: Double = 3.0
|
||||||
|
|
||||||
|
/// Upper cutoff frequency in Hz at maximum envelope.
|
||||||
|
@UIParam public var range: Double = 2400.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Cutoff at zero envelope, in Hz. `LinExp` requires a strictly positive lower bound.
|
||||||
|
private let freqLo: Double = 200.0
|
||||||
|
|
||||||
|
/// Envelope-follower attack/release times, in seconds.
|
||||||
|
private let attackTime: Double = 0.01
|
||||||
|
private let releaseTime: Double = 0.12
|
||||||
|
|
||||||
|
/// Clamp bounds for the scaled envelope before the exponential frequency map.
|
||||||
|
private let envFloor: Double = 0.0
|
||||||
|
private let envCeiling: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
|
||||||
|
private let resonanceRange: ClosedRange<Double> = 0.5 ... 8.0
|
||||||
|
private let rangeRange: ClosedRange<Double> = 500.0 ... 5000.0
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Sensitivity", node: $sensitivity, range: sensitivityRange),
|
||||||
|
PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange),
|
||||||
|
PedalKnob(label: "Range", node: $range, range: rangeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
|
super.init(
|
||||||
|
name: "Auto-Wah",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: AutoWahPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
// Track the dry signal's amplitude envelope.
|
||||||
|
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
|
||||||
|
in: dry,
|
||||||
|
attackTime: attackTime,
|
||||||
|
releaseTime: releaseTime
|
||||||
|
)
|
||||||
|
|
||||||
|
// Scale by sensitivity and clamp to [0, 1] so the exponential map stays in range
|
||||||
|
// and the swept cutoff never exceeds `range` (and thus never approaches Nyquist).
|
||||||
|
let driven: Clip.Audio = Clip.Audio(
|
||||||
|
envelope * $sensitivity,
|
||||||
|
lo: envFloor,
|
||||||
|
hi: envCeiling
|
||||||
|
)
|
||||||
|
|
||||||
|
// Map the clamped envelope to an exponential cutoff sweep from freqLo to range.
|
||||||
|
let cutoff: LinExp.Audio = LinExp.Audio(
|
||||||
|
driven,
|
||||||
|
inLo: envFloor,
|
||||||
|
inHi: envCeiling,
|
||||||
|
outLo: freqLo,
|
||||||
|
outHi: $range
|
||||||
|
)
|
||||||
|
|
||||||
|
// Resonant bandpass swept by the tracked envelope — the wah voice.
|
||||||
|
let filtered: SVF.Audio = SVF.Audio(
|
||||||
|
input: dry,
|
||||||
|
freq: cutoff,
|
||||||
|
q: $resonance
|
||||||
|
)
|
||||||
|
return filtered.bandpass
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
// FeedbackDelayPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Feedback (tape-style) delay pedal with multiple regenerating repeats.
|
||||||
|
///
|
||||||
|
/// Signal chain (inside `effect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry → DelayLineFeedback(delay: time, decayTime: feedback) → RBJLowPass(tone) → wet
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The feedback path regenerates the echo so a single note produces a train of repeats
|
||||||
|
/// that decays over `feedback` seconds. A `Tone` lowpass darkens the wet signal for the
|
||||||
|
/// warm, rolled-off character of a tape echo (cubic interpolation adds the same smear).
|
||||||
|
/// `effect` returns the pure wet signal — the base `Pedal` blends it via `mix`.
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `time`: Delay time between repeats, in seconds.
|
||||||
|
/// - `feedback`: Repeat decay time in seconds — how long the echoes regenerate before
|
||||||
|
/// falling to −60 dB. Longer values produce more audible repeats.
|
||||||
|
/// - `tone`: Lowpass cutoff in Hz applied to the wet signal; lower darkens the echoes.
|
||||||
|
public final class FeedbackDelayPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Delay time between repeats, in seconds.
|
||||||
|
@UIParam public var time: Double = 0.3
|
||||||
|
|
||||||
|
/// Repeat decay time in seconds (time for echoes to reach −60 dB). Longer = more repeats.
|
||||||
|
@UIParam public var feedback: Double = 2.5
|
||||||
|
|
||||||
|
/// Tone (lowpass) cutoff in Hz applied to the wet echoes.
|
||||||
|
@UIParam public var tone: Double = 4000.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Maximum supported delay time in seconds. Sizes the delay-line buffer at init.
|
||||||
|
private let maxDelayTime: Double = 1.5
|
||||||
|
|
||||||
|
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
||||||
|
private let targetAmp: Double = 0.001
|
||||||
|
|
||||||
|
/// Butterworth Q for the tone lowpass (no resonant peak).
|
||||||
|
private let toneQ: Double = 0.707
|
||||||
|
|
||||||
|
/// Partial wet/dry blend so the dry note and its echoes coexist.
|
||||||
|
private static let defaultMix: Double = 0.35
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let timeRange: ClosedRange<Double> = 0.02 ... 1.5
|
||||||
|
private let feedbackRange: ClosedRange<Double> = 0.1 ... 8.0
|
||||||
|
private let toneRange: ClosedRange<Double> = 500.0 ... 8000.0
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
|
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||||
|
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
|
super.init(
|
||||||
|
name: "Feedback Delay",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: FeedbackDelayPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let echoes: DelayLineFeedback = DelayLineFeedback(
|
||||||
|
input: dry,
|
||||||
|
maxDelay: maxDelayTime,
|
||||||
|
delay: $time,
|
||||||
|
decayTime: $feedback,
|
||||||
|
targetAmp: targetAmp,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
interpolation: .cubic
|
||||||
|
)
|
||||||
|
return RBJLowPass.Audio(
|
||||||
|
input: echoes,
|
||||||
|
freq: $tone,
|
||||||
|
q: toneQ
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
// MuTronPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Envelope-following filter pedal modeled on the Musitronics Mu-Tron III.
|
||||||
|
///
|
||||||
|
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
|
||||||
|
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
|
||||||
|
/// fixes both its filter `mode` and sweep `direction` at `init`, six instances (three
|
||||||
|
/// filter modes × two sweep directions) run in parallel on the shared dry signal and a
|
||||||
|
/// nested `Select` picks the active one from the `mode` and `direction` switches — this
|
||||||
|
/// keeps every filter state warmed so switch changes are click-free (SuperCollider
|
||||||
|
/// `Select` semantics: every input advances each block).
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `sensitivity`: Drive into the envelope follower; higher values open the filter on quieter notes.
|
||||||
|
/// - `resonance`: Filter peak emphasis at the swept cutoff.
|
||||||
|
///
|
||||||
|
/// ## 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 {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Filter response selector. `0` = lowpass, `1` = bandpass, `2` = highpass. Driven by a three-state switch.
|
||||||
|
@UIParam public var mode: Double = 1.0
|
||||||
|
|
||||||
|
/// Sweep direction selector. `0` = down (louder closes), `1` = up (louder opens). Driven by a two-state switch.
|
||||||
|
@UIParam public var direction: Double = 1.0
|
||||||
|
|
||||||
|
/// Envelope-follower drive. Higher values make the filter respond to quieter input.
|
||||||
|
@UIParam public var sensitivity: Double = 1.5
|
||||||
|
|
||||||
|
/// Filter resonance (Chamberlin SVF peak emphasis). Clamped to `≥ 1.0` internally.
|
||||||
|
@UIParam public var resonance: Double = 4.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Cutoff at zero envelope, in Hz.
|
||||||
|
private let freqLo: Double = 80.0
|
||||||
|
|
||||||
|
/// Cutoff at maximum envelope, in Hz (≈40× sweep over `freqLo`).
|
||||||
|
private let freqHi: Double = 3200.0
|
||||||
|
|
||||||
|
/// Envelope attack/release times, in seconds.
|
||||||
|
private let attackTime: Double = 0.005
|
||||||
|
private let releaseTime: Double = 0.15
|
||||||
|
|
||||||
|
/// Half-step bias added before each `Select`'s truncate-toward-zero index, turning a
|
||||||
|
/// switch parameter into a round-to-nearest position selector.
|
||||||
|
private let selectRoundingBias: Double = 0.5
|
||||||
|
|
||||||
|
/// Switch position values.
|
||||||
|
private let modeLowpassValue: Double = 0.0
|
||||||
|
private let modeBandpassValue: Double = 1.0
|
||||||
|
private let modeHighpassValue: Double = 2.0
|
||||||
|
private let directionDownValue: Double = 0.0
|
||||||
|
private let directionUpValue: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
|
||||||
|
private let resonanceRange: ClosedRange<Double> = 1.0 ... 12.0
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Sensitivity", node: $sensitivity, range: sensitivityRange),
|
||||||
|
PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Switches
|
||||||
|
|
||||||
|
public override var effectSwitches: [PedalSwitch] {
|
||||||
|
[
|
||||||
|
PedalSwitch(
|
||||||
|
label: "Sweep",
|
||||||
|
node: $direction,
|
||||||
|
options: [
|
||||||
|
PedalSwitch.Option(title: "Down", value: directionDownValue),
|
||||||
|
PedalSwitch.Option(title: "Up", value: directionUpValue),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
PedalSwitch(
|
||||||
|
label: "Mode",
|
||||||
|
node: $mode,
|
||||||
|
options: [
|
||||||
|
PedalSwitch.Option(title: "LP", value: modeLowpassValue),
|
||||||
|
PedalSwitch.Option(title: "BP", value: modeBandpassValue),
|
||||||
|
PedalSwitch.Option(title: "HP", value: modeHighpassValue),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
|
super.init(
|
||||||
|
name: "Mu-Tron",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: MuTronPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
// Inner mode selectors per sweep direction. `Select` rounds the [0, 2] mode switch
|
||||||
|
// to the nearest position and advances all three filters each block (warmed state).
|
||||||
|
let modeWhich: any ValidGeneratorInput = $mode + selectRoundingBias
|
||||||
|
let downModes: Select.Audio = Select.Audio(
|
||||||
|
which: modeWhich,
|
||||||
|
inputs: [
|
||||||
|
makeFilter(dry, mode: .lowpass, direction: .down),
|
||||||
|
makeFilter(dry, mode: .bandpass, direction: .down),
|
||||||
|
makeFilter(dry, mode: .highpass, direction: .down),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
let upModes: Select.Audio = Select.Audio(
|
||||||
|
which: modeWhich,
|
||||||
|
inputs: [
|
||||||
|
makeFilter(dry, mode: .lowpass, direction: .up),
|
||||||
|
makeFilter(dry, mode: .bandpass, direction: .up),
|
||||||
|
makeFilter(dry, mode: .highpass, direction: .up),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Outer selector picks the sweep direction (Down = 0, Up = 1).
|
||||||
|
let directionWhich: any ValidGeneratorInput = $direction + selectRoundingBias
|
||||||
|
return Select.Audio(
|
||||||
|
which: directionWhich,
|
||||||
|
inputs: [downModes, upModes]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func makeFilter(
|
||||||
|
_ dry: any ValidGeneratorInput,
|
||||||
|
mode: MuTronIIIMode,
|
||||||
|
direction: MuTronIIISweep
|
||||||
|
) -> MuTronIII.Audio {
|
||||||
|
MuTronIII.Audio(
|
||||||
|
input: dry,
|
||||||
|
mode: mode,
|
||||||
|
direction: direction,
|
||||||
|
sensitivity: $sensitivity,
|
||||||
|
peak: $resonance,
|
||||||
|
freqLo: freqLo,
|
||||||
|
freqHi: freqHi,
|
||||||
|
attackTime: attackTime,
|
||||||
|
releaseTime: releaseTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
// MultiTapDelayPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Three-tap delay pedal with no feedback and an independent volume per tap.
|
||||||
|
///
|
||||||
|
/// The dry signal is split into three non-regenerating delay lines at independent times;
|
||||||
|
/// each tap's level is set by its own volume knob, and the three taps are summed into the
|
||||||
|
/// wet output. Because no tap feeds back, the result is a fixed three-echo pattern rather
|
||||||
|
/// than a decaying repeat train — useful for rhythmic slap-back groups and chords of echoes.
|
||||||
|
///
|
||||||
|
/// Signal chain (inside `effect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry ─┬─ DelayLine(time1) × vol1 ─┐
|
||||||
|
/// ├─ DelayLine(time2) × vol2 ─┼─ Σ → wet
|
||||||
|
/// └─ DelayLine(time3) × vol3 ─┘
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `effect` returns the summed wet signal — the base `Pedal` blends it via `mix`.
|
||||||
|
///
|
||||||
|
/// ## Knobs (two rows of three)
|
||||||
|
/// - `time1`, `time2`, `time3`: Delay time of each tap, in seconds.
|
||||||
|
/// - `vol1`, `vol2`, `vol3`: Linear output level of each tap in `[0, 1]`.
|
||||||
|
public final class MultiTapDelayPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Tap times
|
||||||
|
|
||||||
|
/// Tap 1 delay time, in seconds.
|
||||||
|
@UIParam public var time1: Double = 0.12
|
||||||
|
|
||||||
|
/// Tap 2 delay time, in seconds.
|
||||||
|
@UIParam public var time2: Double = 0.24
|
||||||
|
|
||||||
|
/// Tap 3 delay time, in seconds.
|
||||||
|
@UIParam public var time3: Double = 0.36
|
||||||
|
|
||||||
|
// MARK: - Tap volumes
|
||||||
|
|
||||||
|
/// Tap 1 linear level in [0, 1].
|
||||||
|
@UIParam public var vol1: Double = 0.8
|
||||||
|
|
||||||
|
/// Tap 2 linear level in [0, 1].
|
||||||
|
@UIParam public var vol2: Double = 0.5
|
||||||
|
|
||||||
|
/// Tap 3 linear level in [0, 1].
|
||||||
|
@UIParam public var vol3: Double = 0.3
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Maximum supported per-tap delay time in seconds. Sizes each delay-line buffer at init.
|
||||||
|
private let maxDelayTime: Double = 1.0
|
||||||
|
|
||||||
|
/// Partial wet/dry blend so the dry note and its taps coexist.
|
||||||
|
private static let defaultMix: Double = 0.4
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let timeRange: ClosedRange<Double> = 0.01 ... 1.0
|
||||||
|
private let volRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
/// Two rows of three: the three tap times, then the three tap volumes.
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Time 1", node: $time1, range: timeRange),
|
||||||
|
PedalKnob(label: "Time 2", node: $time2, range: timeRange),
|
||||||
|
PedalKnob(label: "Time 3", node: $time3, range: timeRange),
|
||||||
|
PedalKnob(label: "Vol 1", node: $vol1, range: volRange),
|
||||||
|
PedalKnob(label: "Vol 2", node: $vol2, range: volRange),
|
||||||
|
PedalKnob(label: "Vol 3", node: $vol3, range: volRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
|
super.init(
|
||||||
|
name: "Multi-Tap Delay",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: MultiTapDelayPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let tap1: DelayLine = makeTap(dry, delay: $time1, volume: $vol1)
|
||||||
|
let tap2: DelayLine = makeTap(dry, delay: $time2, volume: $vol2)
|
||||||
|
let tap3: DelayLine = makeTap(dry, delay: $time3, volume: $vol3)
|
||||||
|
return tap1 + tap2 + tap3
|
||||||
|
}
|
||||||
|
|
||||||
|
private func makeTap(
|
||||||
|
_ dry: any ValidGeneratorInput,
|
||||||
|
delay: any ValidGeneratorInput,
|
||||||
|
volume: any ValidGeneratorInput
|
||||||
|
) -> DelayLine {
|
||||||
|
DelayLine(
|
||||||
|
input: dry,
|
||||||
|
maxDelay: maxDelayTime,
|
||||||
|
delay: delay,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
interpolation: .linear,
|
||||||
|
mul: volume
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,9 +17,11 @@ extension Pedal {
|
|||||||
/// - Returns: A `PedalState` reflecting the pedal's current parameter values.
|
/// - Returns: A `PedalState` reflecting the pedal's current parameter values.
|
||||||
public func captureState() -> PedalState {
|
public func captureState() -> PedalState {
|
||||||
let values: [Double] = knobs.map { $0.node.value }
|
let values: [Double] = knobs.map { $0.node.value }
|
||||||
|
let switchValues: [Double] = effectSwitches.map { $0.node.value }
|
||||||
return PedalState(
|
return PedalState(
|
||||||
type: displayName,
|
type: displayName,
|
||||||
knobValues: values,
|
knobValues: values,
|
||||||
|
switchValues: switchValues,
|
||||||
bypass: bypass
|
bypass: bypass
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -27,10 +29,12 @@ extension Pedal {
|
|||||||
/// Applies a previously captured `PedalState` to this pedal's parameters.
|
/// Applies a previously captured `PedalState` to this pedal's parameters.
|
||||||
///
|
///
|
||||||
/// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's
|
/// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's
|
||||||
/// `UIParamNode` is updated via `node.update(_:)`. If `state.knobValues` has
|
/// `UIParamNode` is updated via `node.update(_:)`; switch positions are restored the
|
||||||
/// fewer entries than `knobs`, the trailing knobs retain their current values.
|
/// same way from `zip(effectSwitches, state.switchValues)`. If either array has fewer
|
||||||
/// Extra values beyond `knobs.count` are ignored. The `bypass` parameter is
|
/// entries than its controls, the trailing controls retain their current values; extra
|
||||||
/// always applied regardless of knob-count mismatches.
|
/// values are ignored. The `bypass` parameter is always applied regardless of any
|
||||||
|
/// count mismatch. Presets saved before switches existed carry an empty
|
||||||
|
/// `switchValues`, leaving switch positions at their defaults.
|
||||||
///
|
///
|
||||||
/// - Parameter state: The state to restore. The `state.type` is not validated
|
/// - Parameter state: The state to restore. The `state.type` is not validated
|
||||||
/// against `displayName` — the caller is responsible for matching types before
|
/// against `displayName` — the caller is responsible for matching types before
|
||||||
@@ -39,6 +43,9 @@ extension Pedal {
|
|||||||
for (knob, value) in zip(knobs, state.knobValues) {
|
for (knob, value) in zip(knobs, state.knobValues) {
|
||||||
knob.node.update(value)
|
knob.node.update(value)
|
||||||
}
|
}
|
||||||
|
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
|
||||||
|
pedalSwitch.node.update(value)
|
||||||
|
}
|
||||||
bypass = state.bypass
|
bypass = state.bypass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
/// are silently skipped by the loader.
|
/// are silently skipped by the loader.
|
||||||
///
|
///
|
||||||
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
||||||
/// and merging it before calling `loadRig`. The built-in registry covers the eight
|
/// and merging it before calling `loadRig`. The built-in registry covers the twelve
|
||||||
/// factory pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser, and
|
/// factory pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser,
|
||||||
/// Compressor.
|
/// Compressor, Mu-Tron, Auto-Wah, Feedback Delay, and Multi-Tap Delay.
|
||||||
public enum PedalRegistry {
|
public enum PedalRegistry {
|
||||||
|
|
||||||
/// Maps each built-in pedal display name to a `@MainActor` no-argument constructor.
|
/// Maps each built-in pedal display name to a `@MainActor` no-argument constructor.
|
||||||
@@ -32,6 +32,10 @@ public enum PedalRegistry {
|
|||||||
"Tremolo": { TremoloPedal() },
|
"Tremolo": { TremoloPedal() },
|
||||||
"Phaser": { PhaserPedal() },
|
"Phaser": { PhaserPedal() },
|
||||||
"Compressor": { CompressorPedal() },
|
"Compressor": { CompressorPedal() },
|
||||||
|
"Mu-Tron": { MuTronPedal() },
|
||||||
|
"Auto-Wah": { AutoWahPedal() },
|
||||||
|
"Feedback Delay": { FeedbackDelayPedal() },
|
||||||
|
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// Knob values in the same order as `Pedal.knobs` (effect knobs then Mix, Level).
|
/// Knob values in the same order as `Pedal.knobs` (effect knobs then Mix, Level).
|
||||||
public let knobValues: [Double]
|
public let knobValues: [Double]
|
||||||
|
|
||||||
|
/// Switch values in the same order as `Pedal.effectSwitches`. Empty for pedals with
|
||||||
|
/// no switches. Absent in presets saved before switches existed — decodes to `[]`.
|
||||||
|
public let switchValues: [Double]
|
||||||
|
|
||||||
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
||||||
public let bypass: Double
|
public let bypass: Double
|
||||||
|
|
||||||
@@ -30,14 +34,34 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - type: The pedal's `displayName`, used to identify the pedal type on load.
|
/// - type: The pedal's `displayName`, used to identify the pedal type on load.
|
||||||
/// - knobValues: Current knob values in `Pedal.knobs` order.
|
/// - knobValues: Current knob values in `Pedal.knobs` order.
|
||||||
|
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
|
||||||
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
||||||
public init(
|
public init(
|
||||||
type: String,
|
type: String,
|
||||||
knobValues: [Double],
|
knobValues: [Double],
|
||||||
|
switchValues: [Double] = [],
|
||||||
bypass: Double
|
bypass: Double
|
||||||
) {
|
) {
|
||||||
self.type = type
|
self.type = type
|
||||||
self.knobValues = knobValues
|
self.knobValues = knobValues
|
||||||
|
self.switchValues = switchValues
|
||||||
self.bypass = bypass
|
self.bypass = bypass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case type
|
||||||
|
case knobValues
|
||||||
|
case switchValues
|
||||||
|
case bypass
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes a snapshot, tolerating presets saved before `switchValues` existed by
|
||||||
|
/// defaulting the missing key to an empty array.
|
||||||
|
public init(from decoder: any Decoder) throws {
|
||||||
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.type = try container.decode(String.self, forKey: .type)
|
||||||
|
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
||||||
|
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
||||||
|
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
// PedalSwitchView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
// MARK: - PedalSwitchView
|
||||||
|
|
||||||
|
/// A segmented multi-position switch bound to a live ``UIParamNode``.
|
||||||
|
///
|
||||||
|
/// Renders one button per ``PedalSwitch/Option`` in a horizontal pill, with a caption
|
||||||
|
/// label beneath — mirroring the look of ``ParameterKnob``. The same view serves both a
|
||||||
|
/// two-state toggle (two options, e.g. sweep Up / Down) and a three-state selector (three
|
||||||
|
/// options, e.g. filter LP / BP / HP); the segment count follows `pedalSwitch.options`.
|
||||||
|
///
|
||||||
|
/// The lit segment is the option whose `value` is nearest the node's current value.
|
||||||
|
/// Tapping a segment writes that option's exact `value` via `node.update(_:)`. Reading
|
||||||
|
/// `node.value` in `body` registers the view for automatic re-render (UIParamNode is
|
||||||
|
/// `@Observable`).
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
/// ```swift
|
||||||
|
/// PedalSwitchView(pedalSwitch)
|
||||||
|
/// ```
|
||||||
|
public struct PedalSwitchView: View {
|
||||||
|
|
||||||
|
// MARK: - Layout constants
|
||||||
|
|
||||||
|
private static let cornerRadius: CGFloat = 6
|
||||||
|
private static let segmentSpacing: CGFloat = 3
|
||||||
|
private static let labelSpacing: CGFloat = 4
|
||||||
|
private static let segmentPaddingV: CGFloat = 5
|
||||||
|
private static let segmentPaddingH: CGFloat = 6
|
||||||
|
private static let fontSize: CGFloat = 11
|
||||||
|
private static let captionFontSize: CGFloat = 11
|
||||||
|
private static let activeFillOpacity: Double = 0.88
|
||||||
|
private static let inactiveFillOpacity: Double = 0.16
|
||||||
|
private static let borderOpacity: Double = 0.35
|
||||||
|
private static let borderLineWidth: CGFloat = 1
|
||||||
|
private static let activeTextBrightness: Double = 0.12
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let pedalSwitch: PedalSwitch
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a segmented switch view.
|
||||||
|
///
|
||||||
|
/// - Parameter pedalSwitch: The discrete switch descriptor to render.
|
||||||
|
public init(_ pedalSwitch: PedalSwitch) {
|
||||||
|
self.pedalSwitch = pedalSwitch
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
// Reading `node.value` registers this view for @Observable re-render on change.
|
||||||
|
let current: Double = pedalSwitch.node.value
|
||||||
|
let selectedIndex: Int = nearestIndex(to: current)
|
||||||
|
|
||||||
|
VStack(spacing: PedalSwitchView.labelSpacing) {
|
||||||
|
HStack(spacing: PedalSwitchView.segmentSpacing) {
|
||||||
|
ForEach(Array(pedalSwitch.options.enumerated()), id: \.offset) { pair in
|
||||||
|
let option: PedalSwitch.Option = pair.element
|
||||||
|
let isActive: Bool = pair.offset == selectedIndex
|
||||||
|
segment(option: option, isActive: isActive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: PedalSwitchView.cornerRadius)
|
||||||
|
.stroke(Color.black.opacity(PedalSwitchView.borderOpacity),
|
||||||
|
lineWidth: PedalSwitchView.borderLineWidth)
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(pedalSwitch.label)
|
||||||
|
.font(.system(size: PedalSwitchView.captionFontSize))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Subviews
|
||||||
|
|
||||||
|
private func segment(option: PedalSwitch.Option, isActive: Bool) -> some View {
|
||||||
|
Button(action: {
|
||||||
|
pedalSwitch.node.update(option.value)
|
||||||
|
}) {
|
||||||
|
Text(option.title)
|
||||||
|
.font(.system(size: PedalSwitchView.fontSize, weight: .semibold))
|
||||||
|
.foregroundStyle(isActive
|
||||||
|
? Color(white: PedalSwitchView.activeTextBrightness)
|
||||||
|
: Color.white)
|
||||||
|
.padding(.vertical, PedalSwitchView.segmentPaddingV)
|
||||||
|
.padding(.horizontal, PedalSwitchView.segmentPaddingH)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: PedalSwitchView.cornerRadius)
|
||||||
|
.fill(Color.white.opacity(isActive
|
||||||
|
? PedalSwitchView.activeFillOpacity
|
||||||
|
: PedalSwitchView.inactiveFillOpacity))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
/// Index of the option whose `value` is nearest `value` — the lit segment.
|
||||||
|
private func nearestIndex(to value: Double) -> Int {
|
||||||
|
var bestIndex: Int = 0
|
||||||
|
var bestDistance: Double = .greatestFiniteMagnitude
|
||||||
|
for index: Int in pedalSwitch.options.indices {
|
||||||
|
let distance: Double = abs(pedalSwitch.options[index].value - value)
|
||||||
|
if distance < bestDistance {
|
||||||
|
bestDistance = distance
|
||||||
|
bestIndex = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -247,6 +247,7 @@ public struct PedalView: View {
|
|||||||
VStack(spacing: PedalView.sectionSpacing) {
|
VStack(spacing: PedalView.sectionSpacing) {
|
||||||
namePlate
|
namePlate
|
||||||
knobGrid
|
knobGrid
|
||||||
|
switchRow
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
bottomControls
|
bottomControls
|
||||||
}
|
}
|
||||||
@@ -312,6 +313,20 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Row of segmented switches drawn from `pedal.effectSwitches`, one per row, beneath
|
||||||
|
/// the knob grid. Renders nothing when the pedal publishes no switches.
|
||||||
|
@ViewBuilder
|
||||||
|
private var switchRow: some View {
|
||||||
|
let switches: [PedalSwitch] = pedal.effectSwitches
|
||||||
|
if !switches.isEmpty {
|
||||||
|
VStack(spacing: PedalView.knobSpacing) {
|
||||||
|
ForEach(Array(switches.enumerated()), id: \.offset) { pair in
|
||||||
|
PedalSwitchView(pair.element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Bottom control row: the `Level` knob and the bypass switch side-by-side, centred
|
/// Bottom control row: the `Level` knob and the bypass switch side-by-side, centred
|
||||||
/// with equal padding below.
|
/// with equal padding below.
|
||||||
private var bottomControls: some View {
|
private var bottomControls: some View {
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
// AutoWahPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("AutoWahPedal")
|
||||||
|
struct AutoWahPedalTests {
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
||||||
|
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: AutoWahPedal = AutoWahPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
let samples: [Float] = readStereoCAF(url: url)
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "AutoWahPedal produced silence")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func sensitivityChangesOutput() throws {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
|
||||||
|
func renderWithSensitivity(_ sensitivityValue: 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: AutoWahPedal = AutoWahPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
pedal.sensitivity = sensitivityValue
|
||||||
|
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 lowSensSamples: [Float] = try renderWithSensitivity(0.5)
|
||||||
|
let highSensSamples: [Float] = try renderWithSensitivity(4.0)
|
||||||
|
|
||||||
|
#expect(hasNonSilentOutput(lowSensSamples), "low-sensitivity render was silent")
|
||||||
|
#expect(hasNonSilentOutput(highSensSamples), "high-sensitivity render was silent")
|
||||||
|
|
||||||
|
let skipSamples: Int = 1024
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard lowSensSamples.count >= skipSamples + windowSize,
|
||||||
|
highSensSamples.count >= skipSamples + windowSize else { return }
|
||||||
|
|
||||||
|
let lowWindow: [Float] = Array(lowSensSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let highWindow: [Float] = Array(highSensSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let ssd: Double = zip(lowWindow, highWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "low and high sensitivity produced identical output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesSensitivityResonanceAndRangeKnobs() throws {
|
||||||
|
let pedal: AutoWahPedal = AutoWahPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Sensitivity", "Resonance", "Range"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// FeedbackDelayPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("FeedbackDelayPedal")
|
||||||
|
struct FeedbackDelayPedalTests {
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let renderDuration: Double = 0.3
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
||||||
|
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: FeedbackDelayPedal = FeedbackDelayPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
let samples: [Float] = readStereoCAF(url: url)
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "FeedbackDelayPedal produced silence")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func feedbackChangesOutput() throws {
|
||||||
|
// Render well past the first echo (time = 0.3 s) so regenerated repeats differ.
|
||||||
|
let renderDuration: Double = 0.8
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
|
||||||
|
func renderWithFeedback(_ feedbackValue: 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: FeedbackDelayPedal = FeedbackDelayPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
pedal.feedback = feedbackValue
|
||||||
|
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 shortFeedback: [Float] = try renderWithFeedback(0.2)
|
||||||
|
let longFeedback: [Float] = try renderWithFeedback(6.0)
|
||||||
|
|
||||||
|
#expect(hasNonSilentOutput(shortFeedback), "short-feedback render was silent")
|
||||||
|
#expect(hasNonSilentOutput(longFeedback), "long-feedback render was silent")
|
||||||
|
|
||||||
|
// Start the window after the second repeat (~0.6 s × 44100 × 2 channels).
|
||||||
|
let skipSamples: Int = 53000
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard shortFeedback.count >= skipSamples + windowSize,
|
||||||
|
longFeedback.count >= skipSamples + windowSize else { return }
|
||||||
|
|
||||||
|
let shortWindow: [Float] = Array(shortFeedback[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let longWindow: [Float] = Array(longFeedback[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let ssd: Double = zip(shortWindow, longWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "short and long feedback produced identical output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesTimeFeedbackAndToneKnobs() throws {
|
||||||
|
let pedal: FeedbackDelayPedal = FeedbackDelayPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Time", "Feedback", "Tone"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
// MuTronPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("MuTronPedal")
|
||||||
|
struct MuTronPedalTests {
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
||||||
|
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: MuTronPedal = MuTronPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
let samples: [Float] = readStereoCAF(url: url)
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "MuTronPedal produced silence")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func filterModesProduceDifferentOutput() throws {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
|
||||||
|
func renderWithMode(_ modeValue: 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: MuTronPedal = MuTronPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
pedal.mode = modeValue
|
||||||
|
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 lowpassSamples: [Float] = try renderWithMode(0.0)
|
||||||
|
let highpassSamples: [Float] = try renderWithMode(2.0)
|
||||||
|
|
||||||
|
#expect(hasNonSilentOutput(lowpassSamples), "lowpass render was silent")
|
||||||
|
#expect(hasNonSilentOutput(highpassSamples), "highpass render was silent")
|
||||||
|
|
||||||
|
let skipSamples: Int = 1024
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard lowpassSamples.count >= skipSamples + windowSize,
|
||||||
|
highpassSamples.count >= skipSamples + windowSize else { return }
|
||||||
|
|
||||||
|
let lowWindow: [Float] = Array(lowpassSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let highWindow: [Float] = Array(highpassSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let ssd: Double = zip(lowWindow, highWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "lowpass and highpass modes produced identical output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func presetRoundTripPreservesSwitchPositions() throws {
|
||||||
|
let pedal: MuTronPedal = MuTronPedal()
|
||||||
|
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()
|
||||||
|
restored.applyState(state)
|
||||||
|
#expect(restored.mode == 2.0)
|
||||||
|
#expect(restored.direction == 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesSensitivityAndResonanceKnobs() throws {
|
||||||
|
let pedal: MuTronPedal = MuTronPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Sensitivity", "Resonance"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesTwoStateSweepAndThreeStateModeSwitches() throws {
|
||||||
|
let pedal: MuTronPedal = MuTronPedal()
|
||||||
|
let switches: [PedalSwitch] = pedal.effectSwitches
|
||||||
|
#expect(switches.map { $0.label } == ["Sweep", "Mode"])
|
||||||
|
// Two-state sweep (Down/Up), three-state mode (LP/BP/HP).
|
||||||
|
#expect(switches.first?.options.map { $0.title } == ["Down", "Up"])
|
||||||
|
#expect(switches.last?.options.map { $0.title } == ["LP", "BP", "HP"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func sweepDirectionChangesOutput() throws {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
|
||||||
|
func renderWithDirection(_ directionValue: 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: MuTronPedal = MuTronPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
pedal.direction = directionValue
|
||||||
|
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 downSamples: [Float] = try renderWithDirection(0.0)
|
||||||
|
let upSamples: [Float] = try renderWithDirection(1.0)
|
||||||
|
|
||||||
|
#expect(hasNonSilentOutput(downSamples), "down-sweep render was silent")
|
||||||
|
#expect(hasNonSilentOutput(upSamples), "up-sweep render was silent")
|
||||||
|
|
||||||
|
let skipSamples: Int = 1024
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard downSamples.count >= skipSamples + windowSize,
|
||||||
|
upSamples.count >= skipSamples + windowSize else { return }
|
||||||
|
|
||||||
|
let downWindow: [Float] = Array(downSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let upWindow: [Float] = Array(upSamples[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let ssd: Double = zip(downWindow, upWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "down and up sweep produced identical output")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// MultiTapDelayPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("MultiTapDelayPedal")
|
||||||
|
struct MultiTapDelayPedalTests {
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let renderDuration: Double = 0.3
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
||||||
|
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: MultiTapDelayPedal = MultiTapDelayPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
let samples: [Float] = readStereoCAF(url: url)
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "MultiTapDelayPedal produced silence")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func tapVolumeChangesOutput() throws {
|
||||||
|
// Render past tap 3's onset (0.36 s) so its echo is actually present.
|
||||||
|
let renderDuration: Double = 0.6
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
|
||||||
|
func renderWithTap3Volume(_ volValue: 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: MultiTapDelayPedal = MultiTapDelayPedal(
|
||||||
|
inputBus: srcBus.index,
|
||||||
|
outputBus: dstBus.index
|
||||||
|
)
|
||||||
|
pedal.vol3 = volValue
|
||||||
|
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 quietTap: [Float] = try renderWithTap3Volume(0.0)
|
||||||
|
let loudTap: [Float] = try renderWithTap3Volume(1.0)
|
||||||
|
|
||||||
|
#expect(hasNonSilentOutput(quietTap), "muted-tap render was silent")
|
||||||
|
#expect(hasNonSilentOutput(loudTap), "loud-tap render was silent")
|
||||||
|
|
||||||
|
// 0.36 s × 44100 ≈ 15876 frames × 2 channels — start the window after tap 3 fires.
|
||||||
|
let skipSamples: Int = 34000
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard quietTap.count >= skipSamples + windowSize,
|
||||||
|
loudTap.count >= skipSamples + windowSize else { return }
|
||||||
|
|
||||||
|
let quietWindow: [Float] = Array(quietTap[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let loudWindow: [Float] = Array(loudTap[skipSamples..<(skipSamples + windowSize)])
|
||||||
|
let ssd: Double = zip(quietWindow, loudWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "tap-3 volume change produced no difference")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesSixKnobsInTwoRowsOfThree() throws {
|
||||||
|
let pedal: MultiTapDelayPedal = MultiTapDelayPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Time 1", "Time 2", "Time 3", "Vol 1", "Vol 2", "Vol 3"])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user