v2.4.0 release: event patterns + live event conductor
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// EventQuantumTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable import LyrebirdSynth
|
||||
|
||||
/// `EventQuantum.targetBeat(from:)` — pure resolution of each quantum against a current beat.
|
||||
@Suite("EventQuantum")
|
||||
struct EventQuantumTests {
|
||||
|
||||
@Test func nowResolvesToNow() {
|
||||
#expect(EventQuantum.now.targetBeat(from: 3.4) == 3.4)
|
||||
}
|
||||
|
||||
@Test func nextBeatIsStrictlyAfterNow() {
|
||||
#expect(EventQuantum.nextBeat.targetBeat(from: 3.4) == 4.0)
|
||||
// On an exact beat, the next boundary is the following whole beat, not the current one.
|
||||
#expect(EventQuantum.nextBeat.targetBeat(from: 3.0) == 4.0)
|
||||
}
|
||||
|
||||
@Test func nextMultipleSnapsToTheNextGridLine() {
|
||||
#expect(EventQuantum.nextMultiple(ofBeats: 4.0).targetBeat(from: 5.2) == 8.0)
|
||||
// On an exact bar line, the next bar is the following one.
|
||||
#expect(EventQuantum.nextMultiple(ofBeats: 4.0).targetBeat(from: 4.0) == 8.0)
|
||||
#expect(EventQuantum.nextMultiple(ofBeats: 2.0).targetBeat(from: 0.5) == 2.0)
|
||||
}
|
||||
|
||||
@Test func atBeatIsAbsolute() {
|
||||
#expect(EventQuantum.atBeat(10.0).targetBeat(from: 2.0) == 10.0)
|
||||
}
|
||||
|
||||
@Test func atBeatInThePastResolvesToThatPastBeat() {
|
||||
// A beat already gone by resolves to itself (below now); the conductor treats it as already due.
|
||||
#expect(EventQuantum.atBeat(1.0).targetBeat(from: 5.0) == 1.0)
|
||||
}
|
||||
|
||||
@Test func nextBeatHandlesNearBoundaryFloat() {
|
||||
// Just shy of beat 3 rounds down to 2, so the next whole beat is 3.
|
||||
#expect(EventQuantum.nextBeat.targetBeat(from: 2.9999999999) == 3.0)
|
||||
}
|
||||
|
||||
@Test func afterBeatsIsRelativeAndClampsNegative() {
|
||||
#expect(EventQuantum.afterBeats(2.5).targetBeat(from: 2.0) == 4.5)
|
||||
#expect(EventQuantum.afterBeats(-1.0).targetBeat(from: 2.0) == 2.0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user