eafc68d283
Harmonizer: two granular PitchShift voices at fixed musical intervals (ratio 2^(semitones/12) via Exp), mixed under the dry signal with V1/V2/ Direct level knobs. Two interval "knob pickers" snap through octave, fifth, fourth, and minor/major third and sixth above and below. New reusable control: - PedalSelectorKnob (model) + PedalSelectorKnobView (rotary knob that snaps to labelled stops; drag up/down to step, shows the stop caption). - Pedal.effectSelectors hook; PedalView renders a selector row. - PedalState.selectorValues for preset round-trip (forward-compatible). Registered + PedalType.harmonizer + enclosure color + palette slot. Tests: build/non-silent, interval-change-changes-output, selector preset round-trip, registry. Full suite 213 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
2.6 KiB
Swift
62 lines
2.6 KiB
Swift
// Pedal+Preset.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
extension Pedal {
|
|
|
|
/// Captures the current parameter values of this pedal as a `PedalState`.
|
|
///
|
|
/// The returned snapshot includes:
|
|
/// - `type`: the pedal's `displayName` (used as a factory key on load).
|
|
/// - `knobValues`: one `Double` per entry in `knobs`, in order
|
|
/// (effect-specific knobs first, then Mix, then Level).
|
|
/// - `bypass`: the current bypass parameter value.
|
|
///
|
|
/// - 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 }
|
|
let sliderValues: [Double] = effectSliders.map { $0.node.value }
|
|
let selectorValues: [Double] = effectSelectors.map { $0.node.value }
|
|
return PedalState(
|
|
type: displayName,
|
|
knobValues: values,
|
|
switchValues: switchValues,
|
|
sliderValues: sliderValues,
|
|
selectorValues: selectorValues,
|
|
bypass: bypass
|
|
)
|
|
}
|
|
|
|
/// 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(_:)`; 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
|
|
/// calling this method.
|
|
public func applyState(_ state: PedalState) {
|
|
for (knob, value) in zip(knobs, state.knobValues) {
|
|
knob.node.update(value)
|
|
}
|
|
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
|
|
pedalSwitch.node.update(value)
|
|
}
|
|
for (slider, value) in zip(effectSliders, state.sliderValues) {
|
|
slider.node.update(value)
|
|
}
|
|
for (selector, value) in zip(effectSelectors, state.selectorValues) {
|
|
selector.node.update(value)
|
|
}
|
|
bypass = state.bypass
|
|
}
|
|
}
|