1893576718
Headline: MIDI control for a Behringer FCB1010 (four phases). - MIDIController (Lyrebird MIDI client): connection indicator via source polling, background-queue->main-actor hop, MIDI Learn. - Volume and Wah pedals (Wah reuses the SVF bandpass sweep, driven by pedal position instead of an envelope follower). - CC -> any pedal knob (0-127 mapped across the knob range). - Program Change -> pedal/board/rig toggles: software latch for booleans, exclusive radio for board solo. Positional addressing with display-name hints; stale/out-of-range bindings are skipped, not fired. - Per-rig MIDIMap embedded in ShoeGazeState as an optional field (old rigs decode to nil; no preset version bump). Central MIDI Mapping sheet with Learn/Clear per control. Also included (same working branch): - Full board bypass and rig bypass (dry passthrough via cascaded crossfades in BoardOutputMaster), with UI toggles. - Horizontal pedal picker grouped by category in filter order. - Drag a palette pedal onto a chain card to insert before it (ShoeGaze.insertPedal); tap still appends. - iOS: guard macOS-only .menuStyle(.borderlessButton) to silence the _UIReparentingView warning; iCloud-unavailable alert; keep the device awake while audio runs. Tests: 24 added (Volume/Wah, MIDIMap Codable incl. legacy decode, CC and PC controller behavior, insert/bypass API). Full suite green; macOS and iOS app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
106 lines
3.6 KiB
Swift
106 lines
3.6 KiB
Swift
// WahPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Foot-swept wah pedal — a resonant bandpass whose cutoff follows the expression-pedal position.
|
||
///
|
||
/// Reuses the same filter voice as ``AutoWahPedal`` (a resonant `SVF` bandpass swept through an
|
||
/// exponential `LinExp` frequency map) but drives the sweep from the `position` knob instead of an
|
||
/// amplitude follower: `0` = heel (low, dark) → `1` = toe (high, bright). The position is smoothed
|
||
/// so hand or MIDI sweeps are click-free.
|
||
///
|
||
/// ## Signal path
|
||
/// ```
|
||
/// position → Lag → LinExp(freqLo…freqHi) → SVF.bandpass(q: resonance)
|
||
/// ↑freq
|
||
/// ```
|
||
///
|
||
/// ## Knobs
|
||
/// - `position`: Sweep position in `[0, 1]`. `0` = low cutoff, `1` = high cutoff.
|
||
/// - `resonance`: Bandpass Q. Higher values sharpen the wah vowel.
|
||
public final class WahPedal: Pedal {
|
||
|
||
/// One-line description shown in the picker and info panel.
|
||
public override var summary: String {
|
||
"Foot-swept resonant filter — the classic wah voice, driven by pedal position."
|
||
}
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Expression-pedal position in `[0, 1]`. `0` = heel (low cutoff), `1` = toe (high cutoff).
|
||
@UIParam public var position: Double = 0.5
|
||
|
||
/// Bandpass resonance (SVF quality factor). Higher values sharpen the wah vowel.
|
||
@UIParam public var resonance: Double = 3.0
|
||
|
||
// MARK: - Constants
|
||
|
||
private static let defaultMix: Double = 1.0
|
||
|
||
/// Cutoff at heel (`position == 0`), in Hz. `LinExp` requires a strictly positive lower bound.
|
||
private let freqLo: Double = 400.0
|
||
|
||
/// Cutoff at toe (`position == 1`), in Hz.
|
||
private let freqHi: Double = 2200.0
|
||
|
||
/// Smoothing time constant in seconds for the position sweep — prevents zipper noise when the
|
||
/// position jumps (e.g. coarse 0–127 steps from a MIDI expression pedal).
|
||
private let smoothingTime: Double = 0.02
|
||
|
||
// MARK: - Ranges
|
||
|
||
private let positionRange: ClosedRange<Double> = 0.0 ... 1.0
|
||
private let resonanceRange: ClosedRange<Double> = 0.5 ... 8.0
|
||
|
||
// MARK: - Knobs
|
||
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Position", node: $position, range: positionRange),
|
||
PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a wah pedal.
|
||
///
|
||
/// - Parameters:
|
||
/// - inputBus: Audio bus to read the dry input from. Defaults to `0`; set by the board.
|
||
/// - outputBus: Audio bus to write the filtered output to. Defaults to `0`; set by the board.
|
||
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||
super.init(
|
||
name: "Wah",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: WahPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
// Smooth the position, map it exponentially to a cutoff sweep, and drive a resonant
|
||
// bandpass — the wah voice following the pedal rather than the signal envelope.
|
||
let smoothed: Lag.Control = Lag.Control(input: $position, time: smoothingTime)
|
||
let cutoff: LinExp.Audio = LinExp.Audio(
|
||
smoothed,
|
||
inLo: 0.0,
|
||
inHi: 1.0,
|
||
outLo: freqLo,
|
||
outHi: freqHi
|
||
)
|
||
let filtered: SVF.Audio = SVF.Audio(
|
||
input: dry,
|
||
freq: cutoff,
|
||
q: $resonance
|
||
)
|
||
return filtered.bandpass
|
||
}
|
||
}
|