// 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: Equatable { /// 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)? /// Optional LED-indicator node for a `.momentary` button. When non-`nil`, the button is /// drawn in the same LED + footswitch style as a `.toggle` button, with the LED lit while /// this node reads `≥ 0.5` — letting a momentary action reflect a persistent state (e.g. a /// looper's Stop lit while stopped, Cue Stop lit while armed). `nil` renders a plain button. public let indicator: UIParamNode? /// Optional live caption describing what the *next* press does, polled by the UI. When set, /// the button shows this instead of the static `label` — letting a state-driven control (the /// looper's Loop footswitch) read "Record" → "Set End" → "Overdub" → "Play" as the state /// changes. `nil` shows the static `label`. public let dynamicLabel: (() -> String)? /// Creates a momentary action button. /// /// - Parameters: /// - label: Short label shown on the button. /// - indicator: Optional state node driving an LED (see ``indicator``). Defaults to `nil` /// for a plain button. /// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``). /// - action: Closure run on each press. public init( label: String, indicator: UIParamNode? = nil, dynamicLabel: (() -> String)? = nil, action: @escaping () -> Void ) { self.label = label self.style = .momentary self.node = nil self.action = action self.indicator = indicator self.dynamicLabel = dynamicLabel } /// 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.$loopOn`, `pedal.$reverse`, …). /// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``). public init(label: String, node: UIParamNode, dynamicLabel: (() -> String)? = nil) { self.label = label self.style = .toggle self.node = node self.action = nil self.indicator = nil self.dynamicLabel = dynamicLabel } }