Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/PedalMappingStripTests.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

88 lines
3.5 KiB
Swift

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