// PedalRebuildEnvironment.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI import LyrebirdSynth import LyrebirdShoeGaze /// Environment action a leaf pedal control can call to ask the host to rebuild the board that /// contains the given pedal — needed when a pedal setting that is *not* a live `@UIParam` (e.g. /// the Neural Amp's model file, stored in ``Pedal/resourcePath``) changes and only takes effect /// after the pedal's graph is rebuilt. Set once near the builder root; defaults to a no-op. private struct PedalRebuildActionKey: EnvironmentKey { static let defaultValue: @MainActor @Sendable (Pedal) -> Void = { _ in } } extension EnvironmentValues { /// Rebuilds the board containing the passed pedal. No-op unless the host installs it. var pedalRebuildAction: @MainActor @Sendable (Pedal) -> Void { get { self[PedalRebuildActionKey.self] } set { self[PedalRebuildActionKey.self] = newValue } } } /// Environment action a leaf pedal control calls when the user finishes changing it, so the host /// can record one undo checkpoint per edit. Arguments: the control's group, its label, and the /// values before and after the edit. ``PedalView`` installs it capturing the pedal's id and the /// undo coordinator; it defaults to a no-op, so a control outside the builder records nothing. private struct PedalParameterEditRecorderKey: EnvironmentKey { static let defaultValue: @MainActor @Sendable (PedalControlGroup, String, Double, Double) -> Void = { _, _, _, _ in } } extension EnvironmentValues { /// Records a finished parameter edit (group, control label, old value, new value). No-op unless /// the host installs it. var pedalParameterEditRecorder: @MainActor @Sendable (PedalControlGroup, String, Double, Double) -> Void { get { self[PedalParameterEditRecorderKey.self] } set { self[PedalParameterEditRecorderKey.self] = newValue } } }