v1.4.0 release: live-coding scratch editor, interpreted Graph DSL, ClosureSynthesizer + SampleLoop

This commit is contained in:
2026-07-20 10:02:49 -07:00
parent 560724d116
commit 38d2107f64
104 changed files with 14471 additions and 105 deletions
@@ -46,8 +46,8 @@ private func sustainedEnvelope() -> Envelope {
/// Drives `engine.processBlock` in bursts so engine-time advances faster than wall-time.
private final class TestBlockDriver: @unchecked Sendable {
private var _thread: Thread?
private let _running: Atomic<Bool> = Atomic<Bool>(false)
private let _done: DispatchSemaphore = DispatchSemaphore(value: 0)
private let _engine: SynthesisEngine
// 32 × 64 samples @ 44.1 kHz ≈ 46 ms audio per 1 ms wall sleep → ~46× realtime.
// Headroom absorbs scheduler jitter so wall-clock test timeouts don't expire
@@ -66,13 +66,20 @@ private final class TestBlockDriver: @unchecked Sendable {
}
Thread.sleep(forTimeInterval: Self.wallSleepSeconds)
}
self._done.signal()
}
thread.qualityOfService = .userInteractive
thread.start()
_thread = thread
}
func stop() { _running.store(false, ordering: .relaxed) }
/// Stop and **join** the pump thread: blocks until the loop has finished its
/// in-flight block and exited, so no `processBlock` can run after `stop()`
/// returns to race the engine's own `stop()`. Idempotent and safe if never
/// started (the `true → false` transition is the one that joins).
func stop() {
guard _running.exchange(false, ordering: .relaxed) else { return }
_done.wait()
}
}
/// Thread-safe one-shot fulfillment token.
@@ -76,8 +76,8 @@ private func makeSimpleEventList(
/// Drives `engine.processBlock` in bursts so engine-time advances faster than wall-time.
private final class TestBlockDriver: @unchecked Sendable {
private var _thread: Thread?
private let _running: Atomic<Bool> = Atomic<Bool>(false)
private let _done: DispatchSemaphore = DispatchSemaphore(value: 0)
private let _engine: SynthesisEngine
// 32 × 64 samples @ 44.1 kHz ≈ 46 ms audio per 1 ms wall sleep → ~46× realtime.
// Headroom absorbs scheduler jitter so wall-clock test timeouts don't expire
@@ -96,13 +96,20 @@ private final class TestBlockDriver: @unchecked Sendable {
}
Thread.sleep(forTimeInterval: Self.wallSleepSeconds)
}
self._done.signal()
}
thread.qualityOfService = .userInteractive
thread.start()
_thread = thread
}
func stop() { _running.store(false, ordering: .relaxed) }
/// Stop and **join** the pump thread: blocks until the loop has finished its
/// in-flight block and exited, so no `processBlock` can run after `stop()`
/// returns to race the engine's own `stop()`. Idempotent and safe if never
/// started (the `true → false` transition is the one that joins).
func stop() {
guard _running.exchange(false, ordering: .relaxed) else { return }
_done.wait()
}
}
// MARK: - Helpers
@@ -7,6 +7,7 @@
import Testing
import Foundation
import AudioToolbox
import Synchronization
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
// MARK: - Private test fixtures
@@ -35,25 +36,34 @@ private func shortAutoEnvelope() -> Envelope {
/// Drives `engine.processBlock` at ~1 ms intervals while `_running` is true.
private final class TimelineTestBlockDriver: @unchecked Sendable {
private var _running: Bool = false
private let _running: Atomic<Bool> = Atomic<Bool>(false)
private let _done: DispatchSemaphore = DispatchSemaphore(value: 0)
private let _engine: SynthesisEngine
private static let blockIntervalSeconds: Double = 0.001
init(engine: SynthesisEngine) { _engine = engine }
func start() {
_running = true
_running.store(true, ordering: .relaxed)
let t: Thread = Thread { [self] in
while self._running {
while self._running.load(ordering: .relaxed) {
self._engine.processBlock(inputSamples: [])
Thread.sleep(forTimeInterval: TimelineTestBlockDriver.blockIntervalSeconds)
}
self._done.signal()
}
t.qualityOfService = .userInteractive
t.start()
}
func stop() { _running = false }
/// Stop and **join** the pump thread: blocks until the loop has finished its
/// in-flight block and exited, so no `processBlock` can run after `stop()`
/// returns to race the engine's own `stop()`. Idempotent and safe if never
/// started (the `true → false` transition is the one that joins).
func stop() {
guard _running.exchange(false, ordering: .relaxed) else { return }
_done.wait()
}
}
/// Returns a temporary directory. Caller is responsible for cleanup.
@@ -64,8 +64,8 @@ private func makeProcessTestEngine() -> SynthesisEngine {
/// The `OfflineDriver` does not generate its own render callbacks, so tests that
/// rely on envelope completion must drive the engine themselves.
private final class TestBlockDriver: @unchecked Sendable {
private var _thread: Thread?
private let _running: Atomic<Bool> = Atomic<Bool>(false)
private let _done: DispatchSemaphore = DispatchSemaphore(value: 0)
private let _engine: SynthesisEngine
// 32 × 64 samples @ 44.1 kHz ≈ 46 ms audio per 1 ms wall sleep → ~46× realtime.
// Headroom absorbs scheduler jitter so wall-clock test timeouts don't expire
@@ -86,14 +86,19 @@ private final class TestBlockDriver: @unchecked Sendable {
}
Thread.sleep(forTimeInterval: Self.wallSleepSeconds)
}
self._done.signal()
}
thread.qualityOfService = .userInteractive
thread.start()
_thread = thread
}
/// Stop and **join** the pump thread: blocks until the loop has finished its
/// in-flight block and exited, so no `processBlock` can run after `stop()`
/// returns to race the engine's own `stop()`. Idempotent and safe if never
/// started (the `true → false` transition is the one that joins).
func stop() {
_running.store(false, ordering: .relaxed)
guard _running.exchange(false, ordering: .relaxed) else { return }
_done.wait()
}
}