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:
@@ -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)")
|
||||
|
||||
@@ -31,7 +31,7 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
// 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`).
|
||||
@@ -64,7 +64,7 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
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)")
|
||||
}
|
||||
@@ -182,7 +182,7 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
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] fallback seed board failed: \(error)")
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ let engine = SynthesisEngine(
|
||||
|
||||
let shoeGaze = ShoeGaze(engine: engine) // defaults to the test-loop signal
|
||||
let board = try shoeGaze.addBoard()
|
||||
try shoeGaze.appendPedal(type: "Overdrive", to: board)
|
||||
try shoeGaze.appendPedal(type: "Delay", to: board)
|
||||
try shoeGaze.appendPedal(.overdrive, to: board)
|
||||
try shoeGaze.appendPedal(.delay, to: board)
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
|
||||
try engine.start()
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,11 +55,11 @@ struct ShoeGazeMultiBoardTests {
|
||||
let shoeGazeA: ShoeGaze = ShoeGaze(engine: engineA)
|
||||
let board1: PedalBoard = try shoeGazeA.addBoard()
|
||||
board1.label = "Lead"
|
||||
try shoeGazeA.appendPedal(type: "Overdrive", to: board1)
|
||||
try shoeGazeA.appendPedal(.overdrive, to: board1)
|
||||
try shoeGazeA.finalizeBoard(board1)
|
||||
let board2: PedalBoard = try shoeGazeA.addBoard()
|
||||
board2.label = "Clean"
|
||||
try shoeGazeA.appendPedal(type: "Graphic EQ", to: board2)
|
||||
try shoeGazeA.appendPedal(.graphicEQ, to: board2)
|
||||
try shoeGazeA.finalizeBoard(board2)
|
||||
|
||||
let snapshot: Data = try shoeGazeA.rigData()
|
||||
|
||||
Reference in New Issue
Block a user