Files
ShoeGaze/Sources/LyrebirdShoeGaze/PedalSwitch.swift
T
josh cb28ea8c7d Add segmented pedal switch control; Mu-Tron sweep + mode switches
Introduces a discrete multi-position switch control alongside the rotary
knobs, and uses it to expose the Mu-Tron's sweep direction and filter mode.

- PedalSwitch: UI-agnostic descriptor (label, node, ordered options of
  caption + value), parallel to PedalKnob. Two options make a two-state
  switch, three a three-state switch.
- PedalSwitchView: segmented SwiftUI control bound to a UIParamNode. Lit
  segment is the option nearest the node's value; tapping writes that
  option's value. Serves both two- and three-state switches.
- Pedal gains an effectSwitches hook; PedalView renders a switch row
  between the knob grid and the footswitch.
- MuTronPedal: sweep direction is now a two-state switch (Down/Up) and
  filter mode a three-state switch (LP/BP/HP). The effect builds six
  MuTronIII instances (three modes x two directions) selected by a nested
  Select so every filter state stays warmed for click-free switching.
- Presets: PedalState gains a backward-compatible switchValues array
  (decodes to empty for older presets); captureState/applyState persist
  and restore switch positions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 15:40:26 -07:00

70 lines
2.6 KiB
Swift

// 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
}
}