Release 2.1.0: tempo-synced pedal parameters, editable BPM, control mapping badges
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>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// NoteDivision.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A rhythmic note value, expressed as a fraction of a bar and measured in quarter-note beats.
|
||||
///
|
||||
/// Used to lock a tempo-syncable pedal parameter (a delay time, an LFO rate) to the shared
|
||||
/// ``ShoeGaze/clock``. The synced period in seconds is `(60 / bpm) * beats`; a delay time uses
|
||||
/// that period directly, an LFO rate uses its inverse (one cycle per division).
|
||||
///
|
||||
/// Cases are ordered longest-first so a stepped selector reads top-to-bottom from slow to fast.
|
||||
public enum NoteDivision: String, Codable, CaseIterable, Sendable {
|
||||
|
||||
/// Whole note — four quarter-note beats.
|
||||
case whole
|
||||
/// Dotted half note — three beats.
|
||||
case dottedHalf
|
||||
/// Half note — two beats.
|
||||
case half
|
||||
/// Dotted quarter note — one and a half beats.
|
||||
case dottedQuarter
|
||||
/// Quarter note — one beat.
|
||||
case quarter
|
||||
/// Dotted eighth note — three-quarters of a beat.
|
||||
case dottedEighth
|
||||
/// Quarter-note triplet — two-thirds of a beat.
|
||||
case quarterTriplet
|
||||
/// Eighth note — half a beat.
|
||||
case eighth
|
||||
/// Eighth-note triplet — one-third of a beat.
|
||||
case eighthTriplet
|
||||
/// Sixteenth note — a quarter of a beat.
|
||||
case sixteenth
|
||||
/// Sixteenth-note triplet — one-sixth of a beat.
|
||||
case sixteenthTriplet
|
||||
|
||||
/// Length of this division in quarter-note beats (a quarter note is `1`).
|
||||
public var beats: Double {
|
||||
switch self {
|
||||
case .whole: return 4.0
|
||||
case .dottedHalf: return 3.0
|
||||
case .half: return 2.0
|
||||
case .dottedQuarter: return 1.5
|
||||
case .quarter: return 1.0
|
||||
case .quarterTriplet: return 2.0 / 3.0
|
||||
case .dottedEighth: return 0.75
|
||||
case .eighth: return 0.5
|
||||
case .eighthTriplet: return 1.0 / 3.0
|
||||
case .sixteenth: return 0.25
|
||||
case .sixteenthTriplet: return 1.0 / 6.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Short label for a selector stop (e.g. `"1/4"`, `"1/8."`, `"1/8T"`).
|
||||
public var label: String {
|
||||
switch self {
|
||||
case .whole: return "1/1"
|
||||
case .dottedHalf: return "1/2."
|
||||
case .half: return "1/2"
|
||||
case .dottedQuarter: return "1/4."
|
||||
case .quarter: return "1/4"
|
||||
case .quarterTriplet: return "1/4T"
|
||||
case .dottedEighth: return "1/8."
|
||||
case .eighth: return "1/8"
|
||||
case .eighthTriplet: return "1/8T"
|
||||
case .sixteenth: return "1/16"
|
||||
case .sixteenthTriplet: return "1/16T"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,6 @@ extension ShoeGaze {
|
||||
|
||||
let averageInterval: TimeInterval = intervals.reduce(0, +) / Double(intervals.count)
|
||||
let secondsPerMinute: Double = 60.0
|
||||
clock.bpm = secondsPerMinute / averageInterval
|
||||
setBpm(secondsPerMinute / averageInterval)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// TempoSync.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Sync state of one tempo-syncable pedal parameter.
|
||||
///
|
||||
/// `.free` leaves the parameter at its stored absolute value (seconds or Hz), controlled by the
|
||||
/// knob as usual. `.division` locks it to a ``NoteDivision`` of the shared ``ShoeGaze/clock`` —
|
||||
/// the value is derived from the current tempo and rewritten whenever the tempo or the division
|
||||
/// changes.
|
||||
public enum TempoSync: Codable, Equatable, Sendable {
|
||||
|
||||
/// Absolute value, knob-controlled. The default for every parameter.
|
||||
case free
|
||||
|
||||
/// Locked to a note division of the live tempo.
|
||||
case division(NoteDivision)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// TempoSyncRevision.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Observation
|
||||
|
||||
/// An observable revision counter bumped whenever a pedal's ``Pedal/tempoSync`` state changes.
|
||||
///
|
||||
/// ``Pedal/tempoSync`` is a plain dictionary, not observable, so a SwiftUI view showing the sync
|
||||
/// state (the note-division badge) needs a signal to re-render when the state changes through any
|
||||
/// path — the knob's own picker, a preset load, or a lightweight recall. Reading ``value`` inside a
|
||||
/// view body subscribes it; ``Pedal/setSync(_:for:)`` and `Pedal.applyState(_:)` bump it.
|
||||
@Observable
|
||||
public final class TempoSyncRevision {
|
||||
|
||||
/// Incremented on every ``Pedal/tempoSync`` mutation. Its magnitude is meaningless — only the
|
||||
/// change matters, as an invalidation signal for observing views.
|
||||
public internal(set) var value: Int = 0
|
||||
|
||||
/// Creates a revision counter starting at zero.
|
||||
public init() {}
|
||||
|
||||
/// Bumps the counter, invalidating any view observing ``value``.
|
||||
func bump() {
|
||||
value &+= 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// TempoSyncableParam.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdUI
|
||||
|
||||
/// Descriptor for one pedal parameter that can be locked to the tempo.
|
||||
///
|
||||
/// A ``Pedal`` publishes an array of these (via ``Pedal/tempoSyncableParams``) so the shared
|
||||
/// tempo-sync machinery can recompute and rewrite each synced parameter without knowing the
|
||||
/// concrete pedal type. The stable ``key`` doubles as the persistence key in ``PedalState``.
|
||||
public struct TempoSyncableParam {
|
||||
|
||||
/// How the synced period maps onto the parameter's value.
|
||||
public enum Kind {
|
||||
/// A duration in seconds — the value is the synced period `T` directly (delay time).
|
||||
case time
|
||||
/// A frequency in Hz — the value is `1 / T` (one LFO cycle per division).
|
||||
case rate
|
||||
}
|
||||
|
||||
/// Stable identifier for this parameter within its pedal (e.g. `"time"`, `"time1"`, `"rate"`).
|
||||
/// Used as the ``TempoSync`` dictionary key and the persistence key, so it must never change.
|
||||
public let key: String
|
||||
|
||||
/// Short display label, matching the parameter's knob label.
|
||||
public let label: String
|
||||
|
||||
/// The live parameter node the synced value is written to.
|
||||
public let node: UIParamNode
|
||||
|
||||
/// Whether the value is a duration (`.time`) or a frequency (`.rate`, inverse of the period).
|
||||
public let kind: Kind
|
||||
|
||||
/// Inclusive value range the parameter accepts, in its own units. A synced value outside this
|
||||
/// range is clamped (a long division can exceed a delay's maximum buffered time).
|
||||
public let range: ClosedRange<Double>
|
||||
|
||||
/// Creates a tempo-syncable parameter descriptor.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - key: Stable identifier and persistence key. Must be unique within the pedal and stable
|
||||
/// across versions.
|
||||
/// - label: Short display label, matching the knob label.
|
||||
/// - node: The live parameter node (`pedal.$time`, `pedal.$rate`, …).
|
||||
/// - kind: `.time` for a duration, `.rate` for a frequency (inverse of the period).
|
||||
/// - range: Inclusive value range in the parameter's units; the synced value is clamped to it.
|
||||
public init(
|
||||
key: String,
|
||||
label: String,
|
||||
node: UIParamNode,
|
||||
kind: Kind,
|
||||
range: ClosedRange<Double>
|
||||
) {
|
||||
self.key = key
|
||||
self.label = label
|
||||
self.node = node
|
||||
self.kind = kind
|
||||
self.range = range
|
||||
}
|
||||
|
||||
private static let secondsPerMinute: Double = 60.0
|
||||
|
||||
/// The unclamped parameter value for `division` at `bpm`. For `.time` this is the note's period
|
||||
/// in seconds; for `.rate` it is `1 / period` in Hz (one LFO cycle per division).
|
||||
public func rawValue(for division: NoteDivision, bpm: Double) -> Double {
|
||||
let period: Double = (TempoSyncableParam.secondsPerMinute / bpm) * division.beats
|
||||
switch kind {
|
||||
case .time:
|
||||
return period
|
||||
case .rate:
|
||||
return period > 0 ? 1.0 / period : range.upperBound
|
||||
}
|
||||
}
|
||||
|
||||
/// The value actually written for `division` at `bpm`, plus whether it had to be clamped to the
|
||||
/// parameter's range. A clamped result means the division can't be represented accurately at this
|
||||
/// tempo (e.g. a whole note longer than the maximum delay time) — the UI disables/flags it.
|
||||
public func value(for division: NoteDivision, bpm: Double) -> (value: Double, clamped: Bool) {
|
||||
let raw: Double = rawValue(for: division, bpm: bpm)
|
||||
let clampedValue: Double = min(max(raw, range.lowerBound), range.upperBound)
|
||||
return (clampedValue, clampedValue != raw)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user