2ba57cadd6
Monophonic octave-down pedal with OCT1/OCT2/Direct knobs and a Mode switch between two algorithms: - Flip-flop (default): a hysteresis comparator clocks a T flip-flop divider chain (new SubOctaveDivider generator) to produce square sub-octaves one and two octaves down, amplitude-followed off the dry signal. Time-domain — tracks low bass with no detection floor. - Tracking: FreqTracker drives square oscillators at half and quarter the detected frequency. Cleaner, but limited by the tracker's ~90 Hz floor; flip-flop is the bass mode. SubOctaveDivider classifies its input as generator-or-scalar at init to keep _computeSamples allocation-free, uses a shared file-scope zero block, bounds-checks the input read, and traps on divisor < 2. Tests: BassOctaverPedal integration (both modes non-silent, modes differ, sub-octaves change output, knobs/switch/preset/registry) and SubOctaveDivider deterministic frequency-division (divisor 2 -> /2, divisor 4 -> /4, /4 one octave below /2). 127 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
3.2 KiB
Swift
66 lines
3.2 KiB
Swift
// PedalRegistry.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/// A factory registry mapping built-in pedal display names to their constructors.
|
|
///
|
|
/// `PedalRegistry` is the authoritative lookup used by `ShoeGaze.loadRig(from:)` to
|
|
/// instantiate the correct `Pedal` subclass for each `PedalState.type` string found
|
|
/// in a saved preset. Unknown type strings return `nil` from `makePedal(type:)` and
|
|
/// are silently skipped by the loader.
|
|
///
|
|
/// 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.
|
|
///
|
|
/// > 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.
|
|
/// > Ping-Pong) appears in that chain it round-trips fully — `board.add(_:)` replays the
|
|
/// > mono → stereo width transition on load. Parallel sections (`split()`/`merge()`) and
|
|
/// > stereo split regions (`splitStereo()`) are *not* part of the captured linear chain
|
|
/// > and are therefore not serialized.
|
|
public enum PedalRegistry {
|
|
|
|
/// Maps each built-in pedal display name to a `@MainActor` no-argument constructor.
|
|
///
|
|
/// Keys are the `displayName` values returned by the corresponding `Pedal` subclass.
|
|
/// Values are closures that allocate a fresh instance with default bus indices —
|
|
/// `ShoeGaze.loadRig(from:)` updates `inputBus`/`outputBus` when adding the pedal
|
|
/// to a board via `board.add(_:)`.
|
|
public static let builtIn: [String: @MainActor () -> Pedal] = [
|
|
"Overdrive": { OverdrivePedal() },
|
|
"Delay": { DelayPedal() },
|
|
"Reverb": { ReverbPedal() },
|
|
"Modulation": { ModulationPedal() },
|
|
"Fuzz": { FuzzPedal() },
|
|
"Tremolo": { TremoloPedal() },
|
|
"Phaser": { PhaserPedal() },
|
|
"Compressor": { CompressorPedal() },
|
|
"Mu-Tron": { MuTronPedal() },
|
|
"Auto-Wah": { AutoWahPedal() },
|
|
"Feedback Delay": { FeedbackDelayPedal() },
|
|
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
|
"Octave Splitter": { OctaveUpSplitterPedal() },
|
|
"Bass Octaver": { BassOctaverPedal() },
|
|
"Ping-Pong": { PingPongDelayPedal() },
|
|
]
|
|
|
|
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
|
/// is not in the built-in registry.
|
|
///
|
|
/// The returned pedal has default bus indices (`inputBus: 0`, `outputBus: 0`);
|
|
/// the caller is responsible for routing it via `board.add(_:)` before the engine
|
|
/// processes any audio.
|
|
///
|
|
/// - Parameter type: The `displayName` of the pedal (e.g. `"Overdrive"`, `"Delay"`).
|
|
/// - Returns: A freshly allocated `Pedal` subclass instance, or `nil` for unknown types.
|
|
@MainActor
|
|
public static func makePedal(type: String) -> Pedal? {
|
|
guard let constructor: @MainActor () -> Pedal = builtIn[type] else { return nil }
|
|
return constructor()
|
|
}
|
|
}
|