Replace stringly-typed pedal API with PedalType tokens
appendPedal(type: String, to:) is replaced by appendPedal(_ kind: PedalType, to:),
where PedalType is an extensible RawRepresentable struct with static members for
the built-in pedals:
try shoeGaze.appendPedal(.overdrive, to: board)
Discoverable/autocompleting call sites, still open for custom pedals
(PedalType("My Pedal")). rawValue == the pedal's displayName, so PedalRegistry
and the rig JSON format are unchanged — saved rigs load exactly as before.
Named PedalType (not PedalKind) to avoid colliding with Lyrebird's score-notation
PedalKind enum, which is visible when both modules are imported. The UI palette
wraps its registry-key strings as PedalType(key); demos/tests use the static
members. PedalRegistry.makePedal(type:) stays string-keyed as the serialization
boundary used by loadRig.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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 muTron = PedalType("Mu-Tron")
|
||||
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")
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)") }
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -373,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)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user