// PedalSelectorKnob.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdUI /// A UI-agnostic description of a knob that snaps to a fixed set of labelled stops. /// /// Where ``PedalKnob`` is a continuous rotary and ``PedalSwitch`` is a segmented strip, a /// `PedalSelectorKnob` reads like a rotary knob but quantises to discrete positions — a knob picker. /// Dragging rotates through the stops; the knob shows the current stop's caption. A `Pedal` /// publishes an array of these via ``Pedal/effectSelectors`` so a generic pedalboard UI can render /// a stepped knob per discrete parameter without knowing the concrete type. /// /// Each stop pairs a short caption with the exact `Double` written to the live ``UIParamNode`` when /// that position is selected; the lit position is the stop whose `value` is nearest the node's /// current value. public struct PedalSelectorKnob { /// One labelled position of a ``PedalSelectorKnob``. public struct Stop { /// Short caption shown under the knob when this position is selected (e.g. "M3", "Oct"). public let title: String /// Value written to the node when this position is selected. public let value: Double /// Creates a selector stop. /// /// - Parameters: /// - title: Short caption shown when this position is selected. /// - 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 knob (e.g. "Voice 1"). public let label: String /// The live parameter node the knob reads and writes. Pass `pedal.$paramName`. public let node: UIParamNode /// Ordered stops the knob snaps through, from fully counter-clockwise to fully clockwise. Must /// contain at least two. public let stops: [Stop] /// When `true`, committing a new stop asks the host to rebuild the board (as the Neural Amp /// model loader does) instead of relying on the live graph to react to the node value. Use for /// selectors whose choice changes the *graph topology* — e.g. a cabinet whose voice picks which /// single convolver is instantiated — rather than a value an always-running node reads live. /// Defaults to `false`. public let rebuildsOnChange: Bool /// Creates a selector-knob descriptor. /// /// - Parameters: /// - label: Short label shown beneath the knob. /// - node: The `UIParamNode` projected value of an `@UIParam` property (`pedal.$voice1`, …). /// - stops: Ordered stops, CCW → CW. At least two. /// - rebuildsOnChange: Ask the host to rebuild the board when a new stop is committed. Use for /// selectors that change graph topology. Defaults to `false`. public init( label: String, node: UIParamNode, stops: [Stop], rebuildsOnChange: Bool = false ) { precondition(stops.count >= 2, "PedalSelectorKnob requires at least two stops") self.label = label self.node = node self.stops = stops self.rebuildsOnChange = rebuildsOnChange } }