// PedalSwitch.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdUI /// A UI-agnostic description of one multi-position pedal switch. /// /// Where ``PedalKnob`` describes a continuous rotary control, `PedalSwitch` describes a /// discrete segmented switch with a fixed set of labelled positions — a two-state toggle /// (e.g. sweep Up / Down) or a three-state selector (e.g. filter LP / BP / HP). A `Pedal` /// publishes an array of these via ``Pedal/effectSwitches`` so a generic pedalboard UI can /// render a segmented control per discrete parameter without knowing the concrete type. /// /// Each option pairs a short caption with the exact `Double` written to the live /// ``UIParamNode`` when that position is selected; the currently-lit segment is the option /// whose `value` is nearest the node's current value. public struct PedalSwitch { /// One labelled position of a ``PedalSwitch``. public struct Option { /// Short caption shown inside the segment (e.g. "Up", "BP"). public let title: String /// Value written to the switch's node when this position is selected. public let value: Double /// Creates a switch position. /// /// - Parameters: /// - title: Short caption shown inside the segment. /// - value: Value written to the node when this position is selected. public init(title: String, value: Double) { self.title = title self.value = value } } /// Short label shown beneath the segmented control (e.g. "Mode", "Sweep"). public let label: String /// The live parameter node the switch reads and writes. Pass `pedal.$paramName`. public let node: UIParamNode /// Ordered positions, left to right. Two entries make a two-state switch, three a /// three-state switch. Must contain at least two options. public let options: [Option] /// Creates a switch descriptor. /// /// - Parameters: /// - label: Short label shown beneath the segmented control. /// - node: The `UIParamNode` projected value of an `@UIParam` property /// (`pedal.$mode`, `pedal.$direction`, …). /// - options: Ordered switch positions, left to right. At least two. public init( label: String, node: UIParamNode, options: [Option] ) { precondition(options.count >= 2, "PedalSwitch requires at least two options") self.label = label self.node = node self.options = options } }