// PedalButton.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdUI /// A UI-agnostic description of one pedal button — a momentary action trigger or a /// node-bound toggle, rendered as a stomp-style button. /// /// Where ``PedalSwitch`` describes a multi-position segmented control, `PedalButton` /// describes a single button in one of two styles: /// - `.momentary`: runs a closure on each press (e.g. "Record / Stop", "Reset"). Use this /// whenever pressing the button must also perform a non-RT side effect (clearing a /// buffer, requesting a recorder reset) beyond writing a single parameter value. /// - `.toggle`: flips a bound ``UIParamNode`` between `0` and `1` on each press, with no /// side effect required — appropriate only when the live audio graph itself reads the /// node continuously (so toggling the raw value is sufficient). /// /// A `Pedal` publishes an array of these via ``Pedal/effectButtons`` so a generic /// pedalboard UI can render a footswitch-style button per action without knowing the /// concrete pedal type. public struct PedalButton { /// Style of button behavior, mirroring `ParameterButton.Style` in `LyrebirdUI`. public enum Style { /// Executes `action` on each press. case momentary /// Flips `node` between `0` and `1` on each press. case toggle } /// Short label shown on the button (e.g. "Record", "Reset"). public let label: String /// Button behavior style. public let style: Style /// The live parameter node this button toggles. Non-`nil` only for `.toggle` style. public let node: UIParamNode? /// The action run on each press. Non-`nil` only for `.momentary` style. public let action: (() -> Void)? /// Creates a momentary action button. /// /// - Parameters: /// - label: Short label shown on the button. /// - action: Closure run on each press. public init(label: String, action: @escaping () -> Void) { self.label = label self.style = .momentary self.node = nil self.action = action } /// Creates a toggle button bound to a `UIParamNode`. /// /// - Parameters: /// - label: Short label shown on the button. /// - node: The `UIParamNode` projected value of an `@UIParam` property /// (`pedal.$overdubOn`, `pedal.$loopOn`, …). public init(label: String, node: UIParamNode) { self.label = label self.style = .toggle self.node = node self.action = nil } }