Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/NoteDivisionTests.swift
T
josh 2772abdc56 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>
2026-07-10 08:47:22 -07:00

53 lines
1.9 KiB
Swift

// 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)
}
}
}