Review fixes: cache pedal summaries; stop engine around Clear

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 19:29:06 -07:00
parent 8c701af128
commit 900b441082
2 changed files with 20 additions and 5 deletions
@@ -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] ?? ""
}
}
@@ -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()
}