From 900b441082333b682de2b8c6ffe373563dcb5680 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Fri, 26 Jun 2026 19:29:06 -0700 Subject: [PATCH] Review fixes: cache pedal summaries; stop engine around Clear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PedalRegistry.summaries caches displayName→summary once, so the picker no longer constructs a fresh Pedal per row on every render. - performClear stops the engine around the remove-all + reseed and restarts it, avoiding a one-block bus-reuse glitch (same pattern as loadRig/setInputSource). Co-Authored-By: Claude Opus 4.8 --- .../Presets/PedalRegistry.swift | 18 +++++++++++++----- .../ShoeGazeBuilderView.swift | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index 5e41797..2b36334 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -70,16 +70,24 @@ public enum PedalRegistry { return constructor() } + /// Cached `displayName → summary` map for all built-in pedals, built once by instantiating + /// each pedal a single time (no `build()` / engine work). Lets the picker look up + /// descriptions per row without reconstructing a pedal on every render. + @MainActor + public static let summaries: [String: String] = { + var map: [String: String] = [:] + for type: String in builtIn.keys { + map[type] = makePedal(type: type)?.summary ?? "" + } + return map + }() + /// Returns the `summary` description for a built-in pedal type, or `""` if unknown. /// - /// Instantiates the pedal to read its `summary` — cheap, since constructing a `Pedal` - /// does not call `build()` or touch the engine. Intended for the pedal picker, which has - /// only the type string; callers that render many rows should cache the result. - /// /// - Parameter type: The `displayName` of the pedal. /// - Returns: The pedal's one-line `summary`, or `""` for unknown types. @MainActor public static func summary(for type: String) -> String { - makePedal(type: type)?.summary ?? "" + summaries[type] ?? "" } } diff --git a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift index f80f605..e86737b 100644 --- a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift +++ b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift @@ -440,6 +440,11 @@ public struct ShoeGazeBuilderView: View { /// Removes every board, then seeds one fresh empty board so the builder is never boardless. /// Resets the edit target and autosaves the cleared state. private func performClear() { + // Stop around the rebuild so removing every board and immediately re-adding a fresh one + // can't reuse a bus a just-removed master is still draining (one-block glitch). + let wasRunning: Bool = shoeGaze.engine.isRunning + if wasRunning { shoeGaze.engine.stop() } + // Snapshot before removing — removeBoard mutates shoeGaze.boards. for board: PedalBoard in Array(shoeGaze.boards) { shoeGaze.removeBoard(board) @@ -452,6 +457,8 @@ public struct ShoeGazeBuilderView: View { print("[ShoeGazeBuilderView] clear failed to seed a fresh board: \(error)") } selectedBoardIndex = 0 + + if wasRunning { try? shoeGaze.engine.start() } autosave() transportTick.toggle() }