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>
This commit is contained in:
2026-06-21 15:40:26 -07:00
parent c28e7cac90
commit cb28ea8c7d
8 changed files with 403 additions and 29 deletions
@@ -17,9 +17,11 @@ extension Pedal {
/// - Returns: A `PedalState` reflecting the pedal's current parameter values.
public func captureState() -> PedalState {
let values: [Double] = knobs.map { $0.node.value }
let switchValues: [Double] = effectSwitches.map { $0.node.value }
return PedalState(
type: displayName,
knobValues: values,
switchValues: switchValues,
bypass: bypass
)
}
@@ -27,10 +29,12 @@ extension Pedal {
/// Applies a previously captured `PedalState` to this pedal's parameters.
///
/// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's
/// `UIParamNode` is updated via `node.update(_:)`. If `state.knobValues` has
/// fewer entries than `knobs`, the trailing knobs retain their current values.
/// Extra values beyond `knobs.count` are ignored. The `bypass` parameter is
/// always applied regardless of knob-count mismatches.
/// `UIParamNode` is updated via `node.update(_:)`; switch positions are restored the
/// same way from `zip(effectSwitches, state.switchValues)`. If either array has fewer
/// entries than its controls, the trailing controls retain their current values; extra
/// values are ignored. The `bypass` parameter is always applied regardless of any
/// count mismatch. Presets saved before switches existed carry an empty
/// `switchValues`, leaving switch positions at their defaults.
///
/// - Parameter state: The state to restore. The `state.type` is not validated
/// against `displayName` — the caller is responsible for matching types before
@@ -39,6 +43,9 @@ extension Pedal {
for (knob, value) in zip(knobs, state.knobValues) {
knob.node.update(value)
}
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
pedalSwitch.node.update(value)
}
bypass = state.bypass
}
}
@@ -22,6 +22,10 @@ public struct PedalState: Codable, Equatable {
/// Knob values in the same order as `Pedal.knobs` (effect knobs then Mix, Level).
public let knobValues: [Double]
/// Switch values in the same order as `Pedal.effectSwitches`. Empty for pedals with
/// no switches. Absent in presets saved before switches existed — decodes to `[]`.
public let switchValues: [Double]
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
public let bypass: Double
@@ -30,14 +34,34 @@ public struct PedalState: Codable, Equatable {
/// - Parameters:
/// - type: The pedal's `displayName`, used to identify the pedal type on load.
/// - knobValues: Current knob values in `Pedal.knobs` order.
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
public init(
type: String,
knobValues: [Double],
switchValues: [Double] = [],
bypass: Double
) {
self.type = type
self.knobValues = knobValues
self.switchValues = switchValues
self.bypass = bypass
}
private enum CodingKeys: String, CodingKey {
case type
case knobValues
case switchValues
case bypass
}
/// Decodes a snapshot, tolerating presets saved before `switchValues` existed by
/// defaulting the missing key to an empty array.
public init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
self.type = try container.decode(String.self, forKey: .type)
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
self.bypass = try container.decode(Double.self, forKey: .bypass)
}
}