2772abdc56
Tempo sync - Lock a delay time or modulation LFO rate to a note division (whole..sixteenth, dotted, triplet) of the shared clock. Value is derived from the tempo and follows tap tempo, the stepper, the editable BPM field, and MIDI. - Delay time: Delay, FeedbackDelay, PingPong, ReverseDelay, MultiTap (per tap). LFO rate (inverse mapping): Tremolo, Vibrato, Chorus, Flanger, Phaser, Modulation. - Core types NoteDivision / TempoSync / TempoSyncableParam; Pedal.tempoSyncableParams / tempoSync / applyTempoSync / setSync; ShoeGaze.setBpm broadcast recomputes all pedals; tempoSync persisted in PedalState (lenient decode) and recomputed on load + recall. - Observable TempoSyncRevision so the sync badge refreshes on any state-change path. UI - Division picker with drawn music-notation glyphs (NoteGlyphView + rasterized cache): noteheads, stems, flags, augmentation dot, bracketed 3 for triplets. Presented as a height-capped popover so it stays on-screen on iOS. - Editable BPM text field: integer-only, live-filtered, clamped 30-300, commit on return / Done / blur. - Divisions that clamp at the current tempo are disabled in the picker; an active clamped sync shows a warning marker. - In-context control mapping badges (PC / CC / KEY) per pedal control, with a legend. Delays - Maximum delay time raised to 5 s across the delay pedals (was 1-2 s). Docs: CHANGELOG.md, RELEASES.md, docs/plans/2.2-tempo-synced-parameters.md. All 454 tests pass; passed lyrebird_external_review (RT-safe, main-thread param writes). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
3.1 KiB
Swift
71 lines
3.1 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(
|
|
id: id,
|
|
type: displayName,
|
|
knobValues: values,
|
|
switchValues: switchValues,
|
|
sliderValues: sliderValues,
|
|
selectorValues: selectorValues,
|
|
bypass: bypass,
|
|
tempoSync: tempoSync.isEmpty ? nil : tempoSync
|
|
)
|
|
}
|
|
|
|
/// 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) {
|
|
// Restore the saved identity so the pedal keeps its id across rebuilds; MIDI bindings
|
|
// address pedals by this id.
|
|
id = state.id
|
|
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
|
|
// Restore tempo-sync state. The synced values themselves are recomputed from the rig's
|
|
// tempo by `ShoeGaze` after the rebuild, so no clock is required here.
|
|
tempoSync = state.tempoSync ?? [:]
|
|
tempoSyncRevision.bump()
|
|
}
|
|
}
|