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,52 @@
|
||||
// NoteDivisionTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@Suite("NoteDivision")
|
||||
struct NoteDivisionTests {
|
||||
|
||||
private let tolerance: Double = 1e-9
|
||||
|
||||
@Test func beatsMatchMusicalValues() {
|
||||
#expect(NoteDivision.whole.beats == 4.0)
|
||||
#expect(NoteDivision.dottedHalf.beats == 3.0)
|
||||
#expect(NoteDivision.half.beats == 2.0)
|
||||
#expect(NoteDivision.dottedQuarter.beats == 1.5)
|
||||
#expect(NoteDivision.quarter.beats == 1.0)
|
||||
#expect(abs(NoteDivision.quarterTriplet.beats - 2.0 / 3.0) < tolerance)
|
||||
#expect(NoteDivision.dottedEighth.beats == 0.75)
|
||||
#expect(NoteDivision.eighth.beats == 0.5)
|
||||
#expect(abs(NoteDivision.eighthTriplet.beats - 1.0 / 3.0) < tolerance)
|
||||
#expect(NoteDivision.sixteenth.beats == 0.25)
|
||||
#expect(abs(NoteDivision.sixteenthTriplet.beats - 1.0 / 6.0) < tolerance)
|
||||
}
|
||||
|
||||
@Test func dottedIsHalfAgainThePlainValue() {
|
||||
#expect(NoteDivision.dottedQuarter.beats == NoteDivision.quarter.beats * 1.5)
|
||||
#expect(NoteDivision.dottedEighth.beats == NoteDivision.eighth.beats * 1.5)
|
||||
}
|
||||
|
||||
@Test func casesAreOrderedSlowToFast() {
|
||||
let beats: [Double] = NoteDivision.allCases.map { $0.beats }
|
||||
#expect(beats == beats.sorted(by: >), "cases must be ordered longest (slowest) first")
|
||||
}
|
||||
|
||||
@Test func labelsAreUnique() {
|
||||
let labels: [String] = NoteDivision.allCases.map { $0.label }
|
||||
#expect(Set(labels).count == labels.count)
|
||||
}
|
||||
|
||||
@Test func codableRoundTrips() throws {
|
||||
for division: NoteDivision in NoteDivision.allCases {
|
||||
let data: Data = try JSONEncoder().encode(division)
|
||||
let decoded: NoteDivision = try JSONDecoder().decode(NoteDivision.self, from: data)
|
||||
#expect(decoded == division)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// PedalMappingStripTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
@testable import LyrebirdShoeGazeUI
|
||||
|
||||
@MainActor
|
||||
@Suite("Pedal mapping strip")
|
||||
struct PedalMappingStripTests {
|
||||
|
||||
/// Builds an engine + a one-board rig with a single Volume pedal, returning the pedal.
|
||||
private func makePedal() throws -> (Pedal, ShoeGaze, URL) {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
guard let pedal: Pedal = board.pedals.first else {
|
||||
throw ShoeGazeTestError.noPedal
|
||||
}
|
||||
return (pedal, sg, url)
|
||||
}
|
||||
|
||||
private enum ShoeGazeTestError: Error { case noPedal }
|
||||
|
||||
@Test func emptyMapYieldsNoRows() throws {
|
||||
let (pedal, sg, url): (Pedal, ShoeGaze, URL) = try makePedal()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
withExtendedLifetime(sg) {
|
||||
#expect(PedalMappingStrip.rows(for: pedal, in: nil).isEmpty)
|
||||
#expect(PedalMappingStrip.rows(for: pedal, in: .empty).isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func ccAndBypassRowsBuiltFromMap() throws {
|
||||
let (pedal, sg, url): (Pedal, ShoeGaze, URL) = try makePedal()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
withExtendedLifetime(sg) {
|
||||
#expect(pedal.ccMappableControls.isEmpty == false, "Volume exposes a CC-mappable control")
|
||||
let controlLabel: String = pedal.ccMappableControls[0].label
|
||||
|
||||
let map: MIDIMap = MIDIMap(
|
||||
switches: [MIDIMap.SwitchBinding(program: 4, action: .pedalBypass(pedalID: pedal.id))],
|
||||
ccs: [MIDIMap.CCBinding(
|
||||
controller: 11,
|
||||
target: .pedalControl(
|
||||
pedalID: pedal.id, controlIndex: 0,
|
||||
pedalNameHint: nil, controlLabelHint: nil))],
|
||||
keys: [MIDIMap.KeyBinding(key: "b", modifiers: [.shift],
|
||||
action: .pedalBypass(pedalID: pedal.id))]
|
||||
)
|
||||
|
||||
let rows: [PedalMappingRow] = PedalMappingStrip.rows(for: pedal, in: map)
|
||||
#expect(rows.count == 2, "one CC control row + one bypass row")
|
||||
|
||||
let ccRow: PedalMappingRow? = rows.first { $0.label == controlLabel }
|
||||
#expect(ccRow?.badges.map(\.text) == ["CC11"])
|
||||
|
||||
let bypassRow: PedalMappingRow? = rows.first { $0.label == "Bypass" }
|
||||
#expect(bypassRow?.badges.map(\.text) == ["PC4", "⇧B"], "footswitch then key, shift glyph")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func unmappedControlsProduceNoRows() throws {
|
||||
let (pedal, sg, url): (Pedal, ShoeGaze, URL) = try makePedal()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
withExtendedLifetime(sg) {
|
||||
// A map that only binds a DIFFERENT pedal's control must not surface rows for this pedal.
|
||||
let otherID: UUID = UUID()
|
||||
let map: MIDIMap = MIDIMap(
|
||||
ccs: [MIDIMap.CCBinding(
|
||||
controller: 5,
|
||||
target: .pedalControl(
|
||||
pedalID: otherID, controlIndex: 0,
|
||||
pedalNameHint: nil, controlLabelHint: nil))]
|
||||
)
|
||||
#expect(PedalMappingStrip.rows(for: pedal, in: map).isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// TempoSyncTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("Tempo sync")
|
||||
struct TempoSyncTests {
|
||||
|
||||
/// A rig with a single `DelayPedal` on a finalized board, so the pedal has a real clock and
|
||||
/// engine injected by `board.add(_:)`. Returns the session (kept alive for its clock), the
|
||||
/// temp render URL, and the pedal.
|
||||
private func makeRigWithDelay(bpm: Double = 120.0) throws -> (ShoeGaze, URL, DelayPedal) {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1)
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
sg.clock.bpm = bpm
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
let delay: DelayPedal = DelayPedal()
|
||||
try board.add(delay)
|
||||
try sg.finalizeBoard(board)
|
||||
return (sg, url, delay)
|
||||
}
|
||||
|
||||
private let tolerance: Double = 1e-6
|
||||
|
||||
@Test func timeDivisionDerivesSecondsFromTempo() throws {
|
||||
// `sg` owns the clock (the pedal holds it weakly), so it must outlive the assertions.
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay(bpm: 120.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
// 120 BPM → 0.5 s per beat. Eighth = 0.5 beat → 0.25 s.
|
||||
delay.setSync(.division(.eighth), for: "time")
|
||||
#expect(abs(delay.$time.value - 0.25) < tolerance)
|
||||
|
||||
// Quarter = 1 beat → 0.5 s.
|
||||
delay.setSync(.division(.quarter), for: "time")
|
||||
#expect(abs(delay.$time.value - 0.5) < tolerance)
|
||||
}
|
||||
|
||||
@Test func freeParameterIsLeftUntouched() throws {
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
let original: Double = delay.$time.value
|
||||
delay.applyTempoSync() // nothing is synced → value unchanged
|
||||
#expect(delay.$time.value == original)
|
||||
}
|
||||
|
||||
@Test func longDivisionClampsToParameterRange() throws {
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay(bpm: 40.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
// Whole note at 40 BPM = 4 beats × 1.5 s = 6.0 s, past the Delay's 5.0 s maximum.
|
||||
delay.setSync(.division(.whole), for: "time")
|
||||
#expect(abs(delay.$time.value - 5.0) < tolerance, "synced value must clamp to the time range")
|
||||
}
|
||||
|
||||
@Test func valueReportsWhenADivisionClamps() throws {
|
||||
let delay: DelayPedal = DelayPedal()
|
||||
let param: TempoSyncableParam = try #require(delay.tempoSyncableParams.first)
|
||||
|
||||
// Fits within [0.01, 5.0]: quarter @ 120 BPM = 0.5 s, not clamped.
|
||||
let quarter: (value: Double, clamped: Bool) = param.value(for: .quarter, bpm: 120.0)
|
||||
#expect(abs(quarter.value - 0.5) < tolerance)
|
||||
#expect(!quarter.clamped)
|
||||
|
||||
// Whole @ 40 BPM = 6.0 s, past the 5.0 s max → clamped and flagged.
|
||||
let whole: (value: Double, clamped: Bool) = param.value(for: .whole, bpm: 40.0)
|
||||
#expect(abs(whole.value - 5.0) < tolerance)
|
||||
#expect(whole.clamped)
|
||||
}
|
||||
|
||||
@Test func setBpmBroadcastsToSyncedParameters() throws {
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay(bpm: 120.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
delay.setSync(.division(.quarter), for: "time")
|
||||
#expect(abs(delay.$time.value - 0.5) < tolerance) // quarter @ 120 BPM
|
||||
|
||||
// Halving the tempo doubles a beat's length → quarter now 1.0 s.
|
||||
sg.setBpm(60.0)
|
||||
#expect(abs(delay.$time.value - 1.0) < tolerance, "setBpm must recompute synced parameters")
|
||||
}
|
||||
|
||||
@Test func rateParameterUsesInverseOfPeriod() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
sg.clock.bpm = 120.0
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
let tremolo: TremoloPedal = TremoloPedal()
|
||||
try board.add(tremolo)
|
||||
try sg.finalizeBoard(board)
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
// 120 BPM → 0.5 s per beat. A quarter-note LFO = one cycle per 0.5 s → 2 Hz.
|
||||
tremolo.setSync(.division(.quarter), for: "rate")
|
||||
#expect(abs(tremolo.$rate.value - 2.0) < tolerance)
|
||||
|
||||
// Eighth = 0.25 s period → 4 Hz.
|
||||
tremolo.setSync(.division(.eighth), for: "rate")
|
||||
#expect(abs(tremolo.$rate.value - 4.0) < tolerance)
|
||||
}
|
||||
|
||||
@Test func multiTapSyncsEachTapIndependently() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
sg.clock.bpm = 120.0
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
let multiTap: MultiTapDelayPedal = MultiTapDelayPedal()
|
||||
try board.add(multiTap)
|
||||
try sg.finalizeBoard(board)
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
let freeTime3: Double = multiTap.$time3.value
|
||||
multiTap.setSync(.division(.quarter), for: "time1") // 0.5 s
|
||||
multiTap.setSync(.division(.eighth), for: "time2") // 0.25 s
|
||||
|
||||
#expect(abs(multiTap.$time1.value - 0.5) < tolerance)
|
||||
#expect(abs(multiTap.$time2.value - 0.25) < tolerance)
|
||||
#expect(multiTap.$time3.value == freeTime3, "an unsynced tap is left free")
|
||||
}
|
||||
|
||||
@Test func lightweightRecallRecomputesSyncedValuesAtCurrentTempo() throws {
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay(bpm: 120.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
defer { withExtendedLifetime(sg) {} }
|
||||
|
||||
delay.setSync(.division(.quarter), for: "time")
|
||||
#expect(abs(delay.$time.value - 0.5) < tolerance) // quarter @ 120 BPM
|
||||
|
||||
// Capture at 120 BPM (time = 0.5 s), then change tempo so a recall must recompute.
|
||||
let snapshot: ShoeGazeState = sg.captureState()
|
||||
sg.setBpm(60.0)
|
||||
#expect(abs(delay.$time.value - 1.0) < tolerance) // quarter @ 60 BPM
|
||||
|
||||
// Recall the 120-BPM snapshot onto the (now 60-BPM) rig. The restored division must be
|
||||
// recomputed against the current tempo — 1.0 s — not left at the captured 0.5 s.
|
||||
sg.applyState(snapshot)
|
||||
#expect(delay.tempoSync["time"] == .division(.quarter))
|
||||
#expect(abs(delay.$time.value - 1.0) < tolerance, "recall must recompute synced values at the current tempo")
|
||||
}
|
||||
|
||||
@Test func syncStatePersistsThroughCaptureAndApply() throws {
|
||||
let delay: DelayPedal = DelayPedal()
|
||||
delay.setSync(.division(.dottedEighth), for: "time")
|
||||
|
||||
let data: Data = try JSONEncoder().encode(delay.captureState())
|
||||
let restored: PedalState = try JSONDecoder().decode(PedalState.self, from: data)
|
||||
|
||||
let rebuilt: DelayPedal = DelayPedal()
|
||||
rebuilt.applyState(restored)
|
||||
#expect(rebuilt.tempoSync["time"] == .division(.dottedEighth))
|
||||
}
|
||||
|
||||
@Test func presetWithoutTempoSyncDecodesToFree() throws {
|
||||
// A rig saved before tempo sync has no `tempoSync` key — it must decode to "all free".
|
||||
let legacy: String = """
|
||||
{"type":"Delay","knobValues":[0.25,1.0,0.35,1.0],"bypass":0.0}
|
||||
"""
|
||||
let state: PedalState = try JSONDecoder().decode(PedalState.self, from: Data(legacy.utf8))
|
||||
#expect(state.tempoSync == nil)
|
||||
|
||||
let delay: DelayPedal = DelayPedal()
|
||||
delay.applyState(state)
|
||||
#expect(delay.tempoSync.isEmpty, "a legacy preset leaves every parameter free")
|
||||
}
|
||||
|
||||
@Test func disablingTempoStopsRecompute() throws {
|
||||
let (sg, url, delay): (ShoeGaze, URL, DelayPedal) = try makeRigWithDelay(bpm: 120.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
delay.setSync(.division(.quarter), for: "time")
|
||||
let syncedValue: Double = delay.$time.value // 0.5 s
|
||||
|
||||
sg.setTempoEnabled(false)
|
||||
sg.setBpm(60.0) // tempo disabled → no recompute
|
||||
#expect(delay.$time.value == syncedValue, "a disabled tempo must not drive synced parameters")
|
||||
|
||||
// Re-enabling re-syncs to the current (60 BPM) tempo → quarter = 1.0 s.
|
||||
sg.setTempoEnabled(true)
|
||||
#expect(abs(delay.$time.value - 1.0) < tolerance)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user