diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index c9071d5..27147b1 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -256,6 +256,20 @@ And `engine.remove(synth)`: `remove` returns `Bool` (it unbinds synchronously on successful enqueue), but there is a documented one-`processBlock` window between `remove` and a re-`add` of the same instance — the RT thread needs a block to actually unlink it. If `freeQueue` overflows, the framework logs one warning and leaks that single reference rather than risk the RT thread; a leaked voice is preferable to an audio dropout or crash. +### 9.1 Actor isolation of the lifecycle (Phase 201) + +The Swift-concurrency isolation of `Synthesizer` is split along exactly the thread boundary above: + +- **Language side is `@MainActor`.** `SynthesizerBase` is a `@MainActor` class, and the `Synthesizer` protocol declares `build()`, `release(engine:)`, `free(engine:)` as `@MainActor` requirements. Steps 1–4 of the add path (allocate → build → enqueue) and the `engine.add` / `schedule` / `add(position:)` entry points are therefore main-actor-isolated. This is what lets a consumer building under Xcode 26's `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` default subclass `SynthesizerBase` and override `build()` with **no** concurrency annotations — the consumer's MainActor default now matches the base instead of conflicting with a nonisolated override. (`engine.remove` stays nonisolated — it unbinds via atomics and enqueues a pointer-only event; `_bind` / `_unbind` are nonisolated for the same reason.) + +- **The RT entry point is `nonisolated`.** `evaluate(graph:count:)` is `nonisolated final` so the render callback (steps 5–6) reaches it with **no actor hop**. It reads exactly two stored properties cross-thread — `parameterTable` (immutable `let`) and `outputGenerators` (written in `build()` on main, read on RT) — both marked `nonisolated(unsafe)`. Their safety rests entirely on the happens-before edge established by the SPSC `pendingQueue` (§2.1): the RT thread cannot observe the node until it dequeues the `.add` event, which the producer enqueued *after* `build()` fully returned on main. No new runtime synchronisation is introduced by the isolation annotations. + +- **`Group` / `ParallelGroup` stay nonisolated.** They satisfy the `@MainActor` `build`/`release`/`free` requirements with less-isolated (nonisolated) witnesses, keeping their RT-owned linked-list / snapshot state reachable from the render thread. `Group.release` installs its self-free poll timer through a `nonisolated` helper so the utility-queue handler does not inherit `@MainActor` (which would trap when it fires off-main). + +- **Internal controllers that drive the node tree are `@MainActor`** where they touch the language side: `LyrebirdProcess` (`play`/`_play`/`release`/`amp`/teardown), `LyrebirdEventList` (`play(eventIndex:)`/`next`/`releaseAll`/`killAll`/`reset`/master teardown), `VoicePool.init`, `ParallelGroup.add`. Cross-thread reads that pre-existed the change (e.g. the auto-free watcher reading `EnvelopeGen.needsFree`, `EventList.fireTimes` from process body tasks) are preserved via `nonisolated(unsafe)` on the specific fields they touch. + +The guarantee is locked by the committed `RegressionFixtures/MainActorConsumer` package, which compiles an unannotated `SynthesizerBase` subclass under `.swiftLanguageMode(.v6)` + `-default-isolation MainActor`. + --- ## Where to go deeper diff --git a/LiveCompile/Package.swift b/LiveCompile/Package.swift index 75591c0..d16edd5 100644 --- a/LiveCompile/Package.swift +++ b/LiveCompile/Package.swift @@ -47,8 +47,8 @@ let package = Package( "LyrebirdLiveCompile", .product(name: "LyrebirdDynamic", package: "Lyrebird"), ], - path: "Sources/LyrebirdLiveCompileUI", - swiftSettings: [.swiftLanguageMode(.v5)] + path: "Sources/LyrebirdLiveCompileUI" + // Swift 6 language mode (Phase 203): inherits the swift-tools 6.0 default. ), .testTarget( name: "LyrebirdLiveCompileTests", @@ -65,8 +65,7 @@ let package = Package( "LyrebirdLiveCompileUI", .product(name: "LyrebirdDynamic", package: "Lyrebird"), ], - path: "Tests/LyrebirdLiveCompileUITests", - swiftSettings: [.swiftLanguageMode(.v5)] + path: "Tests/LyrebirdLiveCompileUITests" ), ] ) diff --git a/LiveCompile/Sources/LyrebirdLiveCompile/LiveSession.swift b/LiveCompile/Sources/LyrebirdLiveCompile/LiveSession.swift index fbbfd6e..ce360df 100644 --- a/LiveCompile/Sources/LyrebirdLiveCompile/LiveSession.swift +++ b/LiveCompile/Sources/LyrebirdLiveCompile/LiveSession.swift @@ -22,7 +22,20 @@ import LyrebirdSynth /// compile snippets, and the tracking lists needed for re-evaluation cleanup. /// Snippets receive a `SnippetContext` bound to this session through /// `compileAndRun(_:additive:)`. -public final class LiveSession { +/// +/// `@unchecked Sendable` (Phase 203): a `LiveSession` is shared between its `@MainActor` +/// owner (`LyrebirdScratchModel`) and the `nonisolated` `compileAndRunAsync` it calls, so +/// Swift 6 requires it to be `Sendable`. The conformance is sound by construction: +/// +/// - `engine` and all `-I` / `-L` / `-l` / `rpath` configuration are immutable `let`. +/// - The only mutable graph state — `trackedSynths` and `loadedSnippets` — is accessed +/// exclusively under `trackingLock` (`track`, `clearTracked`, `trackedSynthCount`, +/// `runEntry`). +/// - `reportedSampleRate` / `lastSnippetMessage` are test-only side channels (`@testable`), +/// written by the single in-flight snippet entry under the documented +/// one-invocation-at-a-time precondition (see `compileAndRunAsync`) and read by tests +/// after it completes — no concurrent access in practice. +public final class LiveSession: @unchecked Sendable { public let engine: SynthesisEngine @@ -78,7 +91,12 @@ public final class LiveSession { /// (⌘⇧↩ semantics in the future `LyrebirdScratchView` editor). /// - Returns: The compiled snippet handle. Retained internally so the dylib /// stays mapped; callers can ignore it. + /// `@MainActor` (Phase 203): runs the snippet entry — and thus the user body's + /// `MainActor.assumeIsolated { … }` and any `context.play(_:)` → `engine.add` — on the + /// main thread, synchronously (swiftc compile included). The async variant + /// ``compileAndRunAsync(_:additive:)`` keeps the compile off-main. @discardableResult + @MainActor public func compileAndRun(_ userBody: String, additive: Bool = false) throws -> CompiledSnippet { if !additive { clearTracked() @@ -89,11 +107,16 @@ public final class LiveSession { return snippet } - /// Asynchronous variant of ``compileAndRun(_:additive:)``. The swiftc - /// compile runs on a background `Task.detached`; the snippet entry then - /// executes on the caller's actor (typically the main actor, so snippets - /// can touch UI-side state). Lets `LyrebirdScratchView`'s editor stay - /// responsive during the compile. + /// Asynchronous variant of ``compileAndRun(_:additive:)``. The swiftc compile runs on a + /// background `Task.detached` so `LyrebirdScratchView`'s editor stays responsive; the + /// engine-touching steps (`clearTracked()` and the snippet entry via `runEntry`) then run + /// on the **main actor**. + /// + /// Running the entry on the main actor matters (Phase 203): the snippet's + /// `context.play(_:)` calls `engine.add(_:)`, which is `@MainActor` (Phase 201) and + /// mutates `engine.nodeTreeMirror` — state observed by SwiftUI on the main thread. A + /// `nonisolated async` method resumes on the generic executor, NOT the caller's actor, so + /// the hop is explicit here rather than assumed. /// /// - Precondition: only one in-flight invocation at a time per `LiveSession`. /// Concurrent calls can interleave `clearTracked()` with the prior call's @@ -108,14 +131,16 @@ public final class LiveSession { @discardableResult public func compileAndRunAsync(_ userBody: String, additive: Bool = false) async throws -> CompiledSnippet { if !additive { - clearTracked() + // `clearTracked()` calls `engine.remove` (touches `nodeTreeMirror`) — main only. + await MainActor.run { clearTracked() } } let wrapped: WrappedSnippet = SnippetHarness.wrap(userBody: userBody) let args: [String] = makeSwiftcArgs() let snippet: CompiledSnippet = try await Task.detached(priority: .userInitiated) { try LiveSession.compileBlocking(wrapped: wrapped, extraArgs: args) }.value - runEntry(of: snippet) + // Snippet entry runs the user's `context.play(_:)` → `engine.add` (@MainActor). + await MainActor.run { runEntry(of: snippet) } return snippet } diff --git a/LiveCompile/Sources/LyrebirdLiveCompile/SnippetContext.swift b/LiveCompile/Sources/LyrebirdLiveCompile/SnippetContext.swift index 512eefb..0653e37 100644 --- a/LiveCompile/Sources/LyrebirdLiveCompile/SnippetContext.swift +++ b/LiveCompile/Sources/LyrebirdLiveCompile/SnippetContext.swift @@ -37,7 +37,7 @@ public final class SnippetContext { /// - Returns: `true` if the engine accepted the enqueue; `false` if /// `engine.add` threw (e.g. cross-engine binding, double-add, queue full). @discardableResult - public func play(_ synth: any Synthesizer) -> Bool { + @MainActor public func play(_ synth: any Synthesizer) -> Bool { do { try session.engine.add(synth) session.track(synth) diff --git a/LiveCompile/Sources/LyrebirdLiveCompile/SnippetHarness.swift b/LiveCompile/Sources/LyrebirdLiveCompile/SnippetHarness.swift index 30de0da..4baeb22 100644 --- a/LiveCompile/Sources/LyrebirdLiveCompile/SnippetHarness.swift +++ b/LiveCompile/Sources/LyrebirdLiveCompile/SnippetHarness.swift @@ -17,6 +17,14 @@ public enum SnippetHarness { /// Wraps `userBody` in the standard preamble. + /// + /// The user body runs inside `MainActor.assumeIsolated { … }` (Phase 203): snippets call + /// `@MainActor` API — `context.play(_:)` and `SynthesizerBase` subclass construction + /// (both `@MainActor` since Phase 201) — which would not compile from the nonisolated + /// `@_cdecl` entry under Swift 6. The `assumeIsolated` closure gives the body main-actor + /// isolation at compile time; it is safe at runtime because `LiveSession` always invokes + /// the entry on the main actor (`compileAndRunAsync` hops via `MainActor.run`; + /// `compileAndRun` is `@MainActor`). public static func wrap(userBody: String) -> WrappedSnippet { let preamble: String = """ import LyrebirdSynth @@ -27,14 +35,18 @@ public enum SnippetHarness { guard let ctx else { return } let context = Unmanaged.fromOpaque(ctx).takeUnretainedValue() _ = context + MainActor.assumeIsolated { """ // Count newlines in the preamble: the user's body starts on the next line. // `components(separatedBy: "\n")` over a string ending in "\n" yields N+1 // elements (the last is empty); offset = count of those elements = lines - // before the user body + 1 (the line on which the body starts). + // before the user body + 1 (the line on which the body starts). The + // `MainActor.assumeIsolated {` line is part of the preamble, so the offset + // already accounts for it and diagnostic line-mapping stays correct. let lineOffset: Int = preamble.components(separatedBy: "\n").count - let suffix: String = "\n}\n" + // Close the `assumeIsolated` closure, then the entry function. + let suffix: String = "\n }\n}\n" let source: String = preamble + userBody + suffix return WrappedSnippet(source: source, userBodyLineOffset: lineOffset) } diff --git a/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionDiagnosticsTests.swift b/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionDiagnosticsTests.swift index 0edf1bc..e040453 100644 --- a/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionDiagnosticsTests.swift +++ b/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionDiagnosticsTests.swift @@ -11,6 +11,7 @@ import LyrebirdSynth #if os(macOS) +@MainActor @Suite("LiveSession diagnostics") struct LiveSessionDiagnosticsTests { diff --git a/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionTests.swift b/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionTests.swift index acd016d..be34f66 100644 --- a/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionTests.swift +++ b/LiveCompile/Tests/LyrebirdLiveCompileTests/LiveSessionTests.swift @@ -11,6 +11,7 @@ import LyrebirdSynth #if os(macOS) +@MainActor @Suite("LiveSession") struct LiveSessionTests { @@ -73,6 +74,27 @@ struct LiveSessionTests { #expect(session.lastSnippetMessage == "async hello") } + /// Phase 203 runtime guard: a snippet driven through `compileAndRunAsync` that calls + /// `context.play(_:)` actually adds and tracks a synth. `context.play` → `engine.add` is + /// `@MainActor` (Phase 201); `compileAndRunAsync` resumes the snippet entry on the main + /// actor (not the nonisolated executor it suspends on), so this exercises that hop. + @Test + func asyncCompileAndRunPlaysAndTracksSynth() async throws { + let engine: SynthesisEngine = makeEngine() + let session: LiveSession = LiveSession(engine: engine) + #expect(session.trackedSynthCount == 0) + let body: String = """ + final class SineSynth: SynthesizerBase { + override func build() { + output(bus: 0, source: OscSin.Audio(freq: 440, mul: 0.1)) + } + } + _ = context.play(SineSynth()) + """ + _ = try await session.compileAndRunAsync(body) + #expect(session.trackedSynthCount == 1) + } + @Test func asyncCompileFailureSurfacesDiagnosticsThroughSnippetCompileFailed() async { let engine: SynthesisEngine = makeEngine() diff --git a/Package.swift b/Package.swift index 0065755..6e20f2a 100644 --- a/Package.swift +++ b/Package.swift @@ -83,22 +83,17 @@ let package = Package( // .copy preserves the directory structure exactly (Xcode discovers // templates by .xctemplate bundle name + TemplateInfo.plist). .copy("Resources/XcodeTemplates"), - ], - // Swift 5 language mode: the LineNoise package pre-dates Swift 6 concurrency - // annotations. The CLI is a single-threaded synchronous command dispatcher — - // strict concurrency checking adds noise without safety benefit here. - swiftSettings: [.swiftLanguageMode(.v5)] + ] + // Swift 6 language mode (Phase 202): inherits the swift-tools 6.0 default. ), .target( name: "LyrebirdUI", dependencies: [ "LyrebirdSynth", ], - path: "Sources/LyrebirdUI", + path: "Sources/LyrebirdUI" // SwiftUI + AppKit + Observation are system frameworks — no linkerSettings needed. - // .v5 mode: avoids Swift 6 actor-isolation diagnostics in SwiftUI/AppKit interop - // until the concurrency model for UI is fully audited (same rationale as LyrebirdCLI). - swiftSettings: [.swiftLanguageMode(.v5)] + // Swift 6 language mode (Phase 202): inherits the swift-tools 6.0 default. ), // Phase 167 — `LyrebirdLiveCompile` (and its SwiftUI host // `LyrebirdLiveCompileUI`) moved to the `LiveCompile/` nested SwiftPM @@ -130,14 +125,12 @@ let package = Package( "LyrebirdUI", "LyrebirdSynth", ], - path: "Tests/LyrebirdUITests", - swiftSettings: [.swiftLanguageMode(.v5)] + path: "Tests/LyrebirdUITests" ), .testTarget( name: "LyrebirdCLITests", dependencies: ["LyrebirdCLI"], - path: "Tests/LyrebirdCLITests", - swiftSettings: [.swiftLanguageMode(.v5)] + path: "Tests/LyrebirdCLITests" ), ] ) diff --git a/README.md b/README.md index b7f068e..901b949 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,6 @@ Use `Lyrebird-Package` for day-to-day development of the engine and tests. |---|---| | Schemes don't appear | Close Xcode, run `swift package resolve`, reopen | | `Synchronization.Atomic` not indexed | Requires Xcode 16+ — false errors in older versions, still builds | -| LineNoise concurrency warnings | Expected — `LyrebirdCLI` uses `.swiftLanguageMode(.v5)` intentionally | | Nimble in Package dependencies | Cosmetic — LineNoise transitive dep, never built in Lyrebird targets | | Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. | | `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. | diff --git a/RegressionFixtures/MainActorConsumer/Package.resolved b/RegressionFixtures/MainActorConsumer/Package.resolved new file mode 100644 index 0000000..50d6b62 --- /dev/null +++ b/RegressionFixtures/MainActorConsumer/Package.resolved @@ -0,0 +1,24 @@ +{ + "originHash" : "761afb81afb2ac947c6453b20b16362a6beb5e16c81166e6f2953e07cff14b07", + "pins" : [ + { + "identity" : "linenoise-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/andybest/linenoise-swift", + "state" : { + "revision" : "afc897c02b030af7333105c4fedcd843a8339238", + "version" : "0.0.3" + } + }, + { + "identity" : "nimble", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Nimble.git", + "state" : { + "revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0", + "version" : "7.3.4" + } + } + ], + "version" : 3 +} diff --git a/RegressionFixtures/MainActorConsumer/Package.swift b/RegressionFixtures/MainActorConsumer/Package.swift new file mode 100644 index 0000000..6990b73 --- /dev/null +++ b/RegressionFixtures/MainActorConsumer/Package.swift @@ -0,0 +1,41 @@ +// swift-tools-version: 6.0 +// +// Phase 201 regression fixture — committed smoke test. +// +// Proves that a consumer building under Xcode 26's default +// `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` (reproduced here with +// `.swiftLanguageMode(.v6)` + the raw `-default-isolation MainActor` unsafe flag — +// `.defaultIsolation(MainActor.self)` is unavailable in this SwiftPM toolchain) can +// subclass `SynthesizerBase` and override `build()` with ZERO concurrency annotations. +// +// If `SynthesizerBase`'s `@MainActor` isolation ever regresses, this package fails to +// compile with: +// "main actor-isolated instance method 'build()' has different actor isolation +// from nonisolated overridden declaration" +// +// Build to verify: (cd RegressionFixtures/MainActorConsumer && swift build) +// +// This is a standalone SwiftPM package (not part of the root `swift test`), mirroring +// the `LiveCompile/` sub-package layout. It references the core package by relative path. + +import PackageDescription + +let package = Package( + name: "MainActorConsumer", + platforms: [.macOS(.v15)], + dependencies: [ + .package(name: "Lyrebird", path: "../..") + ], + targets: [ + .executableTarget( + name: "MainActorConsumer", + dependencies: [ + .product(name: "Lyrebird", package: "Lyrebird") + ], + swiftSettings: [ + .swiftLanguageMode(.v6), + .unsafeFlags(["-default-isolation", "MainActor"]) + ] + ) + ] +) diff --git a/RegressionFixtures/MainActorConsumer/Sources/MainActorConsumer/main.swift b/RegressionFixtures/MainActorConsumer/Sources/MainActorConsumer/main.swift new file mode 100644 index 0000000..3405bd0 --- /dev/null +++ b/RegressionFixtures/MainActorConsumer/Sources/MainActorConsumer/main.swift @@ -0,0 +1,21 @@ +// main.swift +// MainActorConsumer (Phase 201 regression fixture) +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth + +// PHASE 201 GUARANTEE: a consumer under the MainActor-default build mode subclasses +// `SynthesizerBase` and overrides `build()` with NO `nonisolated`, NO `@preconcurrency`, +// NO `@MainActor`, NO `nonisolated override init`. If this stops compiling, the +// language-side actor-isolation guarantee has regressed. +final class ToneSynth: SynthesizerBase { + @LiveParam var freq: Double = 440 + override func build() { + output(bus: 0, source: OscSin.Audio(freq: $freq) * 0.2) + } +} + +let synth = ToneSynth() +print("Phase 201 regression fixture OK: \(synth)") diff --git a/Sources/Lyrebird/AUv3/LyrebirdAudioUnit.swift b/Sources/Lyrebird/AUv3/LyrebirdAudioUnit.swift index ae93161..c83b61e 100644 --- a/Sources/Lyrebird/AUv3/LyrebirdAudioUnit.swift +++ b/Sources/Lyrebird/AUv3/LyrebirdAudioUnit.swift @@ -81,7 +81,12 @@ open class LyrebirdAudioUnit: AUAudioUnit { /// Required override. Construct and return the synthesizer instance that this /// AU should host. - open class func makeSynthesizer() -> SynthesizerBase { + /// + /// `@MainActor` (Phase 201): the override constructs a `@MainActor` `SynthesizerBase` + /// subclass, so the factory must be main-actor-isolated for a consumer building under + /// the MainActor-default mode to override it with no concurrency annotations — the same + /// rationale as `SynthesizerBase.build()`. Invoked from `init` on the host's main thread. + @MainActor open class func makeSynthesizer() -> SynthesizerBase { fatalError("LyrebirdAudioUnit subclasses must override `makeSynthesizer()`") } @@ -222,7 +227,9 @@ open class LyrebirdAudioUnit: AUAudioUnit { ) throws { // 1. Resolve subclass configuration. - let synth: SynthesizerBase = Self.makeSynthesizer() + // `makeSynthesizer()` is `@MainActor` (it builds a `@MainActor` synth); `AUAudioUnit` + // instances are created by the host on the main thread, so `assumeIsolated` is valid. + let synth: SynthesizerBase = MainActor.assumeIsolated { Self.makeSynthesizer() } let blockSize: Int = Self.lyrebirdBlockSize let outputBusSpecs: [LyrebirdAUBusSpec] = Self.lyrebirdOutputBusses let inputBusSpecs: [LyrebirdAUBusSpec] = Self.lyrebirdInputBusses @@ -436,7 +443,18 @@ open class LyrebirdAudioUnit: AUAudioUnit { newEngine.auOutputBusOffsets = _outputBusOffsets newEngine.auInputBusOffsets = _inputBusOffsets try newEngine.start() - try newEngine.add(synthesizer) + // `engine.add` is `@MainActor` (Phase 201). `allocateRenderResources()` overrides + // `AUAudioUnit`'s nonisolated declaration, so this method cannot itself be + // `@MainActor`. AU hosts usually call render-resource allocation on the main thread, + // but the contract does not guarantee it — the bridge runs the add inline when on + // main and hops synchronously otherwise, so an off-main host (e.g. auval) does not + // trap. The `nonisolated(unsafe)` local transfers the non-`Sendable` engine into the + // bridge closure without tripping region-isolation's sending check (the same value is + // reused below at `engine = newEngine`). `synthesizer` is `Sendable` (`SynthesizerBase` + // is `@MainActor` ⇒ implicitly Sendable), so it needs no such annotation. + nonisolated(unsafe) let engineToConfigure: SynthesisEngine = newEngine + let synthToAdd: SynthesizerBase = synthesizer + try lyrebirdRunMainActorMutation { try engineToConfigure.add(synthToAdd) } engine = newEngine } diff --git a/Sources/Lyrebird/Buffers/LyrebirdBufferFileIO.swift b/Sources/Lyrebird/Buffers/LyrebirdBufferFileIO.swift index 5705fe7..9b83b85 100644 --- a/Sources/Lyrebird/Buffers/LyrebirdBufferFileIO.swift +++ b/Sources/Lyrebird/Buffers/LyrebirdBufferFileIO.swift @@ -267,7 +267,7 @@ public extension LyrebirdBuffer { /// /// For session-end dumps from a ``LyrebirdEventList`` teardown, see the /// "Persisting Captured Input Buffers" subsection of the Process System - /// article (DocC: ``ProcessSystem``) — it covers the background-task + /// article (DocC: ) — it covers the background-task /// pattern (captures strong buffer refs, gated on the next session via /// `await`) that lets large buffers (4 × ~460 MB) flush to disk without /// blocking the UI and without doubling peak memory on rapid stop/start. diff --git a/Sources/Lyrebird/Engine/MainActorMutationBridge.swift b/Sources/Lyrebird/Engine/MainActorMutationBridge.swift new file mode 100644 index 0000000..218cee4 --- /dev/null +++ b/Sources/Lyrebird/Engine/MainActorMutationBridge.swift @@ -0,0 +1,49 @@ +// MainActorMutationBridge.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Foundation + +/// Run a `@MainActor` node-tree mutation from a language-side dispatch adapter that may +/// execute either on the main thread or inline on a background NRT driver thread. +/// +/// Phase 201 made the engine's add / schedule path and `Synthesizer.build`/`release`/`free` +/// `@MainActor`. Most language-side adapters dispatch those mutations through +/// `DispatchQueue.main.async`, so they already run on main. Two adapters can run a mutation +/// **inline on the calling thread**: +/// +/// - `LyrebirdMessageContext(nrtEngine:)` — the NRT inline dispatcher (`_dispatch = { $0() }`) +/// used by `TriggerListener._drainSync`. An NRT render driven from a background thread +/// would invoke the mutation off-main. +/// - `LyrebirdAudioUnit.allocateRenderResources()` — overrides a nonisolated `AUAudioUnit` +/// method; AU hosts *usually* call it on main, but the contract does not guarantee it. +/// +/// A bare `MainActor.assumeIsolated` would **trap** (`dispatch_assert_queue_fail`) on those +/// off-main paths. This bridge instead: +/// +/// - runs `body` inline via `assumeIsolated` when already on the main thread (the common +/// case — zero hop), and +/// - hops synchronously to main otherwise. NRT is offline (not the RT audio thread), so a +/// synchronous main hop is acceptable; it never runs on the real-time render callback, +/// which uses the default `DispatchQueue.main.async` dispatcher and never reaches here. +/// +/// `body` is intentionally **not** `@Sendable` so it can capture the non-`Sendable` engine / +/// synthesizer it mutates; `DispatchQueue.sync` does not escape the closure, so this is safe. +/// `body` returns `Void`: a non-`Sendable` result would have to cross back from the main +/// thread on the off-main hop, which `DispatchQueue.sync` rejects. All node-tree mutations +/// here are fire-and-forget, so `Void` is sufficient and keeps the signature simple. +@inline(__always) +internal func lyrebirdRunMainActorMutation(_ body: @MainActor () throws -> Void) rethrows { + // NOTE: no `_lyrebirdAssertNotOnRTThread()` here. `RTThreadIdentity` is a thread-local + // marker that persists on pooled/reused threads (and AU drivers may mark the allocate + // thread), so an assert false-positives on legitimate off-main callers like AUv3 + // `allocateRenderResources`. RT-path purity is instead enforced statically by the + // `generatorSourcesContainNoActorHopMachinery` source lint (Phase201IsolationGuardTests). + if Thread.isMainThread { + try MainActor.assumeIsolated(body) + return + } + try DispatchQueue.main.sync { try MainActor.assumeIsolated(body) } +} diff --git a/Sources/Lyrebird/Engine/RTThreadIdentity.swift b/Sources/Lyrebird/Engine/RTThreadIdentity.swift index 6725ad9..aab0f74 100644 --- a/Sources/Lyrebird/Engine/RTThreadIdentity.swift +++ b/Sources/Lyrebird/Engine/RTThreadIdentity.swift @@ -81,6 +81,19 @@ internal enum RTThreadIdentity { let sentinel: UnsafeMutableRawPointer? = UnsafeMutableRawPointer(bitPattern: _markerBitPattern) return pthread_getspecific(_key) == sentinel } + + #if DEBUG + /// TEST-ONLY: clear the RT marker on the calling thread. + /// + /// Production never unmarks — an RT render thread stays an RT render thread for the + /// engine's life. But tests that call ``markCurrentThreadAsRT()`` on a transient + /// `DispatchQueue(label:)` worker must clear it before that pthread returns to the + /// system pool; otherwise the stale marker can false-trip `_lyrebirdAssertNotOnRTThread` + /// in a later test that the pool hands the same thread. Not compiled in release. + internal static func _clearCurrentThreadRTMarkForTesting() { + pthread_setspecific(_key, nil) + } + #endif } // MARK: - DEBUG assert helper diff --git a/Sources/Lyrebird/Engine/SynthesisEngine.swift b/Sources/Lyrebird/Engine/SynthesisEngine.swift index 33098a7..60ad538 100644 --- a/Sources/Lyrebird/Engine/SynthesisEngine.swift +++ b/Sources/Lyrebird/Engine/SynthesisEngine.swift @@ -1291,7 +1291,7 @@ public final class SynthesisEngine { /// dropped and the binding (if just acquired) released. Callers can react by /// retrying after a future block, increasing `eventQueueCapacity` at engine /// init time, or surfacing a UI-level back-off. - public func schedule( + @MainActor public func schedule( _ synth: any Synthesizer, at time: SampleTime ) throws { @@ -1320,7 +1320,7 @@ public final class SynthesisEngine { /// - `EngineAddError.boundToOtherEngine` — synth is bound to a different engine. /// - `EngineAddError.pendingQueueFull` — pendingQueue was full; the event was /// dropped and the binding (if just acquired) released. - public func schedule( + @MainActor public func schedule( _ synth: any Synthesizer, after seconds: Double ) throws { @@ -1393,7 +1393,7 @@ public final class SynthesisEngine { /// Equivalent to `schedule(_:at:currentTime)`. The synthesizer lands at the head of /// `mainGroup` — newest-first order. Safe to call from the main thread. /// - Throws: `EngineAddError` — see `schedule(_:at:)` for cases. - public func add(_ synth: any Synthesizer) throws { + @MainActor public func add(_ synth: any Synthesizer) throws { try schedule(synth, at: currentTime) } @@ -1407,7 +1407,7 @@ public final class SynthesisEngine { /// group-relative insertion, or `.before(_:)` / `.after(_:)` for sibling-relative /// insertion (linear O(n) tree search; falls back to `mainGroup` head on miss). /// - Throws: `EngineAddError` — see `schedule(_:at:)` for cases. - public func add( + @MainActor public func add( _ synth: any Synthesizer, position: NodePosition ) throws { @@ -1744,7 +1744,10 @@ public final class SynthesisEngine { /// Build the generator DAG and pre-allocate the linked-list `PreparedNode`. /// All allocation and `build()`/`rebuildGraph()` happen here on the calling thread; /// the RT thread never allocates in `applyEvent`. - private func prepareNode(_ synth: any Synthesizer) -> PreparedNode { + /// `@MainActor`: invokes `build()` / `rebuildGraph()` (the `@MainActor` language-side + /// add surface — Phase 201). The node-tree add path runs on the main thread by + /// contract (it also touches `nodeTreeMirror`, observed by SwiftUI). + @MainActor private func prepareNode(_ synth: any Synthesizer) -> PreparedNode { if let base: SynthesizerBase = synth as? SynthesizerBase { base.rebuildGraph() } else { @@ -1754,7 +1757,7 @@ public final class SynthesisEngine { } /// Build the generator DAG, pre-allocate the linked-list node, and wrap in a `.add` event. - private func prepareAddEvent( + @MainActor private func prepareAddEvent( _ synth: any Synthesizer, at time: SampleTime ) -> ScheduledEvent { diff --git a/Sources/Lyrebird/Envelopes/DoneActionWatchable.swift b/Sources/Lyrebird/Envelopes/DoneActionWatchable.swift index 2da0bad..43ae2c0 100644 --- a/Sources/Lyrebird/Envelopes/DoneActionWatchable.swift +++ b/Sources/Lyrebird/Envelopes/DoneActionWatchable.swift @@ -15,7 +15,7 @@ /// ``SpectralPlayBuffer`` conform out of the box. Any future generator that /// supports `.freeNode` semantics can opt in by adopting this protocol and /// forwarding to its own atomic flag, then calling -/// ``_registerAutoFreeIfNeeded(_:)`` from its designated init. +/// `_registerAutoFreeIfNeeded(_:)` from its designated init. public protocol DoneActionWatchable: AnyObject { /// `true` once the generator's `doneAction == .freeNode` has /// fired. Backed by an atomic load — safe to read from any thread. diff --git a/Sources/Lyrebird/External/LyrebirdMessageContext.swift b/Sources/Lyrebird/External/LyrebirdMessageContext.swift index 084eb44..09f5139 100644 --- a/Sources/Lyrebird/External/LyrebirdMessageContext.swift +++ b/Sources/Lyrebird/External/LyrebirdMessageContext.swift @@ -56,8 +56,13 @@ public struct LyrebirdMessageContext: @unchecked Sendable { public func add(_ synth: any Synthesizer) { let args: SynthArgs = SynthArgs(engine, synth) _dispatch { - do { try args.engine.add(args.synth) } - catch { print("[Lyrebird] MessageContext.add failed: \(error)") } + // `_dispatch` runs this on main (default `DispatchQueue.main.async`) or inline on + // the NRT driver thread. `engine.add` is `@MainActor` (Phase 201); the bridge runs + // it inline when already on main and hops synchronously otherwise — never traps. + lyrebirdRunMainActorMutation { + do { try args.engine.add(args.synth) } + catch { print("[Lyrebird] MessageContext.add failed: \(error)") } + } } } @@ -74,8 +79,10 @@ public struct LyrebirdMessageContext: @unchecked Sendable { ) { let args: SynthArgs = SynthArgs(engine, synth) _dispatch { - do { try args.engine.schedule(args.synth, at: time) } - catch { print("[Lyrebird] MessageContext.schedule(at:) failed: \(error)") } + lyrebirdRunMainActorMutation { + do { try args.engine.schedule(args.synth, at: time) } + catch { print("[Lyrebird] MessageContext.schedule(at:) failed: \(error)") } + } } } @@ -86,8 +93,10 @@ public struct LyrebirdMessageContext: @unchecked Sendable { ) { let args: SynthArgs = SynthArgs(engine, synth) _dispatch { - do { try args.engine.schedule(args.synth, after: seconds) } - catch { print("[Lyrebird] MessageContext.schedule(after:) failed: \(error)") } + lyrebirdRunMainActorMutation { + do { try args.engine.schedule(args.synth, after: seconds) } + catch { print("[Lyrebird] MessageContext.schedule(after:) failed: \(error)") } + } } } @@ -124,10 +133,13 @@ public struct LyrebirdMessageContext: @unchecked Sendable { // but a warning posts to LyrebirdMessageCenter so debug builds get // visibility into typo'd OSC / MIDI param names that would // otherwise route silently to nowhere. - do { - try args.synth.updateParameter(args.key, value: args.value) - } catch { - Task { @MainActor in + // `updateParameter` is `@MainActor` (Phase 201). `_dispatch` runs this on main + // (default) or inline on the NRT driver — the bridge runs inline on main and hops + // synchronously off-main, never trapping. + lyrebirdRunMainActorMutation { + do { + try args.synth.updateParameter(args.key, value: args.value) + } catch { LyrebirdMessageCenter.shared.post( .warning, "parameter '\(args.key)' on \(type(of: args.synth)) — \(error)", diff --git a/Sources/Lyrebird/GeneratorCore/RootRegistering.swift b/Sources/Lyrebird/GeneratorCore/RootRegistering.swift index 9337345..09cae13 100644 --- a/Sources/Lyrebird/GeneratorCore/RootRegistering.swift +++ b/Sources/Lyrebird/GeneratorCore/RootRegistering.swift @@ -31,24 +31,24 @@ /// /// ## Do not double-register /// -/// A `RootRegistering` generator that auto-registers from inside ``build()`` -/// **and** is also passed to ``SynthesizerBase/addOutputGenerator(_:)`` will +/// A `RootRegistering` generator that auto-registers from inside `build()` +/// **and** is also passed to `SynthesizerBase.addOutputGenerator(_:)` will /// appear twice in `outputGenerators`. Within one block segment the second -/// evaluation is short-circuited by the ``Generator/_segmentSerial`` fan-out +/// evaluation is short-circuited by the `_segmentSerial` fan-out /// cache (no `_computeSamples` re-run), so the side effect fires exactly /// once — but the double entry adds a redundant cache check per segment. Let -/// auto-registration handle it, or construct outside ``build()`` and register +/// auto-registration handle it, or construct outside `build()` and register /// manually — never both. /// /// ## Relationship to `DoneActionWatchable` /// /// `RootRegistering` mirrors the ``DoneActionWatchable`` auto-registration /// pattern. Both protocols read the same -/// ``SynthesizerBase/_currentlyBuildingRef`` task-local set by -/// ``SynthesizerBase/rebuildGraph()``. A generator may conform to both +/// `_SynthesizerBuildContext.currentRef` task-local set by +/// `SynthesizerBase.rebuildGraph()`. A generator may conform to both /// (e.g. ``RecordBuffer/Audio``): the init calls -/// ``DoneActionWatchable/_registerAutoFreeIfNeeded(_:)`` and then -/// ``_registerAsRootIfBuilding()``. +/// `_registerAutoFreeIfNeeded(_:)` and then +/// `_registerAsRootIfBuilding()`. public protocol RootRegistering: Generator {} extension RootRegistering { diff --git a/Sources/Lyrebird/Generators/BusIO/ReplaceOut.swift b/Sources/Lyrebird/Generators/BusIO/ReplaceOut.swift index 3aa9f9b..1a52563 100644 --- a/Sources/Lyrebird/Generators/BusIO/ReplaceOut.swift +++ b/Sources/Lyrebird/Generators/BusIO/ReplaceOut.swift @@ -21,7 +21,7 @@ /// Additive ``Out`` writers that run **after** ReplaceOut accumulate into the /// replaced content as normal. /// -/// Inside a ``ParallelGroup``, ReplaceOut routes through ``ScratchBuses.replace`` +/// Inside a ``ParallelGroup``, ReplaceOut routes through `ScratchBuses.replace` /// and only overwrites *this child's scratch contribution*. It does not scrub /// other siblings' parallel writes nor any pre-parallel engine-bus content. See /// `docs/engine/eventlist-routing-design.md` for the full semantic table. diff --git a/Sources/Lyrebird/Generators/Demand/DemandBrownian.swift b/Sources/Lyrebird/Generators/Demand/DemandBrownian.swift index 1a20e1d..708fb8d 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandBrownian.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandBrownian.swift @@ -8,7 +8,7 @@ /// `[-step, step]` to the current state, clamping to `[low, high]`. /// /// RT-side counterpart to ``Pattern/brownian(low:high:step:start:length:seed:)``. -/// Backed by the same module-internal ``BrownianPatternEngine``. Complement +/// Backed by the same module-internal `BrownianPatternEngine`. Complement /// to ``DemandTemporalBrownian``: this is a plain stateless-parameter /// Brownian walk, while ``DemandTemporalBrownian`` accepts /// ``RTTemporalParameter`` bounds / step that can evolve over time. diff --git a/Sources/Lyrebird/Generators/Demand/DemandGeometric.swift b/Sources/Lyrebird/Generators/Demand/DemandGeometric.swift index 5a3afae..9de9757 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandGeometric.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandGeometric.swift @@ -7,7 +7,7 @@ /// Demand-rate geometric series: `start, start·ratio, start·ratio², …`. /// /// RT-side counterpart to ``Pattern/geometric(start:ratio:length:)``. Backed -/// by the same module-internal ``GeometricPatternEngine``. +/// by the same module-internal `GeometricPatternEngine`. /// /// **RT contract** — `nextValue()` and `reset()` are pure arithmetic; no /// allocation, no locks. Single-owner per puller. diff --git a/Sources/Lyrebird/Generators/Demand/DemandNonRepeatingRandom.swift b/Sources/Lyrebird/Generators/Demand/DemandNonRepeatingRandom.swift index 1f5ec04..4eaf0ff 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandNonRepeatingRandom.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandNonRepeatingRandom.swift @@ -7,7 +7,7 @@ /// Demand-rate random pick avoiding the same *index* as the previous pick. /// /// RT-side counterpart to ``Pattern/nonRepeatingRandom(_:repeats:seed:)``. -/// Backed by the same module-internal ``NonRepeatingRandomPatternEngine`` +/// Backed by the same module-internal `NonRepeatingRandomPatternEngine` /// parameterised over `Double`. Matches SC `Dxrand` semantics. /// /// **Index-based, not value-based.** If `values` contains duplicate doubles diff --git a/Sources/Lyrebird/Generators/Demand/DemandSeries.swift b/Sources/Lyrebird/Generators/Demand/DemandSeries.swift index 35a3daa..e847e01 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandSeries.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandSeries.swift @@ -7,7 +7,7 @@ /// Demand-rate arithmetic series: `start, start + step, start + 2·step, …`. /// /// RT-side counterpart to ``Pattern/series(start:step:length:)``. Backed by -/// the same module-internal ``SeriesPatternEngine`` — algorithm and behaviour +/// the same module-internal `SeriesPatternEngine` — algorithm and behaviour /// match exactly. `length == -1` runs forever. /// /// **RT contract** — `nextValue()` and `reset()` are pure arithmetic; no diff --git a/Sources/Lyrebird/Generators/Demand/DemandShuffle.swift b/Sources/Lyrebird/Generators/Demand/DemandShuffle.swift index 00539d4..36275a7 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandShuffle.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandShuffle.swift @@ -8,7 +8,7 @@ /// cycles through the permuted order. Same permutation replays on `reset()`. /// /// RT-side counterpart to ``Pattern/shuffle(_:repeats:seed:)``. Backed by the -/// same module-internal ``ShufflePatternEngine`` parameterised over `Double`. +/// same module-internal `ShufflePatternEngine` parameterised over `Double`. /// Matches SC `Dshuf` semantics. /// /// **RT contract** — Fisher-Yates runs once at init (off the RT thread). diff --git a/Sources/Lyrebird/Generators/Demand/DemandUniformRandom.swift b/Sources/Lyrebird/Generators/Demand/DemandUniformRandom.swift index fdc694c..2ea9a92 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandUniformRandom.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandUniformRandom.swift @@ -7,7 +7,7 @@ /// Demand-rate uniform random samples in `[low, high]`. /// /// RT-side counterpart to ``Pattern/uniformRandom(low:high:length:seed:)``. -/// Backed by the same module-internal ``UniformRandomPatternEngine``. +/// Backed by the same module-internal `UniformRandomPatternEngine`. /// Complement to the pool-based ``DemandRandom``: this draws continuous /// values inside a range rather than picking from a discrete set. /// diff --git a/Sources/Lyrebird/Generators/Demand/DemandWeightedRandom.swift b/Sources/Lyrebird/Generators/Demand/DemandWeightedRandom.swift index d77ab38..dc33823 100644 --- a/Sources/Lyrebird/Generators/Demand/DemandWeightedRandom.swift +++ b/Sources/Lyrebird/Generators/Demand/DemandWeightedRandom.swift @@ -8,7 +8,7 @@ /// the matching entry in `weights`. /// /// RT-side counterpart to ``Pattern/weightedRandom(_:weights:repeats:seed:)``. -/// Backed by the same module-internal ``WeightedRandomPatternEngine`` +/// Backed by the same module-internal `WeightedRandomPatternEngine` /// parameterised over `Double`. Matches SC `Dwrand` semantics. /// /// **Init preconditions** — `values.count == weights.count`, all weights diff --git a/Sources/Lyrebird/Lyrebird.docc/GeneratorInputProvider.md b/Sources/Lyrebird/Lyrebird.docc/GeneratorInputProvider.md index 50fa217..b70013c 100644 --- a/Sources/Lyrebird/Lyrebird.docc/GeneratorInputProvider.md +++ b/Sources/Lyrebird/Lyrebird.docc/GeneratorInputProvider.md @@ -227,5 +227,6 @@ The full helper-boundary policy lives in [`docs/protocols/writing-generators.md` - ``LyrebirdProcess`` - ``ValidGeneratorInput`` - ``ValueComputable`` -- `docs/protocols/writing-generators.md` § 3.1 — init-time resolution contract -- `docs/protocols/writing-generators.md` § 13 — shared helper functions + +Further reading: `docs/protocols/writing-generators.md` § 3.1 (init-time resolution +contract) and § 13 (shared helper functions). diff --git a/Sources/Lyrebird/Lyrebird.docc/Generators/MultiChannel.md b/Sources/Lyrebird/Lyrebird.docc/Generators/MultiChannel.md index c18b652..585bb8d 100644 --- a/Sources/Lyrebird/Lyrebird.docc/Generators/MultiChannel.md +++ b/Sources/Lyrebird/Lyrebird.docc/Generators/MultiChannel.md @@ -189,7 +189,7 @@ Affected parameters include ``AmbiEncoder1/init(input:azimuth:elevation:mul:add: To convert at the language-side boundary — UI knobs that present degrees to musicians, OSC messages from external apps, score files that author in degrees — -use ``degreesToRadians(_:)`` and ``radiansToDegrees(_:)`` from `LyrebirdMusicMath`: +use `degreesToRadians(_:)` and `radiansToDegrees(_:)` from `LyrebirdMusicMath`: ```swift let azDeg: Double = 45.0 diff --git a/Sources/Lyrebird/Lyrebird.docc/ProcessSystem.md b/Sources/Lyrebird/Lyrebird.docc/ProcessSystem.md index d9cbc24..d828d22 100644 --- a/Sources/Lyrebird/Lyrebird.docc/ProcessSystem.md +++ b/Sources/Lyrebird/Lyrebird.docc/ProcessSystem.md @@ -529,8 +529,6 @@ A 20-minute mono buffer at 48 kHz is ~460 MB; four of them is ~1.8 GB and severa 3. `await` that task, then `clear()` the buffers in place and rebuild the input synths so the next performance starts fresh. 4. If the engine is stopped while a write is still in flight, retain the `Task` and `await` it before allocating fresh buffers for the next session — otherwise the writer's pinned refs and new allocations coexist (~2× memory peak). -```swift - ```swift // On engine .stopped — launch a background write that survives invalidate / nil-out. @discardableResult @@ -1026,10 +1024,10 @@ The `LyrebirdUI` module provides SwiftUI panels that bind directly to a `Lyrebir | View | Bound to | Purpose | |------|----------|---------| -| ``LyrebirdProcessView`` | one `LyrebirdProcess` | Start / Release transport, amp slider, running-state indicator. | -| ``LyrebirdEventListView`` | one `LyrebirdEventList` | Now/Next event display, master amp slider, Next / Skip / Release All / Kill All / Reset / Set Next. | -| ``LyrebirdRunningProcessesView`` | one `LyrebirdEventList` | One `LyrebirdProcessView` per currently-running process owned by the list. Appears when a process starts; disappears when it finishes. | -| ``LyrebirdEventListPerformanceView`` | one `LyrebirdEventList` | Larger performance-focused panel. | +| `LyrebirdProcessView` | one `LyrebirdProcess` | Start / Release transport, amp slider, running-state indicator. | +| `LyrebirdEventListView` | one `LyrebirdEventList` | Now/Next event display, master amp slider, Next / Skip / Release All / Kill All / Reset / Set Next. | +| `LyrebirdRunningProcessesView` | one `LyrebirdEventList` | One `LyrebirdProcessView` per currently-running process owned by the list. Appears when a process starts; disappears when it finishes. | +| `LyrebirdEventListPerformanceView` | one `LyrebirdEventList` | Larger performance-focused panel. | ### Mounting in a Host View @@ -1057,11 +1055,11 @@ struct MyPiece: View { } ``` -`LyrebirdRunningProcessesView` polls `eventList.allProcesses` at 10 Hz (same cadence as the other panels), filters to processes for which `isRunning == true`, and instantiates one ``LyrebirdProcessView`` per surviving entry. Identity is tracked by `ObjectIdentifier`, not by `LyrebirdProcess.id`, so two processes that happen to share an `id` string render as distinct rows. The poll only re-assigns its `@State` snapshot when the set of running identities changes — child `LyrebirdProcessView` instances persist across ticks, so per-row UI state (slider drag, focus) is not destroyed every 100 ms. +`LyrebirdRunningProcessesView` polls `eventList.allProcesses` at 10 Hz (same cadence as the other panels), filters to processes for which `isRunning == true`, and instantiates one `LyrebirdProcessView` per surviving entry. Identity is tracked by `ObjectIdentifier`, not by `LyrebirdProcess.id`, so two processes that happen to share an `id` string render as distinct rows. The poll only re-assigns its `@State` snapshot when the set of running identities changes — child `LyrebirdProcessView` instances persist across ticks, so per-row UI state (slider drag, focus) is not destroyed every 100 ms. ### Standalone (non-EventList) Processes -``LyrebirdRunningProcessesView`` is scoped to one `LyrebirdEventList`. A standalone process created directly via `LyrebirdProcess.init(...)` and played via `process.play(engine:)` is not visible there — host code keeps its own reference and embeds a ``LyrebirdProcessView`` for it directly: +`LyrebirdRunningProcessesView` is scoped to one `LyrebirdEventList`. A standalone process created directly via `LyrebirdProcess.init(...)` and played via `process.play(engine:)` is not visible there — host code keeps its own reference and embeds a `LyrebirdProcessView` for it directly: ```swift LyrebirdProcessView(process: standaloneProcess, engine: engine) @@ -1069,7 +1067,7 @@ LyrebirdProcessView(process: standaloneProcess, engine: engine) ### macOS Standalone Windows -Each panel has a `presentInWindow(...)` factory that opens a free-floating ``LyrebirdWindow`` — useful for REPL / CLI demos that have no parent SwiftUI scene: +Each panel has a `presentInWindow(...)` factory that opens a free-floating `LyrebirdWindow` — useful for REPL / CLI demos that have no parent SwiftUI scene: ```swift let win = LyrebirdRunningProcessesView.presentInWindow( @@ -1092,11 +1090,11 @@ win.close() - ``LyrebirdProcessError`` - ``LyrebirdTimelineEntry`` - ``LyrebirdTimelineError`` -- ``LyrebirdProcessView`` -- ``LyrebirdEventListView`` -- ``LyrebirdRunningProcessesView`` -- ``LyrebirdEventListPerformanceView`` - - - - + +SwiftUI panels (in the separate `LyrebirdUI` module): `LyrebirdProcessView`, +`LyrebirdEventListView`, `LyrebirdRunningProcessesView`, +`LyrebirdEventListPerformanceView`. diff --git a/Sources/Lyrebird/Lyrebird.docc/Targets.md b/Sources/Lyrebird/Lyrebird.docc/Targets.md index 22468d4..cff7baa 100644 --- a/Sources/Lyrebird/Lyrebird.docc/Targets.md +++ b/Sources/Lyrebird/Lyrebird.docc/Targets.md @@ -32,7 +32,7 @@ Optional GUI module. import LyrebirdUI ``` -Provides: `LyrebirdWindow` (AppKit/SwiftUI host), `@SynthParam` property wrapper, and pre-built slider/knob views. Uses Swift 5 language mode to avoid actor-isolation diagnostics in SwiftUI/AppKit interop. +Provides: `LyrebirdWindow` (AppKit/SwiftUI host), `@SynthParam` property wrapper, and pre-built slider/knob views. Builds under Swift 6 language mode (Phase 202). **Rule:** never import `LyrebirdUI` in `Lyrebird` — GUI code must stay in this module only. @@ -49,7 +49,7 @@ lyrebird export MySynth lyrebird repl ``` -Provides an interactive `lyrebird>` shell with history and tab completion. Uses Swift 5 language mode (LineNoise predates Swift 6 concurrency annotations). +Provides an interactive `lyrebird>` shell with history and tab completion. Builds under Swift 6 language mode (Phase 202). See for a full walkthrough. @@ -104,12 +104,12 @@ swift test ``` LyrebirdC └── Lyrebird (links CoreAudio, AudioToolbox, Accelerate) - ├── LyrebirdUI (SwiftUI + AppKit, Swift 5 mode) + ├── LyrebirdUI (SwiftUI + AppKit) ├── LyrebirdDemo ├── LyrebirdBenchmark └── LyrebirdUIDemo (also links LyrebirdUI) -LyrebirdCLI (links LineNoise, Swift 5 mode) +LyrebirdCLI (links LineNoise) ``` ## Choosing a Starting Point diff --git a/Sources/Lyrebird/Math/LyrebirdMusicMath.swift b/Sources/Lyrebird/Math/LyrebirdMusicMath.swift index 106df9e..297adae 100644 --- a/Sources/Lyrebird/Math/LyrebirdMusicMath.swift +++ b/Sources/Lyrebird/Math/LyrebirdMusicMath.swift @@ -147,8 +147,8 @@ public func ratioToCents(_ ratios: [Double]) -> [Double] { ratios.map { ratioToC /// Useful for driving pitch-shift / playback-rate generators that take a ratio /// while you reason musically in semitones — e.g. `PitchShift.Audio(pitchRatio: midiToRatio(12))`. /// -/// Synonym for ``semitonesToRatio(_:)`` with an SC-flavored name that mirrors -/// ``midiToHz(_:)``. Both compile to the same expression; pick whichever reads +/// Synonym for `semitonesToRatio(_:)` with an SC-flavored name that mirrors +/// `midiToHz(_:)`. Both compile to the same expression; pick whichever reads /// best at the call site. @inline(__always) public func midiToRatio(_ semitones: Double) -> Double { semitonesToRatio(semitones) } @@ -160,7 +160,7 @@ public func midiToRatio(_ semitones: Int) -> Double { semitonesToRatio(Double(se /// Frequency ratio → semitone interval (MIDI delta). `2.0` → `12.0`, `0.5` → `-12.0`, /// `1.0` → `0.0`. Returns `-.infinity` / `NaN` for `ratio <= 0`. /// -/// Synonym for ``ratioToSemitones(_:)`` paired with ``midiToRatio(_:)``. +/// Synonym for `ratioToSemitones(_:)` paired with `midiToRatio(_:)`. @inline(__always) public func ratioToMidi(_ ratio: Double) -> Double { ratioToSemitones(ratio) } @@ -434,7 +434,7 @@ public extension Collection where Element == Double { func semitonesToRatio() -> [Double] { map { LyrebirdSynth.semitonesToRatio($0) } } /// Semitone intervals → frequency ratio per element. SC-flavored synonym - /// for ``semitonesToRatio()`` matching the ``midiToHz()`` / ``hzToMidi()`` + /// for `semitonesToRatio(_:)` matching the `midiToHz(_:)` / `hzToMidi(_:)` /// naming pair. Language-side only — allocates a new `[Double]`. func midiToRatio() -> [Double] { map { LyrebirdSynth.midiToRatio($0) } } diff --git a/Sources/Lyrebird/NodeTree/Group.swift b/Sources/Lyrebird/NodeTree/Group.swift index ac6bff8..9187d3f 100644 --- a/Sources/Lyrebird/NodeTree/Group.swift +++ b/Sources/Lyrebird/NodeTree/Group.swift @@ -75,7 +75,11 @@ public final class Group: Synthesizer { // MARK: - Synthesizer conformance /// Groups have no generator graph of their own. - public func build() {} + /// + /// `nonisolated`: a less-isolated witness still satisfies the `@MainActor` + /// `Synthesizer.build()` requirement. Lets the engine install `mainGroup` pre-start + /// from `init` without an actor hop. + nonisolated public func build() {} /// Evaluate all children in insertion order. public func evaluate( @@ -104,7 +108,13 @@ public final class Group: Synthesizer { /// only the first call starts the cascade. /// /// Language-side only — do not call from the RT thread. - public func release(engine: SynthesisEngine) { + /// + /// `@MainActor` (Phase 201): the child cascade calls the `@MainActor` + /// `child.release`/`child.free`. The self-free poll timer — which runs its handler on a + /// utility queue and therefore must NOT be main-actor-isolated — is installed by the + /// `nonisolated` helper `_startSelfFreeTimer(engine:)` so the handler does not inherit + /// this method's isolation (which would trap when the timer fires off-main). + @MainActor public func release(engine: SynthesisEngine) { let (exchanged, _) = _releaseStarted.compareExchange( expected: false, desired: true, ordering: .sequentiallyConsistent ) @@ -144,6 +154,18 @@ public final class Group: Synthesizer { return } + _startSelfFreeTimer(engine: engine) + } + + /// Install the repeating utility-queue timer that self-frees this group once its child + /// count reaches zero. + /// + /// `nonisolated` so the `setEventHandler` closure does NOT inherit `release`'s + /// `@MainActor` isolation (Phase 201) — a main-actor-isolated handler would trap + /// (`dispatch_assert_queue_fail`) when the timer fires on the utility queue. The handler + /// touches only the atomic count off-main and hops to main (via the `@unchecked Sendable` + /// ``GroupFreeArgs``) for the actual `free`. + nonisolated private func _startSelfFreeTimer(engine: SynthesisEngine) { // Poll count atomically; self-free when empty. `source` is captured strongly in its // own handler — this intentional retain cycle is broken by the `source.cancel()` calls // on all exit paths, so the timer does not leak. @@ -153,11 +175,14 @@ public final class Group: Synthesizer { guard let self: Group, let engine: SynthesisEngine else { source.cancel(); return } if self._atomicCount.load(ordering: .relaxed) == 0 { source.cancel() - // Hop to main: `free(engine:)` mutates `engine.nodeTreeMirror`, - // which is observed by SwiftUI on the main thread. Touching it - // from the timer's utility queue would race with view reads. + // Hop to main: `free(engine:)` is `@MainActor` and mutates + // `engine.nodeTreeMirror`, which is observed by SwiftUI on the main + // thread. Touching it from the timer's utility queue would race with + // view reads. `assumeIsolated` documents that this runs on main. let args: GroupFreeArgs = GroupFreeArgs(group: self, engine: engine) - DispatchQueue.main.async { args.group.free(engine: args.engine) } + DispatchQueue.main.async { + MainActor.assumeIsolated { args.group.free(engine: args.engine) } + } } } source.resume() @@ -170,7 +195,7 @@ public final class Group: Synthesizer { /// removed from its parent in the node tree. /// /// Language-side only — do not call from the RT thread. - public func free(engine: SynthesisEngine) { + @MainActor public func free(engine: SynthesisEngine) { let enqueued: Bool = engine.pendingQueue.enqueue( .groupFree(self, parentGroup: nil, at: engine.currentTime) ) diff --git a/Sources/Lyrebird/NodeTree/ParallelGroup.swift b/Sources/Lyrebird/NodeTree/ParallelGroup.swift index 3776c58..a5ebe36 100644 --- a/Sources/Lyrebird/NodeTree/ParallelGroup.swift +++ b/Sources/Lyrebird/NodeTree/ParallelGroup.swift @@ -108,7 +108,7 @@ public final class ParallelGroup: Synthesizer { /// is built immediately (equivalent to the engine's `prepareAddEvent` path). /// /// - Parameter synth: The synthesizer to add. Must not already be active in any engine. - public func add(_ synth: any Synthesizer) { + @MainActor public func add(_ synth: any Synthesizer) { if let base: SynthesizerBase = synth as? SynthesizerBase { base.rebuildGraph() } else { @@ -121,7 +121,11 @@ public final class ParallelGroup: Synthesizer { /// Snapshot children and allocate scratch buses. Called by the engine's /// `prepareAddEvent` path (off the RT thread) before this group is wired in. - public func build() { + /// + /// `nonisolated`: a less-isolated witness satisfies the `@MainActor` `build()` + /// requirement. Mutates only nonisolated snapshot/scratch state, read on the RT thread + /// in `evaluate()` after the add barrier. + nonisolated public func build() { childrenSnapshot.removeAll(keepingCapacity: true) var node: PreparedNode? = head while let current: PreparedNode = node { diff --git a/Sources/Lyrebird/Patterns/PatternFactories.swift b/Sources/Lyrebird/Patterns/PatternFactories.swift index 3fa69c0..9659901 100644 --- a/Sources/Lyrebird/Patterns/PatternFactories.swift +++ b/Sources/Lyrebird/Patterns/PatternFactories.swift @@ -43,7 +43,7 @@ public extension Pattern { /// Picks one value at random from `values` per call, never picking the /// same *index* as the previous pick. See - /// ``NonRepeatingRandomPatternEngine`` for the index-vs-value caveat + /// `NonRepeatingRandomPatternEngine` for the index-vs-value caveat /// when `values` contains duplicates. /// /// - Parameters: diff --git a/Sources/Lyrebird/Process/LyrebirdEventList.swift b/Sources/Lyrebird/Process/LyrebirdEventList.swift index a5f946e..6b0b561 100644 --- a/Sources/Lyrebird/Process/LyrebirdEventList.swift +++ b/Sources/Lyrebird/Process/LyrebirdEventList.swift @@ -404,7 +404,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Master amplitude, lag-smoothed. /// /// Writing ramps to the new value over `ampLag` seconds. - public var amp: Double { + @MainActor public var amp: Double { get { _masterSynth?.$amp.value ?? _initialAmp } set { _masterSynth?.amp = newValue } } @@ -446,14 +446,14 @@ public final class LyrebirdEventList: @unchecked Sendable { /// fires. The synth's lifetime is bounded by `_masterGroup.free()` in /// `_teardownMaster()` — it is automatically released on EventList /// teardown. - public func addPreMaster(_ synth: any Synthesizer) throws { + @MainActor public func addPreMaster(_ synth: any Synthesizer) throws { try _engine.add(synth, position: .tail(of: _preMasterGroup)) } /// Convenience for adding a post-master FX synth at the tail of /// ``postMasterGroup``. Same timing and lifetime guarantees as /// ``addPreMaster(_:)``. - public func addPostMaster(_ synth: any Synthesizer) throws { + @MainActor public func addPostMaster(_ synth: any Synthesizer) throws { try _engine.add(synth, position: .tail(of: _postMasterGroup)) } @@ -523,7 +523,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Play the event at the current ``index`` and increment the index. /// /// No-op when ``nextEvent`` is `nil` (past the end). - public func next() { + @MainActor public func next() { guard _index < _events.count else { return } let idx: Int = _index _index += 1 @@ -535,7 +535,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Out-of-range indices are silently ignored. /// /// - Parameter eventIndex: Zero-based index into the events array. - public func play(eventIndex: Int) { + @MainActor public func play(eventIndex: Int) { guard eventIndex >= 0, eventIndex < _events.count else { return } // Capture engine.currentTime ONCE at the top of the call so every @@ -622,7 +622,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// /// Calls ``LyrebirdProcess/release(reltime:)`` on each running, non-releasing /// process. Does not advance ``index``. - public func releaseAll() { + @MainActor public func releaseAll() { for proc: LyrebirdProcess in _allProcesses { if proc.isRunning && !proc.isReleasing { proc.release() @@ -650,7 +650,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// begins. Use it to dump session ``LyrebirdBuffer``s to disk or run any /// other performance-scoped cleanup. See the "Persisting Captured Input /// Buffers" subsection of the Process System article. - public func killAll() { + @MainActor public func killAll() { // Fire the end-of-performance hook before any teardown so callers can // observe the live state (buffers, node tree) one last time. onKillAll?() @@ -731,18 +731,18 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Poll until `killProc` finishes, then tear down the master on the main thread. /// Uses a DispatchQueue delayed dispatch cascade to avoid blocking the caller. - private func _scheduleDeferredMasterTeardown( + @MainActor private func _scheduleDeferredMasterTeardown( killProc: LyrebirdProcess, engine: SynthesisEngine ) { // Poll interval: 10 ms — matches the watcher timer interval in LyrebirdProcess. let killProcPollIntervalMs: Int = 10 - func poll() { + @MainActor func poll() { if killProc.isRunning { // Still running — re-arm. DispatchQueue.main.asyncAfter( deadline: .now() + .milliseconds(killProcPollIntervalMs) - ) { poll() } + ) { MainActor.assumeIsolated { poll() } } } else { // Kill process done — tear down master now. self._teardownMaster() @@ -750,7 +750,7 @@ public final class LyrebirdEventList: @unchecked Sendable { } DispatchQueue.main.asyncAfter( deadline: .now() + .milliseconds(killProcPollIntervalMs) - ) { poll() } + ) { MainActor.assumeIsolated { poll() } } } /// Kill everything, reset ``index`` to `0`, clear recording state, clear the @@ -767,7 +767,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Any in-progress ``playTimeline(clock:)`` is stopped before the reset. /// Processes that were recording continue to flush their in-flight DiskOut /// buffers to disk until their teardown completes. - public func reset() { + @MainActor public func reset() { stopTimelinePlayback() killAll() stopRecord() @@ -1122,7 +1122,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// `_startSampleTime` so the first event's stem-filename offset /// (which reads `playSampleTime - _startSampleTime`) is exactly /// zero when both reads share the same origin. - private func _firstEventSetup(at originSampleTime: SampleTime) throws { + @MainActor private func _firstEventSetup(at originSampleTime: SampleTime) throws { // Defer mutating instance state (isRunning / dates) until ALL // engine.add calls have succeeded. A mid-sequence throw would // otherwise leave the EventList with isRunning=true and @@ -1399,7 +1399,7 @@ public final class LyrebirdEventList: @unchecked Sendable { /// Free the master synth and both groups. The master `_bus` is caller-owned /// and is NOT released here. - private func _teardownMaster() { + @MainActor private func _teardownMaster() { if let synth: EventListMasterSynth = _masterSynth { // engine.remove routes through pendingQueue (SPSCQueue, lock-free) — RT-safe // to call from the main thread. diff --git a/Sources/Lyrebird/Process/LyrebirdProcess.swift b/Sources/Lyrebird/Process/LyrebirdProcess.swift index ea19e64..5fc7e32 100644 --- a/Sources/Lyrebird/Process/LyrebirdProcess.swift +++ b/Sources/Lyrebird/Process/LyrebirdProcess.swift @@ -59,7 +59,11 @@ final class ProcessRouteSynth: SynthesizerBase { /// The `EnvelopeGen.Audio` instance used to drive the amplitude envelope. /// Held as a strong reference so the watcher can read `needsFree` off-RT. - private(set) var envGen: EnvelopeGen.Audio? + /// + /// `nonisolated(unsafe)`: assigned in `build()` on main; the `LyrebirdProcess` watcher + /// reads `envGen?.needsFree` (an atomic flag) from a utility-queue timer. Effectively + /// immutable after `build()`; cross-thread read is safe (Phase 201). + nonisolated(unsafe) private(set) var envGen: EnvelopeGen.Audio? init( envelope: Envelope, @@ -175,7 +179,10 @@ final class ProcessRouteSynth: SynthesizerBase { /// caller is responsible for routing the process's output to the EventList's /// `bus` (or to any other downstream consumer) if master amp control is wanted. /// - target: Where to insert this process's group in the node tree. -/// - body: `async` closure invoked with a ``LyrebirdProcessContext``. +/// - body: `async` closure invoked with a ``LyrebirdProcessContext``. Runs on the +/// `@MainActor` (Phase 201) so it can construct `@MainActor` `SynthesizerBase` +/// subclasses and call `ctx.add(_:)` directly — no `await MainActor.run { … }` +/// wrapping needed. `await ctx.wait(_:)` suspends without blocking the main thread. /// - onRelease: Optional callback invoked when ``release(reltime:)`` is /// called. Receives the context so callers can remove synths or update /// parameters before the tail. @@ -214,11 +221,11 @@ public final class LyrebirdProcess: @unchecked Sendable { private let _target: LyrebirdProcessTarget /// Maximum amplitude (in dB) that the amplitude slider in - /// ``LyrebirdProcessView`` should expose. Defaults to `+12` dB. + /// `LyrebirdProcessView` should expose. Defaults to `+12` dB. /// Raise per-process when a source needs additional headroom above unity. /// Has no effect on engine behaviour — purely a UI hint. public let maxUIAmpDb: Double - private let _body: @Sendable (LyrebirdProcessContext) async -> Void + private let _body: @MainActor @Sendable (LyrebirdProcessContext) async -> Void private let _onRelease: ((LyrebirdProcessContext) -> Void)? private let _onFinished: (() -> Void)? @@ -294,7 +301,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// writable after ``play(engine:)``. Defaults to `1.0`. /// - ampLag: Lag time in seconds applied to amplitude changes. Defaults /// to `0.01` s. - /// - maxUIAmpDb: Maximum amplitude (in dB) that ``LyrebirdProcessView`` + /// - maxUIAmpDb: Maximum amplitude (in dB) that `LyrebirdProcessView` /// should expose on its amplitude slider. Defaults to `+12` dB. Raise /// when a source needs additional UI headroom above unity. Purely a UI /// hint — has no effect on engine behaviour. @@ -327,7 +334,7 @@ public final class LyrebirdProcess: @unchecked Sendable { numChannels: Int, procOut: any ValidBus = 0, target: LyrebirdProcessTarget = .head, - body: @escaping @Sendable (LyrebirdProcessContext) async -> Void, + body: @escaping @MainActor @Sendable (LyrebirdProcessContext) async -> Void, onRelease: ((LyrebirdProcessContext) -> Void)? = nil, onFinished: (() -> Void)? = nil, ) { @@ -379,7 +386,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// (lag-smoothed over `ampLag` seconds). /// /// Changes ramp to the new value over `ampLag` seconds. - public var amp: Double { + @MainActor public var amp: Double { get { _routeSynth?.$amp.value ?? _initialAmp } set { if let routeSynth: ProcessRouteSynth = _routeSynth { @@ -407,7 +414,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// (explicit ``kill()`` or natural envelope completion) and its /// main-thread teardown, the process rearms to idle and can be played /// again. - public func play(engine: SynthesisEngine) { + @MainActor public func play(engine: SynthesisEngine) { do { try _play(engine: engine, parentGroup: engine.mainGroup) } catch { @@ -439,7 +446,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// - parentGroup: The group to add this process's private group into. /// - playSampleTimeOverride: Optional sample-time origin so EventList /// can align stem-filename offsets to a shared timeline anchor. - internal func _play( + @MainActor internal func _play( engine: SynthesisEngine, parentGroup: Group, playSampleTimeOverride: SampleTime? = nil @@ -557,8 +564,8 @@ public final class LyrebirdProcess: @unchecked Sendable { _context = context // Launch body task. - let body: @Sendable (LyrebirdProcessContext) async -> Void = _body - _bodyTask = Task { + let body: @MainActor @Sendable (LyrebirdProcessContext) async -> Void = _body + _bodyTask = Task { @MainActor in await body(context) } @@ -582,7 +589,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// Override support requires EnvelopeGen swap-queue integration and is /// not yet wired — passing a non-nil `reltime` emits a warning but is /// otherwise ignored. - public func release(reltime: Double? = nil) { + @MainActor public func release(reltime: Double? = nil) { guard _stateRaw.compareExchange( expected: LyrebirdProcess.stateRunning, desired: LyrebirdProcess.stateReleasing, @@ -650,8 +657,10 @@ public final class LyrebirdProcess: @unchecked Sendable { // _teardown (dispatched below) cancels and nils _bodyTask on the main thread. if _engine != nil { DispatchQueue.main.async { [weak self] in - guard let self: LyrebirdProcess, let engine: SynthesisEngine = self._engine else { return } - self._teardown(engine: engine) + MainActor.assumeIsolated { + guard let self: LyrebirdProcess, let engine: SynthesisEngine = self._engine else { return } + self._teardown(engine: engine) + } } } } @@ -693,8 +702,10 @@ public final class LyrebirdProcess: @unchecked Sendable { // Dispatch teardown to the main thread. Access _engine through self to // avoid sending a non-Sendable SynthesisEngine across isolation boundaries. DispatchQueue.main.async { [weak self] in - guard let self: LyrebirdProcess, let engine: SynthesisEngine = self._engine else { return } - self._teardown(engine: engine) + MainActor.assumeIsolated { + guard let self: LyrebirdProcess, let engine: SynthesisEngine = self._engine else { return } + self._teardown(engine: engine) + } } } _watcherTimer = timer @@ -705,7 +716,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// Free group, release bus, stop watcher, close DiskOut, fire `onFinished`. /// Must be called on the main thread. - private func _teardown(engine: SynthesisEngine) { + @MainActor private func _teardown(engine: SynthesisEngine) { // Cancel the body task first — it is safe to access here because _teardown // always runs on the main thread, which is the single writer of _bodyTask. _bodyTask?.cancel() @@ -771,8 +782,15 @@ public final class LyrebirdProcess: @unchecked Sendable { /// from whichever thread drops the final process reference. deinit { guard let engine: SynthesisEngine = _engine else { return } + // `Group.free` is `@MainActor` (Phase 201) — it touches `nodeTreeMirror`. deinit is + // nonisolated and may run on any thread, so hop the group-free to main. The bus + // release + DiskOut close are nonisolated and run inline. Capture locals (not self, + // which is mid-deinit) for the async closure. if let group: Group = _group { - group.free(engine: engine) + let capturedEngine: SynthesisEngine = engine + DispatchQueue.main.async { + MainActor.assumeIsolated { group.free(engine: capturedEngine) } + } } if let bus: AudioBus = _bus { engine.busAllocator.releaseAudioBus(bus) @@ -799,7 +817,7 @@ public final class LyrebirdProcess: @unchecked Sendable { /// - bus: The allocated route bus (DiskOut reads from this bus). /// - playSampleTime: Engine sample time at play start (used to compute offset). /// - playIndex: Zero-based counter for this process instance. - private func _spawnDiskOut( + @MainActor private func _spawnDiskOut( config: ProcessRecordingConfig, engine: SynthesisEngine, group: Group, diff --git a/Sources/Lyrebird/Process/LyrebirdProcessFactory.swift b/Sources/Lyrebird/Process/LyrebirdProcessFactory.swift index 9f6ab53..bbfb00f 100644 --- a/Sources/Lyrebird/Process/LyrebirdProcessFactory.swift +++ b/Sources/Lyrebird/Process/LyrebirdProcessFactory.swift @@ -19,5 +19,10 @@ public protocol LyrebirdProcessFactory: Sendable { /// /// Each call should return an independent process — callers may /// invoke this repeatedly to spawn distinct concurrent processes. - func createProcess() -> LyrebirdProcess + /// + /// `@MainActor` (Phase 201): conformers typically construct `@MainActor` + /// `SynthesizerBase` subclasses here, so the factory method is main-actor-isolated. + /// The protocol stays `Sendable` (factories are stored / passed across actors); only + /// the build step is pinned to main. + @MainActor func createProcess() -> LyrebirdProcess } diff --git a/Sources/Lyrebird/Synthesizer/Synthesizer.swift b/Sources/Lyrebird/Synthesizer/Synthesizer.swift index b9b6345..c95bb63 100644 --- a/Sources/Lyrebird/Synthesizer/Synthesizer.swift +++ b/Sources/Lyrebird/Synthesizer/Synthesizer.swift @@ -12,18 +12,39 @@ /// /// The default evaluate() implementation is a no-op. Most users subclass SynthesizerBase, /// which wires evaluate() to a set of registered output generators. +/// +/// ## Actor isolation (Phase 201) +/// +/// The language-side surface (`build`, `release`, `free`) is `@MainActor`-isolated so a +/// consumer building under Xcode 26's default `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` +/// can subclass `SynthesizerBase` and override `build()` with **no** concurrency +/// annotations — the consumer's MainActor default now *matches* the base instead of +/// conflicting with a nonisolated override. The single RT-thread entry point, `evaluate`, +/// is explicitly `nonisolated` so the engine's render callback reaches it with no actor +/// hop. See `ARCHITECTURE.md` §9 and `docs/00-working-order.md` Phase 201. +/// +/// Isolation is declared **per-requirement** rather than at the protocol level on purpose: +/// the consumer guarantee comes from `SynthesizerBase` being a `@MainActor` class (so its +/// subclasses inherit MainActor), while the engine-internal `Group` / `ParallelGroup` +/// conformers stay fully nonisolated — a whole-type `@MainActor` protocol would infer +/// MainActor onto their RT-owned linked-list / snapshot state and break the render path. public protocol Synthesizer: AnyObject { /// Configure the internal generator DAG. Called once by the engine when this Synthesizer /// is added to the node tree. Allocate all generators here — not during evaluate. - func build() + /// + /// `@MainActor` — called once on the main thread when the synth is added. + @MainActor func build() /// Evaluate one block segment. The engine calls this once per segment (normally once per /// block; may be called multiple times if scheduled events split the block). + /// + /// `nonisolated` — the RT render thread's only entry point into a Synthesizer. Must not + /// hop actors. See the type-level isolation note. /// - Parameters: /// - graph: The current SynthGraph context (engine + busOffset). /// - count: Number of samples to produce for this segment. - func evaluate(graph: SynthGraph, count: Int) + nonisolated func evaluate(graph: SynthGraph, count: Int) /// Begin a graceful release of this synthesizer (e.g., set gate → 0). /// @@ -31,7 +52,7 @@ public protocol Synthesizer: AnyObject { /// parameter update. The default throws `SynthesizerError.noGate`. /// /// Language-side only — never call from the RT audio thread. - func release(engine: SynthesisEngine) throws + @MainActor func release(engine: SynthesisEngine) throws /// Immediately remove this synthesizer from the node tree. /// @@ -39,20 +60,20 @@ public protocol Synthesizer: AnyObject { /// as soon as the RT thread applies the event (next block boundary or segment split). /// /// Language-side only — never call from the RT audio thread. - func free(engine: SynthesisEngine) + @MainActor func free(engine: SynthesisEngine) } extension Synthesizer { /// Default: no-op. SynthesizerBase overrides this to drive registered output generators. - public func evaluate(graph: SynthGraph, count: Int) {} + nonisolated public func evaluate(graph: SynthGraph, count: Int) {} /// Default: throws `.noGate`. Override in synthesizers with EnvelopeGen gate inputs. - public func release(engine: SynthesisEngine) throws { + @MainActor public func release(engine: SynthesisEngine) throws { throw SynthesizerError.noGate } /// Default: posts an immediate remove event via the engine's scheduling queue. - public func free(engine: SynthesisEngine) { + @MainActor public func free(engine: SynthesisEngine) { engine.remove(self) } } diff --git a/Sources/Lyrebird/Synthesizer/SynthesizerBase.swift b/Sources/Lyrebird/Synthesizer/SynthesizerBase.swift index 6b9b52a..2f903cb 100644 --- a/Sources/Lyrebird/Synthesizer/SynthesizerBase.swift +++ b/Sources/Lyrebird/Synthesizer/SynthesizerBase.swift @@ -16,7 +16,7 @@ import Synchronization /// **Side-effect generators auto-register.** Generators conforming to ``RootRegistering`` — /// ``Out/Audio``, ``Out/Control``, ``RecordBuffer/Audio``, ``RecordBuffer/Control``, /// ``DiskOut/Audio``, ``SendTrigger/Audio``, ``SendTrigger/Control`` — added themselves -/// to ``outputGenerators`` when constructed inside ``build()``. No ``addOutputGenerator(_:)`` +/// to `outputGenerators` when constructed inside ``build()``. No ``addOutputGenerator(_:)`` /// or ``output(bus:source:)`` call needed; the result may be discarded with `let _ = ...`. /// Use ``addOutputGenerator(_:)`` explicitly only when constructing a `RootRegistering` /// generator OUTSIDE ``build()`` (e.g. in a helper called from a `LyrebirdTask`). @@ -74,6 +74,18 @@ import Synchronization /// `outputGenerators` on the main thread concurrently with `evaluate()` iterating it on /// the RT thread. Always `engine.remove(synth)` and allow at least one `processBlock` to /// pass before re-adding the same instance. +/// +/// ## Actor isolation (Phase 201) +/// +/// The class is `@MainActor`-isolated so consumer subclasses building under Xcode 26's +/// `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` default override `build()` / `init()` with +/// no concurrency annotations — their MainActor default matches the base. The single +/// RT-thread entry point, `evaluate(graph:count:)`, is `nonisolated final`; the only two +/// stored properties it reads on the RT thread — `parameterTable` and `outputGenerators` — +/// are `nonisolated(unsafe)`, safe by the engine's add-event happens-before barrier +/// (see `ARCHITECTURE.md` §9 and the per-property comments below). No new runtime +/// synchronisation is introduced. +@MainActor open class SynthesizerBase: Synthesizer { // MARK: - Generator DAG @@ -84,7 +96,12 @@ open class SynthesizerBase: Synthesizer { /// **RT-safety:** only accessed from `evaluate()` (RT thread) and `rebuildGraph()` /// (main thread, before the Synthesizer enters the node tree). Concurrent access is /// prevented by the scheduling barrier in `SynthesisEngine.prepareAddEvent`. - private var outputGenerators: [any Generator] = [] + /// + /// `nonisolated(unsafe)`: written in `build()`/`rebuildGraph()` on main; read on the RT + /// thread in `evaluate()`. Cross-thread access is ordered by the add-event happens-before + /// edge through the SPSC `pendingQueue` — the RT thread cannot reach this synth until + /// `build()` has fully returned on main. See `ARCHITECTURE.md` §9. + nonisolated(unsafe) private var outputGenerators: [any Generator] = [] // MARK: - Parameter storage (RT-read / build-write) @@ -93,7 +110,12 @@ open class SynthesizerBase: Synthesizer { /// Written during `build()` (main thread, before add). Read during `evaluate()` /// (RT thread, after add) and also when building `SynthGraph` for downstream generators. /// See `ParameterTable` for the full thread-safety model. - private let parameterTable: ParameterTable = ParameterTable() + /// + /// `nonisolated(unsafe)`: the `let` reference is immutable; `.inputs` is populated on main + /// in `_autoRegisterLiveParams()` before the add event is enqueued, and read on the RT + /// thread in `evaluate()` after the add barrier. Same happens-before edge as + /// `outputGenerators`. See `ARCHITECTURE.md` §9. + nonisolated(unsafe) private let parameterTable: ParameterTable = ParameterTable() // MARK: - Engine binding @@ -139,9 +161,9 @@ open class SynthesizerBase: Synthesizer { /// stale-pointer-then-retry case (one clear + one retry); more /// iterations imply real contention where the structured error is /// more useful than spinning. - private static let bindMaxPasses: Int = 2 + nonisolated private static let bindMaxPasses: Int = 2 - internal func _bind(to engine: SynthesisEngine) throws { + nonisolated internal func _bind(to engine: SynthesisEngine) throws { let rawPointer: UnsafeMutableRawPointer = Unmanaged.passUnretained(engine).toOpaque() let target: UInt = UInt(bitPattern: rawPointer) @@ -209,7 +231,7 @@ open class SynthesizerBase: Synthesizer { /// RT-side iteration. /// /// - Parameter engine: The engine releasing ownership. - internal func _unbind(from engine: SynthesisEngine) { + nonisolated internal func _unbind(from engine: SynthesisEngine) { let rawPointer: UnsafeMutableRawPointer = Unmanaged.passUnretained(engine).toOpaque() let target: UInt = UInt(bitPattern: rawPointer) _ = _engineBinding.compareExchange( @@ -241,10 +263,13 @@ open class SynthesizerBase: Synthesizer { /// (where the task-local pointer is `nil` and auto-registration is a no-op). /// /// **Do not double-register.** Calling this with a `RootRegistering` generator - /// that already auto-registered places it in ``outputGenerators`` twice; the + /// that already auto-registered places it in `outputGenerators` twice; the /// second evaluation is short-circuited by the segment-serial fan-out cache but /// the duplicate entry is wasteful. - public final func addOutputGenerator(_ generator: any Generator) { + /// `nonisolated`: invoked from nonisolated `RootRegistering` generator inits during + /// `build()` (on main, before the add barrier). Mutates `outputGenerators` + /// (`nonisolated(unsafe)`) — same happens-before justification. + public nonisolated final func addOutputGenerator(_ generator: any Generator) { outputGenerators.append(generator) } @@ -256,7 +281,11 @@ open class SynthesizerBase: Synthesizer { /// `true`. Set automatically when a `DoneActionWatchable` generator with /// `doneAction: .freeNode` is constructed inside ``build()``, or explicitly via /// ``autoFreeOnDone(_:)``. - internal var _autoFreeProbe: (any DoneActionWatchable)? + /// + /// `nonisolated(unsafe)`: set inside `build()` on main (before the add barrier) and read + /// later by the engine's auto-free watcher on a utility-queue timer. Effectively immutable + /// after `build()` returns — same cross-thread justification as `outputGenerators`. + nonisolated(unsafe) internal var _autoFreeProbe: (any DoneActionWatchable)? /// `@unchecked Sendable` wrapper around an unowned `SynthesizerBase` pointer. /// Avoids forcing `SynthesizerBase` itself (and every user subclass) to conform @@ -272,11 +301,17 @@ open class SynthesizerBase: Synthesizer { /// `doneAction == .freeNode`. `nil` outside any `build()` context, in which case /// auto-registration is a no-op and the explicit ``autoFreeOnDone(_:)`` escape /// hatch remains available. - @TaskLocal internal static var _currentlyBuildingRef: _BuildingRef? - - /// Convenience unwrapping of ``_currentlyBuildingRef``. - internal static var _currentlyBuilding: SynthesizerBase? { - _currentlyBuildingRef?.synth + /// Convenience unwrapping of the build-context task-local. + /// + /// The backing `@TaskLocal` lives in the file-scope ``_SynthesizerBuildContext`` enum, + /// not here: `@TaskLocal` on a `@MainActor` class generates a main-actor-isolated + /// `$`-projected accessor even under `nonisolated`, which the nonisolated + /// generator-init read path cannot reach — so the storage is hoisted out of this + /// `@MainActor` class into a plain nonisolated namespace. + /// + /// `nonisolated`: read from nonisolated generator inits during `build()`. + nonisolated internal static var _currentlyBuilding: SynthesizerBase? { + _SynthesizerBuildContext.currentRef?.synth } /// Opt this synthesizer into automatic removal when the given probe @@ -310,7 +345,8 @@ open class SynthesizerBase: Synthesizer { /// Calling this twice replaces the previous probe. Pass a generator that the /// synth's own DAG already retains (the engine does not strengthen the /// reference) — losing the probe to ARC turns the auto-free into a no-op. - public final func autoFreeOnDone(_ probe: any DoneActionWatchable) { + /// `nonisolated`: callable from `DoneActionWatchable` generator inits during `build()`. + public nonisolated final func autoFreeOnDone(_ probe: any DoneActionWatchable) { _autoFreeProbe = probe } @@ -351,7 +387,10 @@ open class SynthesizerBase: Synthesizer { /// (sub-)block — no synchronization is required here. /// /// Called by the engine — do not call directly. - public final func evaluate(graph: SynthGraph, count: Int) { + /// + /// `nonisolated`: the RT render thread's entry point. Reads only `parameterTable` and + /// `outputGenerators` (both `nonisolated(unsafe)`), safe by the add-event barrier. + public nonisolated final func evaluate(graph: SynthGraph, count: Int) { let localGraph: SynthGraph = SynthGraph( engine: graph.engine, busOffset: graph.busOffset, @@ -539,7 +578,7 @@ open class SynthesizerBase: Synthesizer { /// `outputGenerators`. Always `engine.remove(synth)` before re-adding. internal func rebuildGraph() { outputGenerators.removeAll() - SynthesizerBase.$_currentlyBuildingRef.withValue(_BuildingRef(synth: self)) { + _SynthesizerBuildContext.$currentRef.withValue(_BuildingRef(synth: self)) { build() } _autoRegisterLiveParams() @@ -578,3 +617,17 @@ open class SynthesizerBase: Synthesizer { } } } + +// MARK: - Build-context task-local (nonisolated namespace) + +/// File-scope holder for the `build()`-context task-local. +/// +/// The task-local cannot live as a static on `SynthesizerBase` because that class is +/// `@MainActor` (Phase 201): `@TaskLocal` would synthesise a main-actor-isolated +/// `$`-projected accessor, which the **nonisolated** generator-init read path +/// (`RootRegistering` / `DoneActionWatchable` self-registration) cannot reach. Hoisting it +/// into this plain `enum` keeps both the `withValue` writer (on main, inside `rebuildGraph`) +/// and the cross-init readers nonisolated. +internal enum _SynthesizerBuildContext { + @TaskLocal static var currentRef: SynthesizerBase._BuildingRef? +} diff --git a/Sources/Lyrebird/Voices/VoicePool.swift b/Sources/Lyrebird/Voices/VoicePool.swift index 63fbd15..1993728 100644 --- a/Sources/Lyrebird/Voices/VoicePool.swift +++ b/Sources/Lyrebird/Voices/VoicePool.swift @@ -89,7 +89,7 @@ public final class VoicePool { /// throw, every voice successfully added so far is rolled back via /// `engine.remove` in reverse order before the error propagates, so the /// engine's node tree is left exactly as it was before this init began. - public init( + @MainActor public init( voiceCount: Int, group: Group, engine: SynthesisEngine, diff --git a/Sources/LyrebirdBenchmark/main.swift b/Sources/LyrebirdBenchmark/main.swift index 212c413..82a8b43 100644 --- a/Sources/LyrebirdBenchmark/main.swift +++ b/Sources/LyrebirdBenchmark/main.swift @@ -293,7 +293,7 @@ final class SineToneAudioEnvSynth: SynthesizerBase { } } -func populateControlEnv(_ engine: SynthesisEngine) { +@MainActor func populateControlEnv(_ engine: SynthesisEngine) { for i: Int in 0..<16 { do { try engine.add(SineToneControlEnvSynth(freq: 220.0 * pow(2.0, Double(i) / 12.0), bus: 0)) @@ -303,7 +303,7 @@ func populateControlEnv(_ engine: SynthesisEngine) { } } -func populateAudioEnv(_ engine: SynthesisEngine) { +@MainActor func populateAudioEnv(_ engine: SynthesisEngine) { for i: Int in 0..<16 { do { try engine.add(SineToneAudioEnvSynth(freq: 220.0 * pow(2.0, Double(i) / 12.0), bus: 0)) @@ -405,7 +405,7 @@ final class PitchShiftSynth: SynthesizerBase { } } -func populatePoolN(_ engine: SynthesisEngine, count: Int, overlap: Int) { +@MainActor func populatePoolN(_ engine: SynthesisEngine, count: Int, overlap: Int) { for i: Int in 0.. — Running"`. /// - width: Initial window width in points. Defaults to `360`. diff --git a/Sources/LyrebirdUI/LyrebirdUI.docc/LyrebirdUI.md b/Sources/LyrebirdUI/LyrebirdUI.docc/LyrebirdUI.md index e8c54fe..ae6d758 100644 --- a/Sources/LyrebirdUI/LyrebirdUI.docc/LyrebirdUI.md +++ b/Sources/LyrebirdUI/LyrebirdUI.docc/LyrebirdUI.md @@ -71,6 +71,6 @@ that need GUI windows. ### Live Coding -The live-coding scratchpad (``LyrebirdScratchView`` / ``LyrebirdScratchModel``) lives +The live-coding scratchpad (`LyrebirdScratchView` / `LyrebirdScratchModel`) lives in the separate `LyrebirdLiveCompileUI` module (sub-package `LiveCompile/`). See the `LyrebirdLiveCompileUI` docc archive for the `LiveCoding` article. diff --git a/Tests/LyrebirdTests/AUv3/AUInputTests.swift b/Tests/LyrebirdTests/AUv3/AUInputTests.swift index c977100..09371cd 100644 --- a/Tests/LyrebirdTests/AUv3/AUInputTests.swift +++ b/Tests/LyrebirdTests/AUv3/AUInputTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AUInput.Audio") struct AUInputAudioTests { @Test func channelMustBeNonNegative() { diff --git a/Tests/LyrebirdTests/AUv3/AUv3DriverTests.swift b/Tests/LyrebirdTests/AUv3/AUv3DriverTests.swift index 3558792..a6f2da0 100644 --- a/Tests/LyrebirdTests/AUv3/AUv3DriverTests.swift +++ b/Tests/LyrebirdTests/AUv3/AUv3DriverTests.swift @@ -88,9 +88,11 @@ private struct ABLFixture { } } +@MainActor @Suite("AUv3Driver") struct AUv3DriverTests { @Test func returnsUninitializedBeforeSetup() { + defer { lyrebirdClearRTMarkAfterTestRender() } let driver: AUv3Driver = AUv3Driver() let fixture: ABLFixture = ABLFixture(channels: 2, frames: 64) defer { fixture.deallocate() } @@ -99,6 +101,7 @@ private struct ABLFixture { } @Test func rejectsFrameCountAboveMax() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 256) let engine: SynthesisEngine = SynthesisEngine( blockSize: 128, sampleRate: 44100, @@ -114,6 +117,7 @@ private struct ABLFixture { } @Test func smallHostFrameCountDrivesMultipleEngineBlocks() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } // Engine block 128; host requests 64 per call — two calls per engine block. let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 64) let engine: SynthesisEngine = SynthesisEngine( @@ -156,6 +160,7 @@ private struct ABLFixture { } @Test func largeHostFrameCountPullsMultipleEngineBlocks() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } // Host wants 1024 per call but engine block is 256 — 4 engine blocks per // render call. let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 1024) @@ -182,6 +187,7 @@ private struct ABLFixture { } @Test func alternatingFrameCountsPreserveContinuity() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } // Hosts may switch frame counts mid-stream; the ring must keep sample // continuity intact. let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 1024) diff --git a/Tests/LyrebirdTests/AUv3/AUv3RingBufferTests.swift b/Tests/LyrebirdTests/AUv3/AUv3RingBufferTests.swift index 98efa34..1dedafb 100644 --- a/Tests/LyrebirdTests/AUv3/AUv3RingBufferTests.swift +++ b/Tests/LyrebirdTests/AUv3/AUv3RingBufferTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AUv3RingBuffer") struct AUv3RingBufferTests { @Test func capacityRoundsUpToPowerOfTwo() { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAUParameterMappingTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAUParameterMappingTests.swift index bb4edd2..2b19f6d 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAUParameterMappingTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAUParameterMappingTests.swift @@ -32,6 +32,7 @@ private final class InheritedParamSynth: ParamSynth { // MARK: - Tests +@MainActor @Suite("LyrebirdAUParameterMapping discovery") struct LyrebirdAUParameterDiscoveryTests { @Test func discoversAllLiveParamsInDeclarationOrder() { @@ -70,6 +71,7 @@ private final class InheritedParamSynth: ParamSynth { } } +@MainActor @Suite("LyrebirdAUParameterMapping tree") struct LyrebirdAUParameterTreeTests { @Test func buildsOneAUParameterPerSlot() { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAUPresetRegistryTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAUPresetRegistryTests.swift index c950283..1f3d774 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAUPresetRegistryTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAUPresetRegistryTests.swift @@ -43,6 +43,7 @@ private final class FixturePresetGen: GeneratorBase, AudioGenerator, LyrebirdAUP func floatValue(graph: SynthGraph) -> Double { _amp } } +@MainActor @Suite("LyrebirdAUPresetSourceRegistry") struct LyrebirdAUPresetRegistryTests { @Test func registerAndMakeRoundTrip() { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAUVoicePoolBindingTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAUVoicePoolBindingTests.swift index f7f3400..8d5a73c 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAUVoicePoolBindingTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAUVoicePoolBindingTests.swift @@ -15,6 +15,7 @@ private final class TestVoice: SynthesizerBase { override func build() { output(bus: 0, source: $freq * $amp * $gate) } } +@MainActor @Suite("LyrebirdAUVoicePoolBinding") struct LyrebirdAUVoicePoolBindingTests { @Test func noteOnAllocatesVoiceAndConfigures() throws { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitEffectTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitEffectTests.swift index 7bd2802..c745a9b 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitEffectTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitEffectTests.swift @@ -21,7 +21,7 @@ private final class PassthroughSynth: SynthesizerBase { private final class PassthroughEffectAU: LyrebirdAudioUnit { public override class func makeSynthesizer() -> SynthesizerBase { - PassthroughSynth() + MainActor.assumeIsolated { PassthroughSynth() } } public override class var lyrebirdInputChannels: Int { 2 } public override class var lyrebirdOutputChannels: Int { 2 } @@ -37,6 +37,7 @@ private func makeEffectDescription() -> AudioComponentDescription { ) } +@MainActor @Suite("LyrebirdAudioUnit effect") struct LyrebirdAudioUnitEffectTests { @Test func effectAUDeclaresInputAndOutputBuses() throws { @@ -62,7 +63,7 @@ private func makeEffectDescription() -> AudioComponentDescription { override func build() { output(bus: 0, source: 0.0) } } final class StubInstrumentAU: LyrebirdAudioUnit { - public override class func makeSynthesizer() -> SynthesizerBase { StubSynth() } + public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { StubSynth() } } } let desc: AudioComponentDescription = AudioComponentDescription( componentType: kAudioUnitType_MusicDevice, diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMIDITests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMIDITests.swift index 77aed12..5ac1eb0 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMIDITests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMIDITests.swift @@ -10,6 +10,7 @@ import AudioToolbox import AVFoundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LyrebirdAudioUnit MIDI dispatch") struct LyrebirdAudioUnitMIDITests { @Test func dispatchHandlesNilHeadGracefully() { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMultiBusTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMultiBusTests.swift index ec6059a..0e1d257 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMultiBusTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitMultiBusTests.swift @@ -26,7 +26,7 @@ private final class StemRenderSynth: SynthesizerBase { } private final class StemRenderAU: LyrebirdAudioUnit { - public override class func makeSynthesizer() -> SynthesizerBase { StemRenderSynth() } + public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { StemRenderSynth() } } public override class var lyrebirdOutputBusses: [LyrebirdAUBusSpec] { [ .init(name: "Main", channelCount: 2), @@ -48,7 +48,7 @@ private final class SidechainPassthrough: SynthesizerBase { } private final class SidechainAU: LyrebirdAudioUnit { - public override class func makeSynthesizer() -> SynthesizerBase { SidechainPassthrough() } + public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { SidechainPassthrough() } } public override class var lyrebirdOutputBusses: [LyrebirdAUBusSpec] { [.init(name: "Output", channelCount: 2)] } @@ -67,7 +67,7 @@ private final class SingleBusSynth: SynthesizerBase { } private final class SingleBusAU: LyrebirdAudioUnit { - public override class func makeSynthesizer() -> SynthesizerBase { SingleBusSynth() } + public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { SingleBusSynth() } } // No bus-spec overrides — must keep the default single-bus behaviour. } @@ -81,6 +81,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { ) } +@MainActor @Suite("LyrebirdAudioUnit multi-bus — defaults") struct LyrebirdAudioUnitMultiBusDefaultTests { @Test func singleBusAUKeeps104aShape() throws { @@ -97,6 +98,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { } } +@MainActor @Suite("LyrebirdAudioUnit multi-bus — multi-output") struct LyrebirdAudioUnitMultiOutputBusTests { @Test func twoOutputBussesAreExposed() throws { @@ -120,6 +122,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { } @Test func asymmetricBusPullsDoNotCrash() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } // AU spec lets a host pull bus 0 repeatedly without pulling bus 1. // Without the driver's saturation guard this would overflow bus 1's // ring buffer after `capacity / blockSize` engine advances. @@ -157,6 +160,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { } @Test func renderingRoutesEachBusIndependently() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } let au: StemRenderAU = try StemRenderAU(componentDescription: makeAUDesc(subtype: 0x534D4F44)) try au.allocateRenderResources() defer { au.deallocateRenderResources() } @@ -199,6 +203,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { } } +@MainActor @Suite("LyrebirdAudioUnit multi-bus — sidechain input") struct LyrebirdAudioUnitSidechainTests { @Test func twoInputBussesAreExposed() throws { @@ -219,6 +224,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription { } @Test func renderLoopDispatchesPerInputBusPullBlock() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } // Drive the full internalRenderBlock → driver → _fillInputStagingFromHost // path with a synthetic pullInputBlock that fills bus 0 ABL with +1.0 // and bus 1 ABL with -1.0. Verify the AU passes bus 0 samples through diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitPresetTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitPresetTests.swift index 277466c..55f1b29 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitPresetTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitPresetTests.swift @@ -17,7 +17,7 @@ private final class PresetSynth: SynthesizerBase { } private final class PresetAU: LyrebirdAudioUnit { - public override class func makeSynthesizer() -> SynthesizerBase { PresetSynth() } + public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { PresetSynth() } } public override class func factoryPresetsForLyrebird() -> [LyrebirdAUFactoryPreset] { [ .init(name: "Bright", scalarValues: ["freq": 880, "amp": 0.8]), @@ -36,6 +36,7 @@ private func makeDesc() -> AudioComponentDescription { ) } +@MainActor @Suite("LyrebirdAudioUnit factory presets") struct LyrebirdAudioUnitFactoryPresetsTests { @Test func factoryPresetsExposeAllNames() throws { diff --git a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitTests.swift b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitTests.swift index 3fd15ed..9cb65a6 100644 --- a/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitTests.swift +++ b/Tests/LyrebirdTests/AUv3/LyrebirdAudioUnitTests.swift @@ -22,7 +22,7 @@ private final class TestFMSynth: SynthesizerBase { private final class TestFMSynthAudioUnit: LyrebirdAudioUnit { public override class func makeSynthesizer() -> SynthesizerBase { - TestFMSynth() + MainActor.assumeIsolated { TestFMSynth() } } public override class func parameterMetadata() -> [String: LyrebirdAUParameterInfo] { [ @@ -44,6 +44,7 @@ private func makeDescription() -> AudioComponentDescription { // MARK: - Init / parameter tree +@MainActor @Suite("LyrebirdAudioUnit init") struct LyrebirdAudioUnitInitTests { @Test func initSucceedsAndPopulatesParameterTree() throws { @@ -94,6 +95,7 @@ private func makeDescription() -> AudioComponentDescription { // MARK: - Resource lifecycle +@MainActor @Suite("LyrebirdAudioUnit render resources") struct LyrebirdAudioUnitRenderResourceTests { @Test func allocateAndDeallocateLifecycle() throws { @@ -127,6 +129,7 @@ private func makeDescription() -> AudioComponentDescription { } @Test func renderProducesNonzeroOutputAfterAllocate() throws { + defer { lyrebirdClearRTMarkAfterTestRender() } let au: TestFMSynthAudioUnit = try TestFMSynthAudioUnit(componentDescription: makeDescription()) try au.allocateRenderResources() defer { au.deallocateRenderResources() } @@ -175,6 +178,7 @@ private func makeDescription() -> AudioComponentDescription { // MARK: - fullState save / restore +@MainActor @Suite("LyrebirdAudioUnit fullState") struct LyrebirdAudioUnitFullStateTests { @Test func fullStateRoundTripPreservesScalarLiveParams() throws { diff --git a/Tests/LyrebirdTests/AdditiveSynthesizerTests.swift b/Tests/LyrebirdTests/AdditiveSynthesizerTests.swift index 021d01e..2a5b8ad 100644 --- a/Tests/LyrebirdTests/AdditiveSynthesizerTests.swift +++ b/Tests/LyrebirdTests/AdditiveSynthesizerTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AdditiveSynthesizer") struct AdditiveSynthesizerTests { diff --git a/Tests/LyrebirdTests/AmbiAFormatConversionTests.swift b/Tests/LyrebirdTests/AmbiAFormatConversionTests.swift index c0cb487..958cc80 100644 --- a/Tests/LyrebirdTests/AmbiAFormatConversionTests.swift +++ b/Tests/LyrebirdTests/AmbiAFormatConversionTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiAFormat conversion (B↔A)") struct AmbiAFormatConversionTests { diff --git a/Tests/LyrebirdTests/AmbiDecoderMonoTests.swift b/Tests/LyrebirdTests/AmbiDecoderMonoTests.swift index cba236e..b3e1fca 100644 --- a/Tests/LyrebirdTests/AmbiDecoderMonoTests.swift +++ b/Tests/LyrebirdTests/AmbiDecoderMonoTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiDecoderMono") struct AmbiDecoderMonoTests { diff --git a/Tests/LyrebirdTests/AmbiDecoderStereoTests.swift b/Tests/LyrebirdTests/AmbiDecoderStereoTests.swift index 86eeeaf..6bfd192 100644 --- a/Tests/LyrebirdTests/AmbiDecoderStereoTests.swift +++ b/Tests/LyrebirdTests/AmbiDecoderStereoTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiDecoderStereo") struct AmbiDecoderStereoTests { diff --git a/Tests/LyrebirdTests/AmbiDecoderUHJTests.swift b/Tests/LyrebirdTests/AmbiDecoderUHJTests.swift index d94d88b..eed3cbd 100644 --- a/Tests/LyrebirdTests/AmbiDecoderUHJTests.swift +++ b/Tests/LyrebirdTests/AmbiDecoderUHJTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiDecoderUHJ") struct AmbiDecoderUHJTests { diff --git a/Tests/LyrebirdTests/AmbiEncoder1ParameterRampingTests.swift b/Tests/LyrebirdTests/AmbiEncoder1ParameterRampingTests.swift index 4eb4a40..8776c1e 100644 --- a/Tests/LyrebirdTests/AmbiEncoder1ParameterRampingTests.swift +++ b/Tests/LyrebirdTests/AmbiEncoder1ParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiEncoder1 parameter ramping") struct AmbiEncoder1ParameterRampingTests { diff --git a/Tests/LyrebirdTests/AmbiEncoderStereoTests.swift b/Tests/LyrebirdTests/AmbiEncoderStereoTests.swift index 667cec8..1f21c55 100644 --- a/Tests/LyrebirdTests/AmbiEncoderStereoTests.swift +++ b/Tests/LyrebirdTests/AmbiEncoderStereoTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiEncoderStereo") struct AmbiEncoderStereoTests { diff --git a/Tests/LyrebirdTests/AmbiEncoderUHJTests.swift b/Tests/LyrebirdTests/AmbiEncoderUHJTests.swift index 28ec959..4742a33 100644 --- a/Tests/LyrebirdTests/AmbiEncoderUHJTests.swift +++ b/Tests/LyrebirdTests/AmbiEncoderUHJTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiEncoderUHJ") struct AmbiEncoderUHJTests { diff --git a/Tests/LyrebirdTests/AmbiSpeakerLayoutTests.swift b/Tests/LyrebirdTests/AmbiSpeakerLayoutTests.swift index 0528a8b..10ca351 100644 --- a/Tests/LyrebirdTests/AmbiSpeakerLayoutTests.swift +++ b/Tests/LyrebirdTests/AmbiSpeakerLayoutTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmbiSpeakerLayout") struct AmbiSpeakerLayoutTests { diff --git a/Tests/LyrebirdTests/AmplitudeFollowerParameterRampingTests.swift b/Tests/LyrebirdTests/AmplitudeFollowerParameterRampingTests.swift index e84ed44..c5e363d 100644 --- a/Tests/LyrebirdTests/AmplitudeFollowerParameterRampingTests.swift +++ b/Tests/LyrebirdTests/AmplitudeFollowerParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("AmplitudeFollower parameter ramping") struct AmplitudeFollowerParameterRampingTests { diff --git a/Tests/LyrebirdTests/AudioRateInputTests.swift b/Tests/LyrebirdTests/AudioRateInputTests.swift index cfca655..f0dcc48 100644 --- a/Tests/LyrebirdTests/AudioRateInputTests.swift +++ b/Tests/LyrebirdTests/AudioRateInputTests.swift @@ -45,6 +45,7 @@ private func collectSamples( // MARK: - AudioRateInput suite +@MainActor @Suite("AudioRateInput") struct AudioRateInputTests { @@ -233,6 +234,7 @@ struct AudioRateInputTests { // MARK: - FMSynthesis suite +@MainActor @Suite("FMSynthesis") struct FMSynthesisTests { diff --git a/Tests/LyrebirdTests/BinaryOpGeneratorTests.swift b/Tests/LyrebirdTests/BinaryOpGeneratorTests.swift index a513593..fcae063 100644 --- a/Tests/LyrebirdTests/BinaryOpGeneratorTests.swift +++ b/Tests/LyrebirdTests/BinaryOpGeneratorTests.swift @@ -66,6 +66,7 @@ fileprivate final class QuadConstantGen: GeneratorBase, AudioGenerator { } } +@MainActor @Suite("BinaryOpGenerator") struct BinaryOpGeneratorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -137,6 +138,7 @@ struct BinaryOpGeneratorTests { // MARK: - Multi-channel broadcast +@MainActor @Suite("BinaryOpGenerator multi-channel broadcast") struct BinaryOpGeneratorMultiChannelTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -323,6 +325,7 @@ struct BinaryOpGeneratorMultiChannelTests { // MARK: - Existential operator overloads (any ValidGeneratorInput op any ValidGeneratorInput) +@MainActor @Suite("BinaryOpGenerator existential operators") struct BinaryOpGeneratorExistentialTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -421,6 +424,7 @@ struct BinaryOpGeneratorExistentialTests { // MARK: - ConstantGeneratorInput +@MainActor @Suite("ConstantGeneratorInput") struct ConstantGeneratorInputTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) diff --git a/Tests/LyrebirdTests/BowedStringTests.swift b/Tests/LyrebirdTests/BowedStringTests.swift index db00e25..cdfb558 100644 --- a/Tests/LyrebirdTests/BowedStringTests.swift +++ b/Tests/LyrebirdTests/BowedStringTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("BowedString") struct BowedStringTests { diff --git a/Tests/LyrebirdTests/BufferReadTests.swift b/Tests/LyrebirdTests/BufferReadTests.swift index 95dcedd..0991c21 100644 --- a/Tests/LyrebirdTests/BufferReadTests.swift +++ b/Tests/LyrebirdTests/BufferReadTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("BufferRead") struct BufferReadTests { diff --git a/Tests/LyrebirdTests/BufferSlotAdoptionTests.swift b/Tests/LyrebirdTests/BufferSlotAdoptionTests.swift index 74f1735..aee2c12 100644 --- a/Tests/LyrebirdTests/BufferSlotAdoptionTests.swift +++ b/Tests/LyrebirdTests/BufferSlotAdoptionTests.swift @@ -11,6 +11,7 @@ import Testing /// Per-generator tests verify (1) swap takes effect on the next block, (2) swap to nil /// silences output, (3) the previously installed buffer is released after the engine's /// freeQueue drains. +@MainActor @Suite("BufferSlot adoption — Phase C") struct BufferSlotAdoptionTests { diff --git a/Tests/LyrebirdTests/Buffers/HRIRFileTests.swift b/Tests/LyrebirdTests/Buffers/HRIRFileTests.swift index cc68a40..6629487 100644 --- a/Tests/LyrebirdTests/Buffers/HRIRFileTests.swift +++ b/Tests/LyrebirdTests/Buffers/HRIRFileTests.swift @@ -69,6 +69,7 @@ private func makeMinimalLBHR( // MARK: - Suite +@MainActor @Suite("HRIRFile") struct HRIRFileTests { diff --git a/Tests/LyrebirdTests/BusAllocatorTests.swift b/Tests/LyrebirdTests/BusAllocatorTests.swift index 5688e2f..0ccd190 100644 --- a/Tests/LyrebirdTests/BusAllocatorTests.swift +++ b/Tests/LyrebirdTests/BusAllocatorTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("BusAllocator") struct BusAllocatorTests { diff --git a/Tests/LyrebirdTests/BusErgonomicsTests.swift b/Tests/LyrebirdTests/BusErgonomicsTests.swift index c914163..478415a 100644 --- a/Tests/LyrebirdTests/BusErgonomicsTests.swift +++ b/Tests/LyrebirdTests/BusErgonomicsTests.swift @@ -81,6 +81,7 @@ private final class ControlInputRoutingSynth: SynthesizerBase { // MARK: - Tests +@MainActor @Suite("Bus Ergonomics — SynthesizerBase convenience helpers") struct BusErgonomicsTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 16) diff --git a/Tests/LyrebirdTests/ButterworthFilterTests.swift b/Tests/LyrebirdTests/ButterworthFilterTests.swift index 8be59c2..3490174 100644 --- a/Tests/LyrebirdTests/ButterworthFilterTests.swift +++ b/Tests/LyrebirdTests/ButterworthFilterTests.swift @@ -29,6 +29,7 @@ private func rms(_ samples: [Double]) -> Double { // MARK: - ButterworthFilterTests +@MainActor @Suite("ButterworthFilters") struct ButterworthFilterTests { @@ -292,6 +293,7 @@ struct ButterworthFilterTests { // MARK: - ButterworthBandPassTests +@MainActor @Suite("ButterworthBandPass") struct ButterworthBandPassTests { @@ -438,6 +440,7 @@ struct ButterworthBandPassTests { // MARK: - ButterworthBandRejectTests +@MainActor @Suite("ButterworthBandReject") struct ButterworthBandRejectTests { diff --git a/Tests/LyrebirdTests/CPUStatsTests.swift b/Tests/LyrebirdTests/CPUStatsTests.swift index 2ed3c48..6262631 100644 --- a/Tests/LyrebirdTests/CPUStatsTests.swift +++ b/Tests/LyrebirdTests/CPUStatsTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("CPU Statistics") final class CPUStatsTests { @@ -17,7 +18,7 @@ final class CPUStatsTests { try engine.start() } - deinit { + isolated deinit { engine.stop() } diff --git a/Tests/LyrebirdTests/ChannelSelectTests.swift b/Tests/LyrebirdTests/ChannelSelectTests.swift index 6912cca..8399bed 100644 --- a/Tests/LyrebirdTests/ChannelSelectTests.swift +++ b/Tests/LyrebirdTests/ChannelSelectTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ChannelSelect") struct ChannelSelectTests { diff --git a/Tests/LyrebirdTests/ChorusTests.swift b/Tests/LyrebirdTests/ChorusTests.swift index 61c0af9..1e5996d 100644 --- a/Tests/LyrebirdTests/ChorusTests.swift +++ b/Tests/LyrebirdTests/ChorusTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Chorus") struct ChorusTests { diff --git a/Tests/LyrebirdTests/ClarinetTests.swift b/Tests/LyrebirdTests/ClarinetTests.swift index 3a33d7b..5096285 100644 --- a/Tests/LyrebirdTests/ClarinetTests.swift +++ b/Tests/LyrebirdTests/ClarinetTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Clarinet") struct ClarinetTests { diff --git a/Tests/LyrebirdTests/CollectionRandomPickTests.swift b/Tests/LyrebirdTests/CollectionRandomPickTests.swift index 87b5b34..d6e2699 100644 --- a/Tests/LyrebirdTests/CollectionRandomPickTests.swift +++ b/Tests/LyrebirdTests/CollectionRandomPickTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("CollectionRandomPick") struct CollectionRandomPickTests { diff --git a/Tests/LyrebirdTests/CompressorParameterRampingTests.swift b/Tests/LyrebirdTests/CompressorParameterRampingTests.swift index 755f19f..5238cc8 100644 --- a/Tests/LyrebirdTests/CompressorParameterRampingTests.swift +++ b/Tests/LyrebirdTests/CompressorParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Compressor parameter ramping") struct CompressorParameterRampingTests { diff --git a/Tests/LyrebirdTests/Concurrency/Phase201IsolationGuardTests.swift b/Tests/LyrebirdTests/Concurrency/Phase201IsolationGuardTests.swift new file mode 100644 index 0000000..a919b34 --- /dev/null +++ b/Tests/LyrebirdTests/Concurrency/Phase201IsolationGuardTests.swift @@ -0,0 +1,175 @@ +// Phase201IsolationGuardTests.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Testing +import Foundation +@testable import LyrebirdSynth + +/// Phase 201/202 isolation guards. +/// +/// These tests protect the main-actor isolation model against silent regression: +/// +/// 1. **Off-main bridge** — `lyrebirdRunMainActorMutation` must run a `@MainActor` +/// mutation correctly when invoked from a background thread (synchronous hop to +/// main), without trapping. This path is exercised in production by the NRT inline +/// dispatcher (`LyrebirdMessageContext(nrtEngine:)`) and by AUv3 off-main hosts. The +/// rest of the suite runs `@MainActor` (node-tree mutation is a main-thread API), so +/// these specific tests are deliberately **nonisolated** to drive the off-main path. +/// +/// 2. **RT-layer purity** — Generator hot-path sources must never reference actor-hop +/// machinery (`MainActor`, `assumeIsolated`, `DispatchQueue`, `Task {`). Under the +/// Swift 6 language mode such a call would compile silently but violate the +/// `nonisolated` RT render contract. This is a source-text lint. +@Suite("Phase 201/202 isolation guards") +struct Phase201IsolationGuardTests { + + // MARK: - Guard A: off-main bridge + + /// The bridge runs inline when already on the main thread. + @Test @MainActor func bridgeRunsInlineOnMain() { + var ran: Bool = false + lyrebirdRunMainActorMutation { ran = true } + #expect(ran) + } + + /// The bridge hops synchronously to main when called off-main — it must NOT trap + /// (the regression that bare `MainActor.assumeIsolated` would have caused on the + /// NRT inline / off-main AU-host paths). + @Test func bridgeHopsFromBackgroundThreadWithoutTrapping() async { + let done: DispatchSemaphore = DispatchSemaphore(value: 0) + let ran: LockedBool = LockedBool() + // Dispatch onto a background queue so the bridge takes its `main.sync` branch. + DispatchQueue.global(qos: .userInitiated).async { + #expect(!Thread.isMainThread) + lyrebirdRunMainActorMutation { + // Body runs on the main actor. + #expect(Thread.isMainThread) + ran.set(true) + } + done.signal() + } + // Wait off the main thread (this test is nonisolated) so main is free to service + // the bridge's synchronous hop. + await withCheckedContinuation { (continuation: CheckedContinuation) in + DispatchQueue.global().async { + _ = done.wait(timeout: .now() + 5) + continuation.resume() + } + } + #expect(ran.get()) + } + + /// End-to-end: the NRT inline `LyrebirdMessageContext` dispatcher invoked from a + /// background thread routes `ctx.add` through the bridge and the synth's `build()` + /// runs (on main) — proving the off-main NRT add path does not trap. + @Test func nrtInlineContextAddFromBackgroundThreadBuildsSynth() async { + // No `engine.start()` here on purpose: `build()` runs at add time (in `prepareNode`), + // before any render. Starting an NRT render would mark this pooled thread RT via + // `RTThreadIdentity`; that marker persists and could false-trip + // `_lyrebirdAssertNotOnRTThread` in a later `.compute()` test reusing the thread. + let engine: SynthesisEngine = makeTestEngine(blockSize: 8, numAudioBuses: 4) + let builtCount: LockedInt = LockedInt() + final class ProbeSynth: SynthesizerBase, @unchecked Sendable { + let onBuild: @Sendable () -> Void + init(onBuild: @escaping @Sendable () -> Void) { self.onBuild = onBuild; super.init() } + override func build() { onBuild() } + } + let ctx: LyrebirdMessageContext = LyrebirdMessageContext(nrtEngine: engine) + // Synth construction is `@MainActor` (Phase 201); build it on main, then add from + // a background thread to exercise the off-main bridge hop. + let synth: ProbeSynth = await MainActor.run { ProbeSynth { builtCount.increment() } } + let done: DispatchSemaphore = DispatchSemaphore(value: 0) + DispatchQueue.global(qos: .userInitiated).async { + ctx.add(synth) // inline dispatcher → lyrebirdRunMainActorMutation off-main → main hop + done.signal() + } + await withCheckedContinuation { (continuation: CheckedContinuation) in + DispatchQueue.global().async { + _ = done.wait(timeout: .now() + 5) + continuation.resume() + } + } + #expect(builtCount.get() == 1) + } + + // MARK: - Guard B: RT-layer source purity + + /// RT-DSP sources must not reference actor-isolation machinery. Under Swift 6 language + /// mode an `@MainActor` / `assumeIsolated` call inside an RT-path source compiles + /// silently but breaks the `nonisolated` RT render contract — this lint fails the build + /// before that can ship. + /// + /// Scope: the pure RT-DSP directories — `Generators/` (concrete units), `GeneratorCore/` + /// (the Generator protocol layer + `MulAdd` + hot-loop helpers), `Oversampling/`, + /// `Spectral/`, and `Math/`. `Engine/` and `NodeTree/` are intentionally NOT scanned: + /// they legitimately host the language-side `@MainActor` surface (`SynthesizerBase`, + /// the `MainActorMutationBridge`) whose `evaluate`/render entry points are separately + /// `nonisolated`. + /// + /// Only `MainActor` / `assumeIsolated` are banned — pure actor-isolation hooks with no + /// legitimate place in an RT-DSP unit. `DispatchQueue` / `Task` are intentionally NOT + /// banned: buffer generators (`DiskIn` / `DiskOut`) use a background queue for off-RT + /// disk I/O (the RT side only touches a lock-free ring buffer). + @Test func generatorSourcesContainNoActorHopMachinery() throws { + let rtDspDirs: [String] = [ + "Sources/Lyrebird/Generators", + "Sources/Lyrebird/GeneratorCore", + "Sources/Lyrebird/Oversampling", + "Sources/Lyrebird/Spectral", + "Sources/Lyrebird/Math", + ] + let forbidden: [String] = [ + "MainActor", + "assumeIsolated", + ] + let fm: FileManager = FileManager.default + var violations: [String] = [] + for dir: String in rtDspDirs { + let root: URL = Self.repoRoot.appendingPathComponent(dir, isDirectory: true) + guard let enumerator: FileManager.DirectoryEnumerator = + fm.enumerator(at: root, includingPropertiesForKeys: nil) else { + Issue.record("Could not enumerate \(root.path)") + continue + } + for case let url as URL in enumerator where url.pathExtension == "swift" { + let text: String = (try? String(contentsOf: url, encoding: .utf8)) ?? "" + for token: String in forbidden where text.contains(token) { + violations.append("\(dir)/\(url.lastPathComponent): contains '\(token)'") + } + } + } + #expect( + violations.isEmpty, + "RT-DSP sources must not use actor-hop machinery (breaks the nonisolated RT contract): \(violations)" + ) + } + + /// Repo root, derived from this file's path: + /// `/Tests/LyrebirdTests/Concurrency/Phase201IsolationGuardTests.swift`. + private static var repoRoot: URL { + URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() // Concurrency/ + .deletingLastPathComponent() // LyrebirdTests/ + .deletingLastPathComponent() // Tests/ + .deletingLastPathComponent() // + } +} + +// MARK: - Tiny thread-safe test helpers + +private final class LockedBool: @unchecked Sendable { + private let lock: NSLock = NSLock() + private var value: Bool = false + func set(_ v: Bool) { lock.lock(); value = v; lock.unlock() } + func get() -> Bool { lock.lock(); defer { lock.unlock() }; return value } +} + +private final class LockedInt: @unchecked Sendable { + private let lock: NSLock = NSLock() + private var value: Int = 0 + func increment() { lock.lock(); value += 1; lock.unlock() } + func get() -> Int { lock.lock(); defer { lock.unlock() }; return value } +} diff --git a/Tests/LyrebirdTests/ControlGeneratorTests.swift b/Tests/LyrebirdTests/ControlGeneratorTests.swift index 344e98a..11f9d26 100644 --- a/Tests/LyrebirdTests/ControlGeneratorTests.swift +++ b/Tests/LyrebirdTests/ControlGeneratorTests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - OscSin.Control Tests +@MainActor @Suite("OscSin.Control") struct OscSinControlTests { let blockSize: Int = 64 @@ -134,6 +135,7 @@ struct OscSinControlTests { // MARK: - OscTableControl Tests +@MainActor @Suite("OscTableControl") struct OscTableControlTests { let blockSize: Int = 64 @@ -217,6 +219,7 @@ struct OscTableControlTests { // MARK: - ImpulseControl Tests +@MainActor @Suite("ImpulseControl") struct ImpulseControlTests { // Use blockSize == sampleRate so 1 Hz fires exactly once per block. @@ -332,6 +335,7 @@ struct ImpulseControlTests { // MARK: - WhiteNoiseControl Tests +@MainActor @Suite("WhiteNoiseControl") struct WhiteNoiseControlTests { let blockSize: Int = 64 @@ -406,6 +410,7 @@ struct WhiteNoiseControlTests { // MARK: - LFStepNoiseControl Tests +@MainActor @Suite("LFStepNoiseControl") struct LFStepNoiseControlTests { // blockSize == sampleRate so 1 Hz fires exactly once per block. @@ -522,6 +527,7 @@ struct LFStepNoiseControlTests { // MARK: - LFLineNoiseControl Tests +@MainActor @Suite("LFLineNoiseControl") struct LFLineNoiseControlTests { let blockSize: Int = 100 @@ -648,6 +654,7 @@ private final class CountingControl: GeneratorBase, ControlGenerator { // MARK: - Sub-block control tests +@MainActor @Suite("ControlGenerator sub-block") struct ControlGeneratorSubBlockTests { @@ -826,6 +833,7 @@ struct ControlGeneratorSubBlockTests { // MARK: - PinkNoiseControl Tests +@MainActor @Suite("PinkNoiseControl") struct PinkNoiseControlTests { let blockSize: Int = 64 @@ -901,6 +909,7 @@ struct PinkNoiseControlTests { // MARK: - BrownNoiseControl Tests +@MainActor @Suite("BrownNoiseControl") struct BrownNoiseControlTests { let blockSize: Int = 64 @@ -975,6 +984,7 @@ struct BrownNoiseControlTests { // MARK: - GrayNoiseControl Tests +@MainActor @Suite("GrayNoiseControl") struct GrayNoiseControlTests { let blockSize: Int = 64 @@ -1049,6 +1059,7 @@ struct GrayNoiseControlTests { // MARK: - ClipNoiseControl Tests +@MainActor @Suite("ClipNoiseControl") struct ClipNoiseControlTests { let blockSize: Int = 64 @@ -1124,6 +1135,7 @@ struct ClipNoiseControlTests { // MARK: - DustControl Tests +@MainActor @Suite("DustControl") struct DustControlTests { let blockSize: Int = 64 @@ -1200,6 +1212,7 @@ struct DustControlTests { // MARK: - Dust2Control Tests +@MainActor @Suite("Dust2Control") struct Dust2ControlTests { let blockSize: Int = 64 @@ -1276,6 +1289,7 @@ struct Dust2ControlTests { // MARK: - CrackleControl Tests +@MainActor @Suite("CrackleControl") struct CrackleControlTests { let blockSize: Int = 64 @@ -1356,6 +1370,7 @@ struct CrackleControlTests { // MARK: - LFCurveNoiseControl Tests +@MainActor @Suite("LFCurveNoiseControl") struct LFCurveNoiseControlTests { let blockSize: Int = 100 diff --git a/Tests/LyrebirdTests/ConvolutionReverbTests.swift b/Tests/LyrebirdTests/ConvolutionReverbTests.swift index 8685dbc..6baedb5 100644 --- a/Tests/LyrebirdTests/ConvolutionReverbTests.swift +++ b/Tests/LyrebirdTests/ConvolutionReverbTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ConvolutionReverb.Audio — partitioned overlap-save FFT convolution") struct ConvolutionReverbTests { diff --git a/Tests/LyrebirdTests/CoreAudioDriverTests.swift b/Tests/LyrebirdTests/CoreAudioDriverTests.swift index 334a232..d7dd6cd 100644 --- a/Tests/LyrebirdTests/CoreAudioDriverTests.swift +++ b/Tests/LyrebirdTests/CoreAudioDriverTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - CoreAudioDriverOptions defaults +@MainActor @Suite("CoreAudioDriverOptions") struct CoreAudioDriverOptionsTests { @Test func defaultMatchDeviceSampleRateIsFalse() { let opts: CoreAudioDriverOptions = CoreAudioDriverOptions() @@ -23,6 +24,7 @@ import Testing // MARK: - Sample rate validation (offline, no hardware required) +@MainActor @Suite("CoreAudioDriver sample rate validation") struct CoreAudioSampleRateValidationTests { @Test func doesNotThrowWhenRatesMatch() throws { let opts: CoreAudioDriverOptions = CoreAudioDriverOptions() @@ -73,6 +75,7 @@ import Testing // MARK: - deviceSampleRate property +@MainActor @Suite("CoreAudioDriver deviceSampleRate") struct CoreAudioDeviceSampleRateTests { @Test func deviceSampleRateNilBeforeSetup() { let driver: CoreAudioDriver = CoreAudioDriver() @@ -82,6 +85,7 @@ import Testing // MARK: - Lifecycle (no hardware required) +@MainActor @Suite("CoreAudioDriver lifecycle") struct CoreAudioDriverLifecycleTests { @Test func stopBeforeSetupIsNoop() { let driver: CoreAudioDriver = CoreAudioDriver() diff --git a/Tests/LyrebirdTests/Decay2Tests.swift b/Tests/LyrebirdTests/Decay2Tests.swift index 3f84da9..95d5bdc 100644 --- a/Tests/LyrebirdTests/Decay2Tests.swift +++ b/Tests/LyrebirdTests/Decay2Tests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Decay2") struct Decay2Tests { diff --git a/Tests/LyrebirdTests/DecayTests.swift b/Tests/LyrebirdTests/DecayTests.swift index d4d11de..badee56 100644 --- a/Tests/LyrebirdTests/DecayTests.swift +++ b/Tests/LyrebirdTests/DecayTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Decay") struct DecayTests { diff --git a/Tests/LyrebirdTests/DelayLineFeedbackParameterRampingTests.swift b/Tests/LyrebirdTests/DelayLineFeedbackParameterRampingTests.swift index d363eae..f8ad47d 100644 --- a/Tests/LyrebirdTests/DelayLineFeedbackParameterRampingTests.swift +++ b/Tests/LyrebirdTests/DelayLineFeedbackParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DelayLineFeedback parameter ramping") struct DelayLineFeedbackParameterRampingTests { diff --git a/Tests/LyrebirdTests/DemandBrownianTests.swift b/Tests/LyrebirdTests/DemandBrownianTests.swift index 226b71b..071809b 100644 --- a/Tests/LyrebirdTests/DemandBrownianTests.swift +++ b/Tests/LyrebirdTests/DemandBrownianTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandBrownian") struct DemandBrownianTests { diff --git a/Tests/LyrebirdTests/DemandConcatenateTests.swift b/Tests/LyrebirdTests/DemandConcatenateTests.swift index 298a587..8deaa2e 100644 --- a/Tests/LyrebirdTests/DemandConcatenateTests.swift +++ b/Tests/LyrebirdTests/DemandConcatenateTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandConcatenate") struct DemandConcatenateTests { diff --git a/Tests/LyrebirdTests/DemandGeneratorTests.swift b/Tests/LyrebirdTests/DemandGeneratorTests.swift index b109783..e46be19 100644 --- a/Tests/LyrebirdTests/DemandGeneratorTests.swift +++ b/Tests/LyrebirdTests/DemandGeneratorTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - DemandSequence +@MainActor @Suite("DemandSequence") struct DSequenceTests { @@ -65,6 +66,7 @@ struct DSequenceTests { // MARK: - DemandRandom +@MainActor @Suite("DemandRandom") struct DRandomTests { @@ -115,6 +117,7 @@ struct DRandomTests { // MARK: - Demand.Audio +@MainActor @Suite("Demand.Audio") struct DemandAudioTests { @@ -235,6 +238,7 @@ struct DemandAudioTests { // MARK: - Demand.Control +@MainActor @Suite("Demand.Control") struct DemandControlTests { diff --git a/Tests/LyrebirdTests/DemandGeometricTests.swift b/Tests/LyrebirdTests/DemandGeometricTests.swift index 1c3d252..4b9019b 100644 --- a/Tests/LyrebirdTests/DemandGeometricTests.swift +++ b/Tests/LyrebirdTests/DemandGeometricTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandGeometric") struct DemandGeometricTests { diff --git a/Tests/LyrebirdTests/DemandNonRepeatingRandomTests.swift b/Tests/LyrebirdTests/DemandNonRepeatingRandomTests.swift index e3a5e92..e91956b 100644 --- a/Tests/LyrebirdTests/DemandNonRepeatingRandomTests.swift +++ b/Tests/LyrebirdTests/DemandNonRepeatingRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandNonRepeatingRandom") struct DemandNonRepeatingRandomTests { diff --git a/Tests/LyrebirdTests/DemandSeriesTests.swift b/Tests/LyrebirdTests/DemandSeriesTests.swift index 128edee..57f5f2c 100644 --- a/Tests/LyrebirdTests/DemandSeriesTests.swift +++ b/Tests/LyrebirdTests/DemandSeriesTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandSeries") struct DemandSeriesTests { diff --git a/Tests/LyrebirdTests/DemandShuffleTests.swift b/Tests/LyrebirdTests/DemandShuffleTests.swift index c153bd7..d0b82a3 100644 --- a/Tests/LyrebirdTests/DemandShuffleTests.swift +++ b/Tests/LyrebirdTests/DemandShuffleTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandShuffle") struct DemandShuffleTests { diff --git a/Tests/LyrebirdTests/DemandStutterTests.swift b/Tests/LyrebirdTests/DemandStutterTests.swift index c578566..cc1b955 100644 --- a/Tests/LyrebirdTests/DemandStutterTests.swift +++ b/Tests/LyrebirdTests/DemandStutterTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandStutter") struct DemandStutterTests { diff --git a/Tests/LyrebirdTests/DemandSwitchTests.swift b/Tests/LyrebirdTests/DemandSwitchTests.swift index 7eb150d..9e993b9 100644 --- a/Tests/LyrebirdTests/DemandSwitchTests.swift +++ b/Tests/LyrebirdTests/DemandSwitchTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandSwitch") struct DemandSwitchTests { diff --git a/Tests/LyrebirdTests/DemandUniformRandomTests.swift b/Tests/LyrebirdTests/DemandUniformRandomTests.swift index 5d0c39f..32c2c20 100644 --- a/Tests/LyrebirdTests/DemandUniformRandomTests.swift +++ b/Tests/LyrebirdTests/DemandUniformRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandUniformRandom") struct DemandUniformRandomTests { diff --git a/Tests/LyrebirdTests/DemandWeightedRandomTests.swift b/Tests/LyrebirdTests/DemandWeightedRandomTests.swift index d4c0b5f..a062bbf 100644 --- a/Tests/LyrebirdTests/DemandWeightedRandomTests.swift +++ b/Tests/LyrebirdTests/DemandWeightedRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("DemandWeightedRandom") struct DemandWeightedRandomTests { diff --git a/Tests/LyrebirdTests/DenormalHandlingTests.swift b/Tests/LyrebirdTests/DenormalHandlingTests.swift index 46f2765..0230276 100644 --- a/Tests/LyrebirdTests/DenormalHandlingTests.swift +++ b/Tests/LyrebirdTests/DenormalHandlingTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - denormalsToZero helper +@MainActor @Suite("denormalsToZero") struct DenormalsToZeroTests { @@ -57,6 +58,7 @@ struct DenormalsToZeroTests { // any computation that would produce a subnormal result is flushed to zero by the // hardware, so filter outputs and delay-line writes must never be subnormal. +@MainActor @Suite("FirstOrderSection — no subnormals under FTZ") struct FirstOrderSectionFTZTests { @@ -87,6 +89,7 @@ struct FirstOrderSectionFTZTests { } } +@MainActor @Suite("SecondOrderSection — no subnormals under FTZ") struct SecondOrderSectionFTZTests { @@ -115,6 +118,7 @@ struct SecondOrderSectionFTZTests { } } +@MainActor @Suite("RBJBandPass — no subnormals under FTZ") struct RBJBandPassFTZTests { @@ -141,6 +145,7 @@ struct RBJBandPassFTZTests { } } +@MainActor @Suite("DelayLineFeedback — no subnormals under FTZ") struct DelayLineFeedbackFTZTests { diff --git a/Tests/LyrebirdTests/Diagnostics/LyrebirdMessageCenterTests.swift b/Tests/LyrebirdTests/Diagnostics/LyrebirdMessageCenterTests.swift index c6a38de..cf698e6 100644 --- a/Tests/LyrebirdTests/Diagnostics/LyrebirdMessageCenterTests.swift +++ b/Tests/LyrebirdTests/Diagnostics/LyrebirdMessageCenterTests.swift @@ -8,8 +8,8 @@ import Testing import Foundation @testable import LyrebirdSynth -@Suite("LyrebirdMessageCenter") @MainActor +@Suite("LyrebirdMessageCenter") struct LyrebirdMessageCenterTests { @Test("post stores message at the given tier") diff --git a/Tests/LyrebirdTests/DiskInOutTests.swift b/Tests/LyrebirdTests/DiskInOutTests.swift index 5f7c84a..237580c 100644 --- a/Tests/LyrebirdTests/DiskInOutTests.swift +++ b/Tests/LyrebirdTests/DiskInOutTests.swift @@ -122,6 +122,7 @@ private func makeNRTEngine(outputURL: URL, duration: Double, // MARK: - Tests +@MainActor @Suite("DiskIn / DiskOut") struct DiskInOutTests { diff --git a/Tests/LyrebirdTests/DynamicsTests.swift b/Tests/LyrebirdTests/DynamicsTests.swift index 6efb2bb..a91c545 100644 --- a/Tests/LyrebirdTests/DynamicsTests.swift +++ b/Tests/LyrebirdTests/DynamicsTests.swift @@ -38,6 +38,7 @@ private func collect2ch( // MARK: - AmplitudeFollower Tests +@MainActor @Suite("AmplitudeFollower") struct AmplitudeFollowerTests { @@ -185,6 +186,7 @@ struct AmplitudeFollowerTests { // MARK: - FreqTracker Tests +@MainActor @Suite("FreqTracker") struct FreqTrackerTests { @@ -287,6 +289,7 @@ struct FreqTrackerTests { // MARK: - LookAheadLimiter Tests +@MainActor @Suite("LookAheadLimiter") struct LookAheadLimiterTests { @@ -432,6 +435,7 @@ struct LookAheadLimiterTests { // MARK: - Compressor Tests +@MainActor @Suite("Compressor") struct CompressorTests { @@ -570,6 +574,7 @@ struct CompressorTests { // MARK: - Expander Tests +@MainActor @Suite("Expander") struct ExpanderTests { diff --git a/Tests/LyrebirdTests/EngineHostTests.swift b/Tests/LyrebirdTests/EngineHostTests.swift index b0555ac..460832b 100644 --- a/Tests/LyrebirdTests/EngineHostTests.swift +++ b/Tests/LyrebirdTests/EngineHostTests.swift @@ -8,7 +8,29 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +/// NRT `build`-closure shim (Phase 201). +/// +/// `NRTJob.build` is a non-isolated `@Sendable (SynthesisEngine) throws -> Void` +/// that `EngineHost._executeJob` runs on a background task — *not* the main actor. +/// `SynthesisEngine.add(_:)` is `@MainActor` (Phase 201), so it cannot be invoked +/// directly from inside the off-main build closure. The build closure runs *before* +/// `engine.start()`, so the engine is not yet rendering and nothing else touches it +/// concurrently; hopping the add onto the main actor synchronously is therefore safe +/// in this narrow window. The `nonisolated(unsafe)` captures move the non-`Sendable` +/// engine/synth across the hop — sound because of that exclusivity. +private func nrtBuildAdd(_ engine: SynthesisEngine, _ makeSynth: @escaping @MainActor () -> any Synthesizer) throws { + nonisolated(unsafe) let e: SynthesisEngine = engine + var thrown: (any Error)? = nil + DispatchQueue.main.sync { + MainActor.assumeIsolated { + do { try e.add(makeSynth()) } catch { thrown = error } + } + } + if let thrown: any Error = thrown { throw thrown } +} + /// Phase 197 — `EngineHost` facade coverage. +@MainActor @Suite("EngineHost (Phase 197)") struct EngineHostTests { @@ -240,7 +262,7 @@ struct EngineHostTests { sampleRate: 44100, numOutputChannels: 2 ) { engine in - try engine.add(ConstSynth(value: 0.1 * Double(i + 1))) + try nrtBuildAdd(engine) { ConstSynth(value: 0.1 * Double(i + 1)) } } } @@ -279,7 +301,7 @@ struct EngineHostTests { sampleRate: 44100, numOutputChannels: 2 ) { engine in - try engine.add(ConstSynth(value: 0.1)) + try nrtBuildAdd(engine) { ConstSynth(value: 0.1) } }, NRTJob( outputURL: dir.appendingPathComponent("fail.caf"), @@ -359,7 +381,7 @@ struct EngineHostTests { sampleRate: 44100, numOutputChannels: 2 ) { engine in - try engine.add(ConstSynth(value: 0.1)) + try nrtBuildAdd(engine) { ConstSynth(value: 0.1) } } } @@ -397,7 +419,7 @@ struct EngineHostTests { sampleRate: 44100, numOutputChannels: 2 ) { engine in - try engine.add(ConstSynth(value: 0.1)) + try nrtBuildAdd(engine) { ConstSynth(value: 0.1) } } ] var count: Int = 0 diff --git a/Tests/LyrebirdTests/EngineMainGroupTests.swift b/Tests/LyrebirdTests/EngineMainGroupTests.swift index 244d238..e33f3ef 100644 --- a/Tests/LyrebirdTests/EngineMainGroupTests.swift +++ b/Tests/LyrebirdTests/EngineMainGroupTests.swift @@ -38,6 +38,7 @@ private final class ControlBusStamper: Synthesizer { // MARK: - +@MainActor @Suite("EngineMainGroup") struct EngineMainGroupTests { diff --git a/Tests/LyrebirdTests/EngineNodeCountTests.swift b/Tests/LyrebirdTests/EngineNodeCountTests.swift index bcde5f0..227bb1b 100644 --- a/Tests/LyrebirdTests/EngineNodeCountTests.swift +++ b/Tests/LyrebirdTests/EngineNodeCountTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Engine node counts") struct EngineNodeCountTests { diff --git a/Tests/LyrebirdTests/Envelopes/AutoFreeOnDoneTests.swift b/Tests/LyrebirdTests/Envelopes/AutoFreeOnDoneTests.swift index 86b2666..477506c 100644 --- a/Tests/LyrebirdTests/Envelopes/AutoFreeOnDoneTests.swift +++ b/Tests/LyrebirdTests/Envelopes/AutoFreeOnDoneTests.swift @@ -10,6 +10,7 @@ import AudioToolbox import Synchronization @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SynthesizerBase autoFreeOnDone") struct AutoFreeOnDoneTests { diff --git a/Tests/LyrebirdTests/Envelopes/EnvelopeTimeScaleVerificationTests.swift b/Tests/LyrebirdTests/Envelopes/EnvelopeTimeScaleVerificationTests.swift index 983c931..c662ca4 100644 --- a/Tests/LyrebirdTests/Envelopes/EnvelopeTimeScaleVerificationTests.swift +++ b/Tests/LyrebirdTests/Envelopes/EnvelopeTimeScaleVerificationTests.swift @@ -11,6 +11,7 @@ import Foundation /// One-off verification of `EnvelopeGen.{Audio,Control}` timeScale behavior /// — reproduces the MyPiece scenario: envelope durations [0.2, 0.6, 0.2] /// (sum 1.0), timeScale 8.0 → expected total 8 seconds. +@MainActor @Suite("EnvelopeGen timeScale verification") struct EnvelopeTimeScaleVerificationTests { diff --git a/Tests/LyrebirdTests/EuclideanRhythmTests.swift b/Tests/LyrebirdTests/EuclideanRhythmTests.swift index e1c5573..07b0f10 100644 --- a/Tests/LyrebirdTests/EuclideanRhythmTests.swift +++ b/Tests/LyrebirdTests/EuclideanRhythmTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("EuclideanRhythm") struct EuclideanRhythmTests { diff --git a/Tests/LyrebirdTests/ExpanderParameterRampingTests.swift b/Tests/LyrebirdTests/ExpanderParameterRampingTests.swift index fe0cbec..6543c22 100644 --- a/Tests/LyrebirdTests/ExpanderParameterRampingTests.swift +++ b/Tests/LyrebirdTests/ExpanderParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Expander parameter ramping") struct ExpanderParameterRampingTests { diff --git a/Tests/LyrebirdTests/ExponentialLineTests.swift b/Tests/LyrebirdTests/ExponentialLineTests.swift index ce7f684..f68ee97 100644 --- a/Tests/LyrebirdTests/ExponentialLineTests.swift +++ b/Tests/LyrebirdTests/ExponentialLineTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ExponentialLine") struct ExponentialLineTests { diff --git a/Tests/LyrebirdTests/FFTTests.swift b/Tests/LyrebirdTests/FFTTests.swift index 403b7af..7faf247 100644 --- a/Tests/LyrebirdTests/FFTTests.swift +++ b/Tests/LyrebirdTests/FFTTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("FFT Infrastructure") struct FFTTests { diff --git a/Tests/LyrebirdTests/FanOutCachingTests.swift b/Tests/LyrebirdTests/FanOutCachingTests.swift index d3efe30..64ce2c6 100644 --- a/Tests/LyrebirdTests/FanOutCachingTests.swift +++ b/Tests/LyrebirdTests/FanOutCachingTests.swift @@ -13,6 +13,7 @@ import Testing /// generators within the same engine segment (same `segmentSerial`), its `_computeSamples` /// is invoked exactly once and the cached result is shared. This prevents the "double phase /// advance" artefact that one oscillator feeding two `Out` generators would otherwise produce. +@MainActor @Suite("Fan-out caching") struct FanOutCachingTests { diff --git a/Tests/LyrebirdTests/FlangerTests.swift b/Tests/LyrebirdTests/FlangerTests.swift index 5d3e70a..efc9daa 100644 --- a/Tests/LyrebirdTests/FlangerTests.swift +++ b/Tests/LyrebirdTests/FlangerTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Flanger") struct FlangerTests { diff --git a/Tests/LyrebirdTests/FluteTests.swift b/Tests/LyrebirdTests/FluteTests.swift index 327a28a..e703f82 100644 --- a/Tests/LyrebirdTests/FluteTests.swift +++ b/Tests/LyrebirdTests/FluteTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Flute") struct FluteTests { diff --git a/Tests/LyrebirdTests/FormantGrainTests.swift b/Tests/LyrebirdTests/FormantGrainTests.swift index cda3d73..f821d13 100644 --- a/Tests/LyrebirdTests/FormantGrainTests.swift +++ b/Tests/LyrebirdTests/FormantGrainTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("FormantGrain") struct FormantGrainTests { diff --git a/Tests/LyrebirdTests/FractionTests.swift b/Tests/LyrebirdTests/FractionTests.swift index e01ce60..23241c2 100644 --- a/Tests/LyrebirdTests/FractionTests.swift +++ b/Tests/LyrebirdTests/FractionTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Fraction — exact rational arithmetic for Score") struct FractionTests { diff --git a/Tests/LyrebirdTests/FreeVerbTests.swift b/Tests/LyrebirdTests/FreeVerbTests.swift index fd287da..40433c2 100644 --- a/Tests/LyrebirdTests/FreeVerbTests.swift +++ b/Tests/LyrebirdTests/FreeVerbTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("FreeVerb — stereo reverb") struct FreeVerbTests { diff --git a/Tests/LyrebirdTests/FrequencyShifterTests.swift b/Tests/LyrebirdTests/FrequencyShifterTests.swift index 270e82f..2779466 100644 --- a/Tests/LyrebirdTests/FrequencyShifterTests.swift +++ b/Tests/LyrebirdTests/FrequencyShifterTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("FrequencyShifter") struct FrequencyShifterTests { diff --git a/Tests/LyrebirdTests/GVerbTests.swift b/Tests/LyrebirdTests/GVerbTests.swift index 53efd18..1bd86ac 100644 --- a/Tests/LyrebirdTests/GVerbTests.swift +++ b/Tests/LyrebirdTests/GVerbTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("GVerb — Griesinger algorithmic stereo reverb") struct GVerbTests { diff --git a/Tests/LyrebirdTests/GateTests.swift b/Tests/LyrebirdTests/GateTests.swift index a90e3a9..eaa4337 100644 --- a/Tests/LyrebirdTests/GateTests.swift +++ b/Tests/LyrebirdTests/GateTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Gate.Audio") struct GateAudioTests { @@ -88,6 +89,7 @@ struct GateAudioTests { } } +@MainActor @Suite("Gate.Control") struct GateControlTests { diff --git a/Tests/LyrebirdTests/GatedKarplusStrongTests.swift b/Tests/LyrebirdTests/GatedKarplusStrongTests.swift index 31c6302..89be662 100644 --- a/Tests/LyrebirdTests/GatedKarplusStrongTests.swift +++ b/Tests/LyrebirdTests/GatedKarplusStrongTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("GatedKarplusStrong") struct GatedKarplusStrongTests { diff --git a/Tests/LyrebirdTests/Gendy/Gendy1Tests.swift b/Tests/LyrebirdTests/Gendy/Gendy1Tests.swift index 46f5f0c..33e1842 100644 --- a/Tests/LyrebirdTests/Gendy/Gendy1Tests.swift +++ b/Tests/LyrebirdTests/Gendy/Gendy1Tests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Gendy1") struct Gendy1Tests { diff --git a/Tests/LyrebirdTests/Gendy/Gendy2Tests.swift b/Tests/LyrebirdTests/Gendy/Gendy2Tests.swift index d2034af..b3f9a64 100644 --- a/Tests/LyrebirdTests/Gendy/Gendy2Tests.swift +++ b/Tests/LyrebirdTests/Gendy/Gendy2Tests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Gendy2") struct Gendy2Tests { diff --git a/Tests/LyrebirdTests/Gendy/Gendy3Tests.swift b/Tests/LyrebirdTests/Gendy/Gendy3Tests.swift index 3f405ff..1616765 100644 --- a/Tests/LyrebirdTests/Gendy/Gendy3Tests.swift +++ b/Tests/LyrebirdTests/Gendy/Gendy3Tests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Gendy3") struct Gendy3Tests { diff --git a/Tests/LyrebirdTests/GeneratorArrayTests.swift b/Tests/LyrebirdTests/GeneratorArrayTests.swift index ae6dd63..476928f 100644 --- a/Tests/LyrebirdTests/GeneratorArrayTests.swift +++ b/Tests/LyrebirdTests/GeneratorArrayTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("GeneratorArray") struct GeneratorArrayTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) diff --git a/Tests/LyrebirdTests/GeneratorInputProviderTests.swift b/Tests/LyrebirdTests/GeneratorInputProviderTests.swift index aec7431..a28418f 100644 --- a/Tests/LyrebirdTests/GeneratorInputProviderTests.swift +++ b/Tests/LyrebirdTests/GeneratorInputProviderTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("GeneratorInputProvider") struct GeneratorInputProviderTests { diff --git a/Tests/LyrebirdTests/GeneratorProtocolTests.swift b/Tests/LyrebirdTests/GeneratorProtocolTests.swift index fba17c8..00ec841 100644 --- a/Tests/LyrebirdTests/GeneratorProtocolTests.swift +++ b/Tests/LyrebirdTests/GeneratorProtocolTests.swift @@ -47,6 +47,7 @@ final class MutableControlGen: GeneratorBase, ControlGenerator { func floatValue(graph: SynthGraph) -> Double { target } } +@MainActor @Suite("ProcessingRate") struct ProcessingRateTests { @Test func audioRateExists() { @@ -70,6 +71,7 @@ struct ProcessingRateTests { } } +@MainActor @Suite("Generator protocol") struct GeneratorProtocolTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) diff --git a/Tests/LyrebirdTests/GranularTests.swift b/Tests/LyrebirdTests/GranularTests.swift index 3e4fb4c..0f89229 100644 --- a/Tests/LyrebirdTests/GranularTests.swift +++ b/Tests/LyrebirdTests/GranularTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("BufferGrain") struct GranularTests { @@ -372,6 +373,7 @@ struct GranularTests { // MARK: - SineGrain +@MainActor @Suite("SineGrain") struct SineGrainTests { @@ -599,6 +601,7 @@ struct SineGrainTests { // MARK: - FMGrain +@MainActor @Suite("FMGrain") struct FMGrainTests { @@ -826,6 +829,7 @@ struct FMGrainTests { // MARK: - InputGrain +@MainActor @Suite("InputGrain") struct InputGrainTests { @@ -1051,6 +1055,7 @@ struct InputGrainTests { // MARK: - TimeStretch +@MainActor @Suite("TimeStretch") struct TimeStretchTests { diff --git a/Tests/LyrebirdTests/GroupSemanticsTests.swift b/Tests/LyrebirdTests/GroupSemanticsTests.swift index 49e9862..1285cee 100644 --- a/Tests/LyrebirdTests/GroupSemanticsTests.swift +++ b/Tests/LyrebirdTests/GroupSemanticsTests.swift @@ -32,6 +32,7 @@ final class NoGateSynth: Synthesizer { // MARK: - +@MainActor @Suite("Group Semantics") struct GroupSemanticsTests { diff --git a/Tests/LyrebirdTests/GroupTests.swift b/Tests/LyrebirdTests/GroupTests.swift index 0283388..6175c21 100644 --- a/Tests/LyrebirdTests/GroupTests.swift +++ b/Tests/LyrebirdTests/GroupTests.swift @@ -14,6 +14,7 @@ import Testing // Synthesizer values in PreparedNode(_:) at the call site — mirroring what // SynthesisEngine.schedule does on the main thread. +@MainActor @Suite("Group") struct GroupTests { diff --git a/Tests/LyrebirdTests/HalfbandDownsampler2xTests.swift b/Tests/LyrebirdTests/HalfbandDownsampler2xTests.swift index b4c8124..4ce8d9f 100644 --- a/Tests/LyrebirdTests/HalfbandDownsampler2xTests.swift +++ b/Tests/LyrebirdTests/HalfbandDownsampler2xTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("HalfbandDownsampler2x") struct HalfbandDownsampler2xTests { diff --git a/Tests/LyrebirdTests/HalfbandFIRTests.swift b/Tests/LyrebirdTests/HalfbandFIRTests.swift index f7c2763..99fd7a1 100644 --- a/Tests/LyrebirdTests/HalfbandFIRTests.swift +++ b/Tests/LyrebirdTests/HalfbandFIRTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("HalfbandFIR coefficients") struct HalfbandFIRTests { diff --git a/Tests/LyrebirdTests/HalfbandRoundTripTests.swift b/Tests/LyrebirdTests/HalfbandRoundTripTests.swift index 80b4b71..1b719ec 100644 --- a/Tests/LyrebirdTests/HalfbandRoundTripTests.swift +++ b/Tests/LyrebirdTests/HalfbandRoundTripTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Halfband oversampling round-trip") struct HalfbandRoundTripTests { diff --git a/Tests/LyrebirdTests/HalfbandUpsampler2xTests.swift b/Tests/LyrebirdTests/HalfbandUpsampler2xTests.swift index 46280c5..fe8cfbb 100644 --- a/Tests/LyrebirdTests/HalfbandUpsampler2xTests.swift +++ b/Tests/LyrebirdTests/HalfbandUpsampler2xTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("HalfbandUpsampler2x") struct HalfbandUpsampler2xTests { diff --git a/Tests/LyrebirdTests/HilbertTests.swift b/Tests/LyrebirdTests/HilbertTests.swift index 523a27f..a19845e 100644 --- a/Tests/LyrebirdTests/HilbertTests.swift +++ b/Tests/LyrebirdTests/HilbertTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Hilbert") struct HilbertTests { diff --git a/Tests/LyrebirdTests/InGeneratorTests.swift b/Tests/LyrebirdTests/InGeneratorTests.swift index bf8356a..c5e63a0 100644 --- a/Tests/LyrebirdTests/InGeneratorTests.swift +++ b/Tests/LyrebirdTests/InGeneratorTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("In (audio bus)") struct InGeneratorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 64) @@ -78,6 +79,7 @@ struct InGeneratorTests { } } +@MainActor @Suite("ControlIn") struct ControlInTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 64) @@ -137,6 +139,7 @@ struct ControlInTests { // MARK: - Multi-channel In.Audio +@MainActor @Suite("In.Audio multi-channel") struct InAudioMultiChannelTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 64) @@ -198,6 +201,7 @@ struct InAudioMultiChannelTests { // MARK: - Multi-channel In.Control +@MainActor @Suite("In.Control multi-channel") struct InControlMultiChannelTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 64) diff --git a/Tests/LyrebirdTests/JitterTests.swift b/Tests/LyrebirdTests/JitterTests.swift index 8fdfd68..562fdb6 100644 --- a/Tests/LyrebirdTests/JitterTests.swift +++ b/Tests/LyrebirdTests/JitterTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Jitter") struct JitterTests { diff --git a/Tests/LyrebirdTests/KarplusStrongTests.swift b/Tests/LyrebirdTests/KarplusStrongTests.swift index 8eb197c..eef84d9 100644 --- a/Tests/LyrebirdTests/KarplusStrongTests.swift +++ b/Tests/LyrebirdTests/KarplusStrongTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("KarplusStrong") struct KarplusStrongTests { diff --git a/Tests/LyrebirdTests/LFCurveNoiseAudioGenFreqTests.swift b/Tests/LyrebirdTests/LFCurveNoiseAudioGenFreqTests.swift index fdcfbe7..8b661dd 100644 --- a/Tests/LyrebirdTests/LFCurveNoiseAudioGenFreqTests.swift +++ b/Tests/LyrebirdTests/LFCurveNoiseAudioGenFreqTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LFCurveNoise.Audio generator freq") struct LFCurveNoiseAudioGenFreqTests { diff --git a/Tests/LyrebirdTests/LFDutyCycleTests.swift b/Tests/LyrebirdTests/LFDutyCycleTests.swift index 7d33de7..022cd21 100644 --- a/Tests/LyrebirdTests/LFDutyCycleTests.swift +++ b/Tests/LyrebirdTests/LFDutyCycleTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - LFDutyCycle Tests +@MainActor @Suite("LFDutyCycle") struct LFDutyCycleTests { diff --git a/Tests/LyrebirdTests/LFLineNoiseAudioGenFreqTests.swift b/Tests/LyrebirdTests/LFLineNoiseAudioGenFreqTests.swift index 028666f..08d1de3 100644 --- a/Tests/LyrebirdTests/LFLineNoiseAudioGenFreqTests.swift +++ b/Tests/LyrebirdTests/LFLineNoiseAudioGenFreqTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LFLineNoise.Audio generator freq") struct LFLineNoiseAudioGenFreqTests { diff --git a/Tests/LyrebirdTests/LFSawtoothTests.swift b/Tests/LyrebirdTests/LFSawtoothTests.swift index 5236500..1f8086e 100644 --- a/Tests/LyrebirdTests/LFSawtoothTests.swift +++ b/Tests/LyrebirdTests/LFSawtoothTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - LFSawtooth Tests +@MainActor @Suite("LFSawtooth") struct LFSawtoothTests { diff --git a/Tests/LyrebirdTests/LFSquareTests.swift b/Tests/LyrebirdTests/LFSquareTests.swift index 8e24be9..ba41712 100644 --- a/Tests/LyrebirdTests/LFSquareTests.swift +++ b/Tests/LyrebirdTests/LFSquareTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - LFSquare Tests +@MainActor @Suite("LFSquare") struct LFSquareTests { diff --git a/Tests/LyrebirdTests/LFStepNoiseAudioGenFreqTests.swift b/Tests/LyrebirdTests/LFStepNoiseAudioGenFreqTests.swift index 59360a5..e94c945 100644 --- a/Tests/LyrebirdTests/LFStepNoiseAudioGenFreqTests.swift +++ b/Tests/LyrebirdTests/LFStepNoiseAudioGenFreqTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LFStepNoise.Audio generator freq") struct LFStepNoiseAudioGenFreqTests { diff --git a/Tests/LyrebirdTests/LFTriangleTests.swift b/Tests/LyrebirdTests/LFTriangleTests.swift index 5e6d972..bdf7daf 100644 --- a/Tests/LyrebirdTests/LFTriangleTests.swift +++ b/Tests/LyrebirdTests/LFTriangleTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - LFTriangle Tests +@MainActor @Suite("LFTriangle") struct LFTriangleTests { diff --git a/Tests/LyrebirdTests/Lag2Tests.swift b/Tests/LyrebirdTests/Lag2Tests.swift index 6e65283..7dc3734 100644 --- a/Tests/LyrebirdTests/Lag2Tests.swift +++ b/Tests/LyrebirdTests/Lag2Tests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Lag2") struct Lag2Tests { diff --git a/Tests/LyrebirdTests/Lag2UpDownTests.swift b/Tests/LyrebirdTests/Lag2UpDownTests.swift index f1020e2..cce9dd8 100644 --- a/Tests/LyrebirdTests/Lag2UpDownTests.swift +++ b/Tests/LyrebirdTests/Lag2UpDownTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Lag2UpDown") struct Lag2UpDownTests { diff --git a/Tests/LyrebirdTests/LagTests.swift b/Tests/LyrebirdTests/LagTests.swift index d6802ab..bb8e855 100644 --- a/Tests/LyrebirdTests/LagTests.swift +++ b/Tests/LyrebirdTests/LagTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Lag") struct LagTests { diff --git a/Tests/LyrebirdTests/LagUpDownTests.swift b/Tests/LyrebirdTests/LagUpDownTests.swift index c1955ec..d4003b4 100644 --- a/Tests/LyrebirdTests/LagUpDownTests.swift +++ b/Tests/LyrebirdTests/LagUpDownTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LagUpDown") struct LagUpDownTests { diff --git a/Tests/LyrebirdTests/LeakDCTests.swift b/Tests/LyrebirdTests/LeakDCTests.swift index 46f27aa..346a08d 100644 --- a/Tests/LyrebirdTests/LeakDCTests.swift +++ b/Tests/LyrebirdTests/LeakDCTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LeakDC") struct LeakDCTests { diff --git a/Tests/LyrebirdTests/LineTests.swift b/Tests/LyrebirdTests/LineTests.swift index b19c918..e8b2300 100644 --- a/Tests/LyrebirdTests/LineTests.swift +++ b/Tests/LyrebirdTests/LineTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Line") struct LineTests { diff --git a/Tests/LyrebirdTests/LyrebirdBufferFileIOTests.swift b/Tests/LyrebirdTests/LyrebirdBufferFileIOTests.swift index 2f3c924..cab34c0 100644 --- a/Tests/LyrebirdTests/LyrebirdBufferFileIOTests.swift +++ b/Tests/LyrebirdTests/LyrebirdBufferFileIOTests.swift @@ -178,6 +178,7 @@ private func writeTempMultichannelWAV(channels: [[Float]], sampleRate: Double = // MARK: - load(url:channel:normalise:) +@MainActor @Suite("LyrebirdBuffer.load") struct LyrebirdBufferLoadTests { @@ -282,6 +283,7 @@ struct LyrebirdBufferLoadTests { // MARK: - fill(fromFile:channel:normalise:) +@MainActor @Suite("LyrebirdBuffer.fill(fromFile:)") struct LyrebirdBufferFillFromFileTests { @@ -337,6 +339,7 @@ struct LyrebirdBufferFillFromFileTests { // MARK: - write(to:format:sampleRate:) +@MainActor @Suite("LyrebirdBuffer.write") struct LyrebirdBufferWriteTests { @@ -460,6 +463,7 @@ struct LyrebirdBufferWriteTests { // MARK: - loadAllChannels(url:normalise:) +@MainActor @Suite("LyrebirdBuffer.loadAllChannels") struct LyrebirdBufferLoadAllChannelsTests { @@ -560,6 +564,7 @@ struct LyrebirdBufferLoadAllChannelsTests { // MARK: - Multichannel write round-trips +@MainActor @Suite("LyrebirdBuffer multichannel write") struct LyrebirdBufferMultichannelWriteTests { @@ -732,6 +737,7 @@ private func writeTempRawWAV(channelCount: UInt16, sampleRate: UInt32 = 44100) t return url } +@MainActor @Suite("LyrebirdBufferFileIO channel-count validation") struct LyrebirdBufferChannelCountValidationTests { diff --git a/Tests/LyrebirdTests/LyrebirdBufferLiveWriteTests.swift b/Tests/LyrebirdTests/LyrebirdBufferLiveWriteTests.swift index eaef1f4..fe2c889 100644 --- a/Tests/LyrebirdTests/LyrebirdBufferLiveWriteTests.swift +++ b/Tests/LyrebirdTests/LyrebirdBufferLiveWriteTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LyrebirdBuffer live writes") struct LyrebirdBufferLiveWriteTests { diff --git a/Tests/LyrebirdTests/LyrebirdBufferRateScaleTests.swift b/Tests/LyrebirdTests/LyrebirdBufferRateScaleTests.swift index e8983db..799951f 100644 --- a/Tests/LyrebirdTests/LyrebirdBufferRateScaleTests.swift +++ b/Tests/LyrebirdTests/LyrebirdBufferRateScaleTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LyrebirdBuffer.nativeRateScale") struct LyrebirdBufferRateScaleTests { diff --git a/Tests/LyrebirdTests/LyrebirdBufferTests.swift b/Tests/LyrebirdTests/LyrebirdBufferTests.swift index 3d4b472..d48ddea 100644 --- a/Tests/LyrebirdTests/LyrebirdBufferTests.swift +++ b/Tests/LyrebirdTests/LyrebirdBufferTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LyrebirdBuffer") struct LyrebirdBufferTests { @@ -180,6 +181,7 @@ struct LyrebirdBufferTests { // MARK: - Multichannel +@MainActor @Suite("LyrebirdBuffer multichannel") struct LyrebirdBufferMultichannelTests { @@ -272,6 +274,7 @@ struct LyrebirdBufferMultichannelTests { } } +@MainActor @Suite("LyrebirdBuffer duration and phasorFrequency") struct LyrebirdBufferDurationTests { diff --git a/Tests/LyrebirdTests/LyrebirdBufferWavetableTests.swift b/Tests/LyrebirdTests/LyrebirdBufferWavetableTests.swift index 35f9b66..a10a3db 100644 --- a/Tests/LyrebirdTests/LyrebirdBufferWavetableTests.swift +++ b/Tests/LyrebirdTests/LyrebirdBufferWavetableTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - 2b.1 Partial series fill +@MainActor @Suite("LyrebirdBuffer fill(partials:)") struct BufferFillPartialsTests { @@ -90,6 +91,7 @@ struct BufferFillPartialsTests { // MARK: - 2b.2 Chebyshev polynomial tables +@MainActor @Suite("LyrebirdBuffer fillChebyshev(coefficients:)") struct BufferFillChebyshevTests { @@ -136,6 +138,7 @@ struct BufferFillChebyshevTests { // MARK: - 2b.3 Window function fills +@MainActor @Suite("LyrebirdBuffer fillWindow(_:)") struct BufferFillWindowTests { @@ -237,6 +240,7 @@ struct BufferFillWindowTests { // MARK: - 2b.4 Waveshaper transfer curves +@MainActor @Suite("LyrebirdBuffer fillWaveshaper(_:)") struct BufferFillWaveshaperTests { @@ -326,6 +330,7 @@ struct BufferFillWaveshaperTests { // MARK: - 2b.5 Band-limited waveform tables +@MainActor @Suite("LyrebirdBuffer fillBandLimited(_:fundamental:sampleRate:)") struct BufferFillBandLimitedTests { @@ -401,6 +406,7 @@ struct BufferFillBandLimitedTests { // MARK: - 2b.6 Inharmonic partial series +@MainActor @Suite("LyrebirdBuffer fillPartials(_:) and fillInharmonicPartials(fundamental:beta:amplitudes:)") struct BufferFillInharmonicTests { @@ -486,6 +492,7 @@ struct BufferFillInharmonicTests { // MARK: - 2b.7 WavetableSet factory +@MainActor @Suite("WavetableSet factory methods") struct WavetableSetTests { diff --git a/Tests/LyrebirdTests/LyrebirdClockTests.swift b/Tests/LyrebirdTests/LyrebirdClockTests.swift index 4d93fff..32f3f80 100644 --- a/Tests/LyrebirdTests/LyrebirdClockTests.swift +++ b/Tests/LyrebirdTests/LyrebirdClockTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("LyrebirdClock") struct LyrebirdClockTests { diff --git a/Tests/LyrebirdTests/MIDIClockFollowerTests.swift b/Tests/LyrebirdTests/MIDIClockFollowerTests.swift index 7b3dd8f..8c1976e 100644 --- a/Tests/LyrebirdTests/MIDIClockFollowerTests.swift +++ b/Tests/LyrebirdTests/MIDIClockFollowerTests.swift @@ -54,6 +54,7 @@ private func feedTicks( } } +@MainActor @Suite("MIDIClockFollower") struct MIDIClockFollowerTests { diff --git a/Tests/LyrebirdTests/MIDIFilePlayerTests.swift b/Tests/LyrebirdTests/MIDIFilePlayerTests.swift index 70d04c5..f8e8fe7 100644 --- a/Tests/LyrebirdTests/MIDIFilePlayerTests.swift +++ b/Tests/LyrebirdTests/MIDIFilePlayerTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MIDIFilePlayer — SMF playback through LyrebirdClock") struct MIDIFilePlayerTests { diff --git a/Tests/LyrebirdTests/MIDIFileTests.swift b/Tests/LyrebirdTests/MIDIFileTests.swift index a58ef8e..2a15485 100644 --- a/Tests/LyrebirdTests/MIDIFileTests.swift +++ b/Tests/LyrebirdTests/MIDIFileTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MIDIFile — Standard MIDI File parser") struct MIDIFileTests { diff --git a/Tests/LyrebirdTests/MIDITests.swift b/Tests/LyrebirdTests/MIDITests.swift index 8ceb4f4..ea8be84 100644 --- a/Tests/LyrebirdTests/MIDITests.swift +++ b/Tests/LyrebirdTests/MIDITests.swift @@ -9,6 +9,7 @@ import Foundation import CoreMIDI @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MIDIMessage") struct MIDIMessageTests { @@ -126,6 +127,7 @@ struct MIDIMessageTests { // MARK: - MIDI handler token management +@MainActor @Suite("MIDI tokens") struct MIDITokenTests { @@ -152,6 +154,7 @@ private let handlerPropagationDelay: UInt64 = 50_000_000 // 50 ms — time for a // MARK: - MIDI dispatch integration +@MainActor @Suite("MIDI dispatch") struct MIDIDispatchTests { diff --git a/Tests/LyrebirdTests/MasterGainMuteTests.swift b/Tests/LyrebirdTests/MasterGainMuteTests.swift index 048ce40..ae6b627 100644 --- a/Tests/LyrebirdTests/MasterGainMuteTests.swift +++ b/Tests/LyrebirdTests/MasterGainMuteTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Master gain and mute") struct MasterGainMuteTests { @Test func defaultMasterGainIsUnity() { diff --git a/Tests/LyrebirdTests/MathGeneratorTests.swift b/Tests/LyrebirdTests/MathGeneratorTests.swift index d7de85f..03bf353 100644 --- a/Tests/LyrebirdTests/MathGeneratorTests.swift +++ b/Tests/LyrebirdTests/MathGeneratorTests.swift @@ -9,6 +9,7 @@ import Darwin import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MathGenerators — waveshaping + mapping") struct MathGeneratorTests { @@ -237,6 +238,7 @@ struct MathGeneratorTests { // MARK: - Additional math generators +@MainActor @Suite("Abs") struct AbsTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -256,6 +258,7 @@ struct AbsTests { } } +@MainActor @Suite("Sign") struct SignTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -279,6 +282,7 @@ struct SignTests { } } +@MainActor @Suite("Floor") struct FloorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -298,6 +302,7 @@ struct FloorTests { } } +@MainActor @Suite("Ceil") struct CeilTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -317,6 +322,7 @@ struct CeilTests { } } +@MainActor @Suite("Round") struct RoundTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -336,6 +342,7 @@ struct RoundTests { } } +@MainActor @Suite("Sqrt") struct SqrtTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -351,6 +358,7 @@ struct SqrtTests { } } +@MainActor @Suite("Reciprocal") struct ReciprocalTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -366,6 +374,7 @@ struct ReciprocalTests { } } +@MainActor @Suite("Log") struct LogTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -385,6 +394,7 @@ struct LogTests { } } +@MainActor @Suite("Exp") struct ExpTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -404,6 +414,7 @@ struct ExpTests { } } +@MainActor @Suite("Min (binary)") struct MinTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -423,6 +434,7 @@ struct MinTests { } } +@MainActor @Suite("Max (binary)") struct MaxTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -442,6 +454,7 @@ struct MaxTests { } } +@MainActor @Suite("ExpLin") struct ExpLinTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -473,6 +486,7 @@ struct ExpLinTests { } } +@MainActor @Suite("ExpExp") struct ExpExpTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -499,6 +513,7 @@ struct ExpExpTests { // MARK: - Ring1 Tests +@MainActor @Suite("Ring1") struct Ring1Tests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -522,6 +537,7 @@ struct Ring1Tests { // MARK: - Ring2 Tests +@MainActor @Suite("Ring2") struct Ring2Tests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -545,6 +561,7 @@ struct Ring2Tests { // MARK: - Ring3 Tests +@MainActor @Suite("Ring3") struct Ring3Tests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -568,6 +585,7 @@ struct Ring3Tests { // MARK: - Ring4 Tests +@MainActor @Suite("Ring4") struct Ring4Tests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -589,6 +607,7 @@ struct Ring4Tests { } } +@MainActor @Suite("Cos") struct CosTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -616,6 +635,7 @@ struct CosTests { } } +@MainActor @Suite("Sin") struct SinTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } @@ -639,6 +659,7 @@ struct SinTests { } } +@MainActor @Suite("Tan") struct TanTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8); var graph: SynthGraph { makeSynthGraph(engine: engine) } diff --git a/Tests/LyrebirdTests/MixInAudioTests.swift b/Tests/LyrebirdTests/MixInAudioTests.swift index f51761e..dca297d 100644 --- a/Tests/LyrebirdTests/MixInAudioTests.swift +++ b/Tests/LyrebirdTests/MixInAudioTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MixIn.Audio") struct MixInAudioTests { diff --git a/Tests/LyrebirdTests/MoogLadderTests.swift b/Tests/LyrebirdTests/MoogLadderTests.swift index fb20272..13e4689 100644 --- a/Tests/LyrebirdTests/MoogLadderTests.swift +++ b/Tests/LyrebirdTests/MoogLadderTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - MoogLadderTests +@MainActor @Suite("MoogLadder") struct MoogLadderTests { diff --git a/Tests/LyrebirdTests/MouseGeneratorTests.swift b/Tests/LyrebirdTests/MouseGeneratorTests.swift index a39979b..ba26ef8 100644 --- a/Tests/LyrebirdTests/MouseGeneratorTests.swift +++ b/Tests/LyrebirdTests/MouseGeneratorTests.swift @@ -29,6 +29,7 @@ final class SyntheticMouseInputBridge: MouseInputBridge, @unchecked Sendable { override var button: Double { _button.load(ordering: .relaxed) } } +@MainActor @Suite("Mouse Generators", .serialized) struct MouseGeneratorTests { diff --git a/Tests/LyrebirdTests/MuTronIIITests.swift b/Tests/LyrebirdTests/MuTronIIITests.swift index 7fa8ff0..689f9d3 100644 --- a/Tests/LyrebirdTests/MuTronIIITests.swift +++ b/Tests/LyrebirdTests/MuTronIIITests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - MuTronIIITests +@MainActor @Suite("MuTronIII") struct MuTronIIITests { diff --git a/Tests/LyrebirdTests/MulAddTests.swift b/Tests/LyrebirdTests/MulAddTests.swift index 869db21..cb4cc4a 100644 --- a/Tests/LyrebirdTests/MulAddTests.swift +++ b/Tests/LyrebirdTests/MulAddTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MulAdd") struct MulAddTests { let blockSize: Int = 64 @@ -200,6 +201,7 @@ fileprivate final class StereoConstantGen: GeneratorBase, AudioGenerator { /// Pan2-shaped pass-through that exposes a public `mul:` parameter for the test. /// `Pan2` itself takes `mul:` and routes through `MulAddSpec.apply` per channel. +@MainActor @Suite("MulAddSpec channel-aware") struct MulAddSpecChannelAwareTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) diff --git a/Tests/LyrebirdTests/MultiChannelTests.swift b/Tests/LyrebirdTests/MultiChannelTests.swift index 7ccf4d1..84c1a9b 100644 --- a/Tests/LyrebirdTests/MultiChannelTests.swift +++ b/Tests/LyrebirdTests/MultiChannelTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Multi-channel expansion") struct MultiChannelTests { diff --git a/Tests/LyrebirdTests/MultiEngineRegressionTests.swift b/Tests/LyrebirdTests/MultiEngineRegressionTests.swift index c519a60..61566a2 100644 --- a/Tests/LyrebirdTests/MultiEngineRegressionTests.swift +++ b/Tests/LyrebirdTests/MultiEngineRegressionTests.swift @@ -25,6 +25,7 @@ import Foundation /// `.boundToOtherEngine` for cross-engine sharing, `.doubleAdd` for /// same-engine re-add without intervening `remove`, and accepts /// re-add after `remove` clears the binding. +@MainActor @Suite("Multi-engine regression (Phase 196.6)") struct MultiEngineRegressionTests { diff --git a/Tests/LyrebirdTests/MusicMathTests.swift b/Tests/LyrebirdTests/MusicMathTests.swift index 4274d2d..74a3d66 100644 --- a/Tests/LyrebirdTests/MusicMathTests.swift +++ b/Tests/LyrebirdTests/MusicMathTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("MusicMath") struct MusicMathTests { diff --git a/Tests/LyrebirdTests/MusicXMLTests.swift b/Tests/LyrebirdTests/MusicXMLTests.swift index 76ae20a..d12647b 100644 --- a/Tests/LyrebirdTests/MusicXMLTests.swift +++ b/Tests/LyrebirdTests/MusicXMLTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Score ↔ MusicXML bidirectional bridge") struct MusicXMLTests { diff --git a/Tests/LyrebirdTests/NRTDriverTests.swift b/Tests/LyrebirdTests/NRTDriverTests.swift index 7dd270e..4021705 100644 --- a/Tests/LyrebirdTests/NRTDriverTests.swift +++ b/Tests/LyrebirdTests/NRTDriverTests.swift @@ -8,6 +8,7 @@ import Testing import AudioToolbox @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("NRTDriver") struct NRTDriverTests { diff --git a/Tests/LyrebirdTests/NodeTree/NodeTreeMirrorTests.swift b/Tests/LyrebirdTests/NodeTree/NodeTreeMirrorTests.swift index 552b75e..9579bbe 100644 --- a/Tests/LyrebirdTests/NodeTree/NodeTreeMirrorTests.swift +++ b/Tests/LyrebirdTests/NodeTree/NodeTreeMirrorTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable import LyrebirdSynth +@MainActor @Suite("NodeTreeMirror") struct NodeTreeMirrorTests { diff --git a/Tests/LyrebirdTests/NodeTreeTests.swift b/Tests/LyrebirdTests/NodeTreeTests.swift index 699930a..e8adee4 100644 --- a/Tests/LyrebirdTests/NodeTreeTests.swift +++ b/Tests/LyrebirdTests/NodeTreeTests.swift @@ -12,6 +12,7 @@ import Testing // MARK: - SynthesizerBase +@MainActor @Suite("SynthesizerBase") struct SynthesizerBaseTests { @@ -50,6 +51,7 @@ struct SynthesizerBaseTests { // MARK: - Node tree integration +@MainActor @Suite("Node tree integration") struct NodeTreeIntegrationTests { diff --git a/Tests/LyrebirdTests/OSCTests.swift b/Tests/LyrebirdTests/OSCTests.swift index 932433e..bb1a98e 100644 --- a/Tests/LyrebirdTests/OSCTests.swift +++ b/Tests/LyrebirdTests/OSCTests.swift @@ -10,6 +10,7 @@ import Foundation // MARK: - OSCCodec round-trip +@MainActor @Suite("OSCCodec") struct OSCCodecTests { @@ -158,6 +159,7 @@ struct OSCCodecTests { // MARK: - Glob pattern matching +@MainActor @Suite("OSCAddressPatternMatch") struct OSCAddressPatternMatchTests { @@ -218,6 +220,7 @@ struct OSCAddressPatternMatchTests { // MARK: - Handler registration +@MainActor @Suite("OSCServer handlers") struct OSCServerHandlerTests { @@ -259,6 +262,7 @@ private let handlerPropagationDelay: UInt64 = 50_000_000 // 50 ms — time for a // MARK: - LyrebirdMessageContext +@MainActor @Suite("LyrebirdMessageContext") struct LyrebirdMessageContextTests { diff --git a/Tests/LyrebirdTests/OnsetDetectorTests.swift b/Tests/LyrebirdTests/OnsetDetectorTests.swift index 7bb0912..c0818a7 100644 --- a/Tests/LyrebirdTests/OnsetDetectorTests.swift +++ b/Tests/LyrebirdTests/OnsetDetectorTests.swift @@ -29,6 +29,7 @@ private func runMagnitudeHops( // MARK: - Construction +@MainActor @Suite("OnsetDetector init validation") struct OnsetDetectorInitTests { @@ -61,6 +62,7 @@ struct OnsetDetectorInitTests { // MARK: - Spectral flux ODF +@MainActor @Suite("OnsetDetector .spectralFlux") struct OnsetDetectorFluxTests { @@ -185,6 +187,7 @@ struct OnsetDetectorFluxTests { // MARK: - Complex-domain ODF +@MainActor @Suite("OnsetDetector .complexDomain") struct OnsetDetectorComplexDomainTests { @@ -266,6 +269,7 @@ struct OnsetDetectorComplexDomainTests { // MARK: - .Control output +@MainActor @Suite("OnsetDetector.Control output") struct OnsetDetectorControlTests { @@ -361,6 +365,7 @@ struct OnsetDetectorControlTests { // MARK: - End-to-end: real SpectralChain.Audio + impulse input +@MainActor @Suite("OnsetDetector end-to-end via SpectralChain.Audio") struct OnsetDetectorEndToEndTests { @@ -422,6 +427,7 @@ struct OnsetDetectorEndToEndTests { // MARK: - Registration precondition +@MainActor @Suite("OnsetDetector.Control registration check") struct OnsetDetectorRegistrationTests { diff --git a/Tests/LyrebirdTests/OscDutyCycleTests.swift b/Tests/LyrebirdTests/OscDutyCycleTests.swift index bef5eb7..befd3be 100644 --- a/Tests/LyrebirdTests/OscDutyCycleTests.swift +++ b/Tests/LyrebirdTests/OscDutyCycleTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - OscDutyCycle Tests +@MainActor @Suite("OscDutyCycle") struct OscDutyCycleTests { diff --git a/Tests/LyrebirdTests/OscSawtoothTests.swift b/Tests/LyrebirdTests/OscSawtoothTests.swift index 1e8a5ce..79afcd9 100644 --- a/Tests/LyrebirdTests/OscSawtoothTests.swift +++ b/Tests/LyrebirdTests/OscSawtoothTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - OscSawtooth Tests +@MainActor @Suite("OscSawtooth") struct OscSawtoothTests { diff --git a/Tests/LyrebirdTests/OscSquareTests.swift b/Tests/LyrebirdTests/OscSquareTests.swift index 3106bb4..a2584fd 100644 --- a/Tests/LyrebirdTests/OscSquareTests.swift +++ b/Tests/LyrebirdTests/OscSquareTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - OscSquare Tests +@MainActor @Suite("OscSquare") struct OscSquareTests { diff --git a/Tests/LyrebirdTests/OscTableTests.swift b/Tests/LyrebirdTests/OscTableTests.swift index 442ede7..2c627cd 100644 --- a/Tests/LyrebirdTests/OscTableTests.swift +++ b/Tests/LyrebirdTests/OscTableTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("OscTable") struct OscTableTests { diff --git a/Tests/LyrebirdTests/OscTriangleTests.swift b/Tests/LyrebirdTests/OscTriangleTests.swift index 02a8046..2d1ab51 100644 --- a/Tests/LyrebirdTests/OscTriangleTests.swift +++ b/Tests/LyrebirdTests/OscTriangleTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - OscTriangle Tests +@MainActor @Suite("OscTriangle") struct OscTriangleTests { diff --git a/Tests/LyrebirdTests/OutGeneratorTests.swift b/Tests/LyrebirdTests/OutGeneratorTests.swift index e3102d3..7e202b1 100644 --- a/Tests/LyrebirdTests/OutGeneratorTests.swift +++ b/Tests/LyrebirdTests/OutGeneratorTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Out (audio bus)") struct OutGeneratorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 16) @@ -93,6 +94,7 @@ struct OutGeneratorTests { } } +@MainActor @Suite("ControlOut") struct ControlOutTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 16) diff --git a/Tests/LyrebirdTests/Pan2ParameterRampingTests.swift b/Tests/LyrebirdTests/Pan2ParameterRampingTests.swift index 93e0913..ee37943 100644 --- a/Tests/LyrebirdTests/Pan2ParameterRampingTests.swift +++ b/Tests/LyrebirdTests/Pan2ParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pan2 parameter ramping") struct Pan2ParameterRampingTests { diff --git a/Tests/LyrebirdTests/PanAzDistanceTests.swift b/Tests/LyrebirdTests/PanAzDistanceTests.swift index f2283bd..a407225 100644 --- a/Tests/LyrebirdTests/PanAzDistanceTests.swift +++ b/Tests/LyrebirdTests/PanAzDistanceTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanAzDistance") struct PanAzDistanceTests { diff --git a/Tests/LyrebirdTests/PanAzParameterRampingTests.swift b/Tests/LyrebirdTests/PanAzParameterRampingTests.swift index d2f0562..33698ed 100644 --- a/Tests/LyrebirdTests/PanAzParameterRampingTests.swift +++ b/Tests/LyrebirdTests/PanAzParameterRampingTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanAz parameter ramping") struct PanAzParameterRampingTests { diff --git a/Tests/LyrebirdTests/PanNParameterRampingTests.swift b/Tests/LyrebirdTests/PanNParameterRampingTests.swift index 519336a..08da19a 100644 --- a/Tests/LyrebirdTests/PanNParameterRampingTests.swift +++ b/Tests/LyrebirdTests/PanNParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanN parameter ramping") struct PanNParameterRampingTests { diff --git a/Tests/LyrebirdTests/PanNTests.swift b/Tests/LyrebirdTests/PanNTests.swift index d0c7438..cdfcf53 100644 --- a/Tests/LyrebirdTests/PanNTests.swift +++ b/Tests/LyrebirdTests/PanNTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanN") struct PanNTests { diff --git a/Tests/LyrebirdTests/PanXYDistanceTests.swift b/Tests/LyrebirdTests/PanXYDistanceTests.swift index ee5f037..511d41e 100644 --- a/Tests/LyrebirdTests/PanXYDistanceTests.swift +++ b/Tests/LyrebirdTests/PanXYDistanceTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanXYDistance") struct PanXYDistanceTests { diff --git a/Tests/LyrebirdTests/PanXYParameterRampingTests.swift b/Tests/LyrebirdTests/PanXYParameterRampingTests.swift index 2426438..56d3ba7 100644 --- a/Tests/LyrebirdTests/PanXYParameterRampingTests.swift +++ b/Tests/LyrebirdTests/PanXYParameterRampingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanXY parameter ramping") struct PanXYParameterRampingTests { diff --git a/Tests/LyrebirdTests/PanXYTests.swift b/Tests/LyrebirdTests/PanXYTests.swift index 07a2f45..041f82f 100644 --- a/Tests/LyrebirdTests/PanXYTests.swift +++ b/Tests/LyrebirdTests/PanXYTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PanXY") struct PanXYTests { diff --git a/Tests/LyrebirdTests/PanningTests.swift b/Tests/LyrebirdTests/PanningTests.swift index 9c60aa8..3a42e2b 100644 --- a/Tests/LyrebirdTests/PanningTests.swift +++ b/Tests/LyrebirdTests/PanningTests.swift @@ -10,6 +10,7 @@ import Foundation // MARK: - PanAz (polar equal-power 4-speaker square panner) +@MainActor @Suite("PanAz") struct PanAzTests { @@ -196,6 +197,7 @@ struct PanAzTests { // MARK: - AmbiEncoder1 +@MainActor @Suite("AmbiEncoder1") struct AmbiEncoder1Tests { @@ -351,6 +353,7 @@ struct AmbiEncoder1Tests { // MARK: - AmbiDecoder1 +@MainActor @Suite("AmbiDecoder1") struct AmbiDecoder1Tests { diff --git a/Tests/LyrebirdTests/ParallelGroupTests.swift b/Tests/LyrebirdTests/ParallelGroupTests.swift index 0ce429b..70c053a 100644 --- a/Tests/LyrebirdTests/ParallelGroupTests.swift +++ b/Tests/LyrebirdTests/ParallelGroupTests.swift @@ -48,6 +48,7 @@ private final class RecordingSynth: Synthesizer { // MARK: - Tests +@MainActor @Suite("ParallelGroup") struct ParallelGroupTests { diff --git a/Tests/LyrebirdTests/ParameterNodeTests.swift b/Tests/LyrebirdTests/ParameterNodeTests.swift index 75ef4ab..91d394e 100644 --- a/Tests/LyrebirdTests/ParameterNodeTests.swift +++ b/Tests/LyrebirdTests/ParameterNodeTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - ParameterNode Tests +@MainActor @Suite("ParameterNode") struct ParameterNodeTests { @@ -263,6 +264,7 @@ struct ParameterNodeTests { // MARK: - @LiveParam Tests +@MainActor @Suite("@LiveParam") struct LiveParamTests { diff --git a/Tests/LyrebirdTests/ParameterSourceQueueTests.swift b/Tests/LyrebirdTests/ParameterSourceQueueTests.swift index 926d755..0639537 100644 --- a/Tests/LyrebirdTests/ParameterSourceQueueTests.swift +++ b/Tests/LyrebirdTests/ParameterSourceQueueTests.swift @@ -20,6 +20,7 @@ private final class MinimalGen: GeneratorBase, AudioGenerator { // MARK: - SourcePacket Tests +@MainActor @Suite("SourcePacket") struct SourcePacketTests { @@ -101,6 +102,7 @@ struct SourcePacketTests { // MARK: - ParameterSourceQueue Tests +@MainActor @Suite("ParameterSourceQueue") struct ParameterSourceQueueTests { diff --git a/Tests/LyrebirdTests/ParameterSystemTests.swift b/Tests/LyrebirdTests/ParameterSystemTests.swift index bfb67d7..14e825b 100644 --- a/Tests/LyrebirdTests/ParameterSystemTests.swift +++ b/Tests/LyrebirdTests/ParameterSystemTests.swift @@ -76,6 +76,7 @@ private func allSamples(_ engine: SynthesisEngine, bus: Int) -> [Double] { // Suite: Mirror auto-registration // --------------------------------------------------------------------------- +@MainActor @Suite("Mirror auto-registration") struct MirrorAutoRegistrationTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -144,6 +145,7 @@ struct MirrorAutoRegistrationTests { // Suite: updateParameter (Mirror-registered fast path) // --------------------------------------------------------------------------- +@MainActor @Suite("updateParameter on @LiveParam") struct UpdateLiveParamTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -247,6 +249,7 @@ struct UpdateLiveParamTests { // Suite: Sub-block ramping (controlBlockSize < blockSize) // --------------------------------------------------------------------------- +@MainActor @Suite("ParameterNode sub-block ramp") struct ParameterNodeSubBlockTests { diff --git a/Tests/LyrebirdTests/Parameters/ParameterNodeCrossfadeTests.swift b/Tests/LyrebirdTests/Parameters/ParameterNodeCrossfadeTests.swift index 5169473..d30caae 100644 --- a/Tests/LyrebirdTests/Parameters/ParameterNodeCrossfadeTests.swift +++ b/Tests/LyrebirdTests/Parameters/ParameterNodeCrossfadeTests.swift @@ -88,6 +88,7 @@ private func expectedNewWeight(blockIndex: Int, totalBlocks: Int) -> Double { // MARK: - Test suite +@MainActor @Suite("ParameterNode crossfade") struct ParameterNodeCrossfadeTests { diff --git a/Tests/LyrebirdTests/Parameters/ParameterNodeSourceAPITests.swift b/Tests/LyrebirdTests/Parameters/ParameterNodeSourceAPITests.swift index af6b23a..3fe2fcb 100644 --- a/Tests/LyrebirdTests/Parameters/ParameterNodeSourceAPITests.swift +++ b/Tests/LyrebirdTests/Parameters/ParameterNodeSourceAPITests.swift @@ -90,6 +90,7 @@ private func renderBlock( // MARK: - Test suite +@MainActor @Suite("ParameterNode public source API") struct ParameterNodeSourceAPITests { diff --git a/Tests/LyrebirdTests/Parameters/ParameterNodeSourceSlotTests.swift b/Tests/LyrebirdTests/Parameters/ParameterNodeSourceSlotTests.swift index f5836c5..5bf1199 100644 --- a/Tests/LyrebirdTests/Parameters/ParameterNodeSourceSlotTests.swift +++ b/Tests/LyrebirdTests/Parameters/ParameterNodeSourceSlotTests.swift @@ -65,6 +65,7 @@ private final class SentinelSource: GeneratorBase, AudioGenerator { // MARK: - Test suite +@MainActor @Suite("ParameterNode source slot") struct ParameterNodeSourceSlotTests { diff --git a/Tests/LyrebirdTests/Parameters/ParameterSourceSwapIntegrationTests.swift b/Tests/LyrebirdTests/Parameters/ParameterSourceSwapIntegrationTests.swift index 3bc48eb..2863328 100644 --- a/Tests/LyrebirdTests/Parameters/ParameterSourceSwapIntegrationTests.swift +++ b/Tests/LyrebirdTests/Parameters/ParameterSourceSwapIntegrationTests.swift @@ -73,6 +73,7 @@ private func rmsD(_ samples: [Double]) -> Double { // MARK: - Test suite +@MainActor @Suite("ParameterNode source-swap integration") struct ParameterSourceSwapIntegrationTests { diff --git a/Tests/LyrebirdTests/PatternAccumulateTests.swift b/Tests/LyrebirdTests/PatternAccumulateTests.swift index 9070018..8c544a5 100644 --- a/Tests/LyrebirdTests/PatternAccumulateTests.swift +++ b/Tests/LyrebirdTests/PatternAccumulateTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.accumulate") struct PatternAccumulateTests { diff --git a/Tests/LyrebirdTests/PatternBetaTests.swift b/Tests/LyrebirdTests/PatternBetaTests.swift index c74d387..bcc26a1 100644 --- a/Tests/LyrebirdTests/PatternBetaTests.swift +++ b/Tests/LyrebirdTests/PatternBetaTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.beta") struct PatternBetaTests { diff --git a/Tests/LyrebirdTests/PatternBrownianTests.swift b/Tests/LyrebirdTests/PatternBrownianTests.swift index faeb18a..85719e4 100644 --- a/Tests/LyrebirdTests/PatternBrownianTests.swift +++ b/Tests/LyrebirdTests/PatternBrownianTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.brownian") struct PatternBrownianTests { diff --git a/Tests/LyrebirdTests/PatternCauchyTests.swift b/Tests/LyrebirdTests/PatternCauchyTests.swift index 8bde520..4871aa9 100644 --- a/Tests/LyrebirdTests/PatternCauchyTests.swift +++ b/Tests/LyrebirdTests/PatternCauchyTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.cauchy") struct PatternCauchyTests { diff --git a/Tests/LyrebirdTests/PatternClipTests.swift b/Tests/LyrebirdTests/PatternClipTests.swift index 99cb94a..3f80598 100644 --- a/Tests/LyrebirdTests/PatternClipTests.swift +++ b/Tests/LyrebirdTests/PatternClipTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.clip") struct PatternClipTests { diff --git a/Tests/LyrebirdTests/PatternClosureTests.swift b/Tests/LyrebirdTests/PatternClosureTests.swift index 4d27fba..d806c6f 100644 --- a/Tests/LyrebirdTests/PatternClosureTests.swift +++ b/Tests/LyrebirdTests/PatternClosureTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.closure") struct PatternClosureTests { diff --git a/Tests/LyrebirdTests/PatternConcatenateTests.swift b/Tests/LyrebirdTests/PatternConcatenateTests.swift index ab483c5..81a3a10 100644 --- a/Tests/LyrebirdTests/PatternConcatenateTests.swift +++ b/Tests/LyrebirdTests/PatternConcatenateTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.concatenate") struct PatternConcatenateTests { diff --git a/Tests/LyrebirdTests/PatternDifferenceTests.swift b/Tests/LyrebirdTests/PatternDifferenceTests.swift index 394b942..b2911f6 100644 --- a/Tests/LyrebirdTests/PatternDifferenceTests.swift +++ b/Tests/LyrebirdTests/PatternDifferenceTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.difference") struct PatternDifferenceTests { diff --git a/Tests/LyrebirdTests/PatternDropTests.swift b/Tests/LyrebirdTests/PatternDropTests.swift index 0209b95..16ea08b 100644 --- a/Tests/LyrebirdTests/PatternDropTests.swift +++ b/Tests/LyrebirdTests/PatternDropTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.drop") struct PatternDropTests { diff --git a/Tests/LyrebirdTests/PatternFilterTests.swift b/Tests/LyrebirdTests/PatternFilterTests.swift index e5a3863..e5b7034 100644 --- a/Tests/LyrebirdTests/PatternFilterTests.swift +++ b/Tests/LyrebirdTests/PatternFilterTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.filter") struct PatternFilterTests { diff --git a/Tests/LyrebirdTests/PatternGaussianTests.swift b/Tests/LyrebirdTests/PatternGaussianTests.swift index 9a0d83e..673e9f7 100644 --- a/Tests/LyrebirdTests/PatternGaussianTests.swift +++ b/Tests/LyrebirdTests/PatternGaussianTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.gaussian") struct PatternGaussianTests { diff --git a/Tests/LyrebirdTests/PatternGeometricTests.swift b/Tests/LyrebirdTests/PatternGeometricTests.swift index df8f1f1..955b8ec 100644 --- a/Tests/LyrebirdTests/PatternGeometricTests.swift +++ b/Tests/LyrebirdTests/PatternGeometricTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.geometric") struct PatternGeometricTests { diff --git a/Tests/LyrebirdTests/PatternInterleaveTests.swift b/Tests/LyrebirdTests/PatternInterleaveTests.swift index 6ca282e..c2764f2 100644 --- a/Tests/LyrebirdTests/PatternInterleaveTests.swift +++ b/Tests/LyrebirdTests/PatternInterleaveTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.interleave") struct PatternInterleaveTests { diff --git a/Tests/LyrebirdTests/PatternLimitTests.swift b/Tests/LyrebirdTests/PatternLimitTests.swift index f947b83..351e3e8 100644 --- a/Tests/LyrebirdTests/PatternLimitTests.swift +++ b/Tests/LyrebirdTests/PatternLimitTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.limit") struct PatternLimitTests { diff --git a/Tests/LyrebirdTests/PatternMapTests.swift b/Tests/LyrebirdTests/PatternMapTests.swift index c6af0e7..4595fdb 100644 --- a/Tests/LyrebirdTests/PatternMapTests.swift +++ b/Tests/LyrebirdTests/PatternMapTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.map") struct PatternMapTests { diff --git a/Tests/LyrebirdTests/PatternNonRepeatingRandomTests.swift b/Tests/LyrebirdTests/PatternNonRepeatingRandomTests.swift index ba512c8..d5eb63e 100644 --- a/Tests/LyrebirdTests/PatternNonRepeatingRandomTests.swift +++ b/Tests/LyrebirdTests/PatternNonRepeatingRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.nonRepeatingRandom") struct PatternNonRepeatingRandomTests { diff --git a/Tests/LyrebirdTests/PatternRejectTests.swift b/Tests/LyrebirdTests/PatternRejectTests.swift index ac26feb..d7826f2 100644 --- a/Tests/LyrebirdTests/PatternRejectTests.swift +++ b/Tests/LyrebirdTests/PatternRejectTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.reject") struct PatternRejectTests { diff --git a/Tests/LyrebirdTests/PatternRepeatingTests.swift b/Tests/LyrebirdTests/PatternRepeatingTests.swift index f5fe799..19f04e5 100644 --- a/Tests/LyrebirdTests/PatternRepeatingTests.swift +++ b/Tests/LyrebirdTests/PatternRepeatingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.repeating") struct PatternRepeatingTests { diff --git a/Tests/LyrebirdTests/PatternRoundRobinTests.swift b/Tests/LyrebirdTests/PatternRoundRobinTests.swift index 9f63915..b703ad1 100644 --- a/Tests/LyrebirdTests/PatternRoundRobinTests.swift +++ b/Tests/LyrebirdTests/PatternRoundRobinTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.roundRobin") struct PatternRoundRobinTests { diff --git a/Tests/LyrebirdTests/PatternRoundTests.swift b/Tests/LyrebirdTests/PatternRoundTests.swift index fd36c3b..91191c0 100644 --- a/Tests/LyrebirdTests/PatternRoundTests.swift +++ b/Tests/LyrebirdTests/PatternRoundTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.round") struct PatternRoundTests { diff --git a/Tests/LyrebirdTests/PatternSeriesTests.swift b/Tests/LyrebirdTests/PatternSeriesTests.swift index 789054f..cc1396b 100644 --- a/Tests/LyrebirdTests/PatternSeriesTests.swift +++ b/Tests/LyrebirdTests/PatternSeriesTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.series") struct PatternSeriesTests { diff --git a/Tests/LyrebirdTests/PatternShuffleTests.swift b/Tests/LyrebirdTests/PatternShuffleTests.swift index acb58a9..fecede6 100644 --- a/Tests/LyrebirdTests/PatternShuffleTests.swift +++ b/Tests/LyrebirdTests/PatternShuffleTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.shuffle") struct PatternShuffleTests { diff --git a/Tests/LyrebirdTests/PatternSmoothTests.swift b/Tests/LyrebirdTests/PatternSmoothTests.swift index 718e90d..5ceaa52 100644 --- a/Tests/LyrebirdTests/PatternSmoothTests.swift +++ b/Tests/LyrebirdTests/PatternSmoothTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.smooth") struct PatternSmoothTests { diff --git a/Tests/LyrebirdTests/PatternStutterTests.swift b/Tests/LyrebirdTests/PatternStutterTests.swift index 38250a3..85848b0 100644 --- a/Tests/LyrebirdTests/PatternStutterTests.swift +++ b/Tests/LyrebirdTests/PatternStutterTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.stutter") struct PatternStutterTests { diff --git a/Tests/LyrebirdTests/PatternSwitchingTests.swift b/Tests/LyrebirdTests/PatternSwitchingTests.swift index 0f6d8f0..bd26c73 100644 --- a/Tests/LyrebirdTests/PatternSwitchingTests.swift +++ b/Tests/LyrebirdTests/PatternSwitchingTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.switching") struct PatternSwitchingTests { diff --git a/Tests/LyrebirdTests/PatternTests.swift b/Tests/LyrebirdTests/PatternTests.swift index d6b0673..b1d9575 100644 --- a/Tests/LyrebirdTests/PatternTests.swift +++ b/Tests/LyrebirdTests/PatternTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern") struct PatternTests { diff --git a/Tests/LyrebirdTests/PatternTupleTests.swift b/Tests/LyrebirdTests/PatternTupleTests.swift index 1329df5..8362631 100644 --- a/Tests/LyrebirdTests/PatternTupleTests.swift +++ b/Tests/LyrebirdTests/PatternTupleTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.tuple") struct PatternTupleTests { diff --git a/Tests/LyrebirdTests/PatternUniformRandomTests.swift b/Tests/LyrebirdTests/PatternUniformRandomTests.swift index d92173e..eac4735 100644 --- a/Tests/LyrebirdTests/PatternUniformRandomTests.swift +++ b/Tests/LyrebirdTests/PatternUniformRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.uniformRandom") struct PatternUniformRandomTests { diff --git a/Tests/LyrebirdTests/PatternWeightedRandomTests.swift b/Tests/LyrebirdTests/PatternWeightedRandomTests.swift index 077e1fb..34b6ce1 100644 --- a/Tests/LyrebirdTests/PatternWeightedRandomTests.swift +++ b/Tests/LyrebirdTests/PatternWeightedRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.weightedRandom") struct PatternWeightedRandomTests { diff --git a/Tests/LyrebirdTests/PatternWrapTests.swift b/Tests/LyrebirdTests/PatternWrapTests.swift index de0e586..0f139f2 100644 --- a/Tests/LyrebirdTests/PatternWrapTests.swift +++ b/Tests/LyrebirdTests/PatternWrapTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pattern.wrap") struct PatternWrapTests { diff --git a/Tests/LyrebirdTests/Phase57NoiseTests.swift b/Tests/LyrebirdTests/Phase57NoiseTests.swift index 449365e..4480be0 100644 --- a/Tests/LyrebirdTests/Phase57NoiseTests.swift +++ b/Tests/LyrebirdTests/Phase57NoiseTests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - Distribution Sampling Unit Tests +@MainActor @Suite("DistributionSampling") struct DistributionSamplingTests { @@ -171,6 +172,7 @@ struct DistributionSamplingTests { // MARK: - UniformNoise Tests +@MainActor @Suite("UniformNoise") struct UniformNoiseTests { let blockSize: Int = 256 @@ -254,6 +256,7 @@ struct UniformNoiseTests { // MARK: - LpRandNoise Tests +@MainActor @Suite("LpRandNoise") struct LpRandNoiseTests { let blockSize: Int = 256 @@ -328,6 +331,7 @@ struct LpRandNoiseTests { // MARK: - HpRandNoise Tests +@MainActor @Suite("HpRandNoise") struct HpRandNoiseTests { let blockSize: Int = 256 @@ -393,6 +397,7 @@ struct HpRandNoiseTests { // MARK: - MeanRandNoise Tests +@MainActor @Suite("MeanRandNoise") struct MeanRandNoiseTests { let blockSize: Int = 256 @@ -457,6 +462,7 @@ struct MeanRandNoiseTests { // MARK: - GaussNoise Tests +@MainActor @Suite("GaussNoise") struct GaussNoiseTests { let blockSize: Int = 256 @@ -538,6 +544,7 @@ struct GaussNoiseTests { // MARK: - ExpRandNoise Tests +@MainActor @Suite("ExpRandNoise") struct ExpRandNoiseTests { let blockSize: Int = 256 @@ -589,6 +596,7 @@ struct ExpRandNoiseTests { // MARK: - ExponentialNoise Tests +@MainActor @Suite("ExponentialNoise") struct ExponentialNoiseTests { let blockSize: Int = 256 @@ -652,6 +660,7 @@ struct ExponentialNoiseTests { // MARK: - GammaNoise Tests +@MainActor @Suite("GammaNoise") struct GammaNoiseTests { let blockSize: Int = 256 @@ -716,6 +725,7 @@ struct GammaNoiseTests { // MARK: - LaplaceNoise Tests +@MainActor @Suite("LaplaceNoise") struct LaplaceNoiseTests { let blockSize: Int = 256 @@ -770,6 +780,7 @@ struct LaplaceNoiseTests { // MARK: - ALaplaceNoise Tests +@MainActor @Suite("ALaplaceNoise") struct ALaplaceNoiseTests { let blockSize: Int = 256 @@ -819,6 +830,7 @@ struct ALaplaceNoiseTests { // MARK: - HcosNoise Tests +@MainActor @Suite("HcosNoise") struct HcosNoiseTests { let blockSize: Int = 256 @@ -868,6 +880,7 @@ struct HcosNoiseTests { // MARK: - LogisticNoise Tests +@MainActor @Suite("LogisticNoise") struct LogisticNoiseTests { let blockSize: Int = 256 @@ -922,6 +935,7 @@ struct LogisticNoiseTests { // MARK: - PoissonNoise Tests +@MainActor @Suite("PoissonNoise") struct PoissonNoiseTests { let blockSize: Int = 256 @@ -988,6 +1002,7 @@ struct PoissonNoiseTests { // MARK: - ArcsinNoise Tests +@MainActor @Suite("ArcsinNoise") struct ArcsinNoiseTests { let blockSize: Int = 256 @@ -1040,6 +1055,7 @@ struct ArcsinNoiseTests { // MARK: - BetaRandNoise Tests +@MainActor @Suite("BetaRandNoise") struct BetaRandNoiseTests { let blockSize: Int = 256 @@ -1101,6 +1117,7 @@ struct BetaRandNoiseTests { // MARK: - CauchyNoise Tests +@MainActor @Suite("CauchyNoise") struct CauchyNoiseTests { let blockSize: Int = 256 @@ -1167,6 +1184,7 @@ struct CauchyNoiseTests { // MARK: - DistributionKind Tests +@MainActor @Suite("DistributionKind") struct DistributionKindTests { diff --git a/Tests/LyrebirdTests/Phase60ScatterCollectionTests.swift b/Tests/LyrebirdTests/Phase60ScatterCollectionTests.swift index eeb83c9..40a035a 100644 --- a/Tests/LyrebirdTests/Phase60ScatterCollectionTests.swift +++ b/Tests/LyrebirdTests/Phase60ScatterCollectionTests.swift @@ -27,6 +27,7 @@ private final class RecordingTDG: TimedDemandGenerator { // MARK: - TemporalStream.collect +@MainActor @Suite("TemporalStreamCollect") struct TemporalStreamCollectTests { @@ -60,6 +61,7 @@ struct TemporalStreamCollectTests { // MARK: - DemandGenerator.samples +@MainActor @Suite("DemandGeneratorSamples") struct DemandGeneratorSamplesTests { @@ -80,6 +82,7 @@ struct DemandGeneratorSamplesTests { // MARK: - TimedDemandGenerator.samples +@MainActor @Suite("TimedDemandGeneratorSamples") struct TimedDemandGeneratorSamplesTests { diff --git a/Tests/LyrebirdTests/PhaserTests.swift b/Tests/LyrebirdTests/PhaserTests.swift index 42c873c..52796d7 100644 --- a/Tests/LyrebirdTests/PhaserTests.swift +++ b/Tests/LyrebirdTests/PhaserTests.swift @@ -8,6 +8,7 @@ import Foundation import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Phaser") struct PhaserTests { diff --git a/Tests/LyrebirdTests/PitchShiftTests.swift b/Tests/LyrebirdTests/PitchShiftTests.swift index c1327c3..ae63b79 100644 --- a/Tests/LyrebirdTests/PitchShiftTests.swift +++ b/Tests/LyrebirdTests/PitchShiftTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PitchShift.Audio (4-head SOLA)") struct PitchShiftTests { @@ -236,6 +237,7 @@ struct PitchShiftTests { // MARK: - SpectralPitchShift +@MainActor @Suite("SpectralPitchShift") struct SpectralPitchShiftTests { diff --git a/Tests/LyrebirdTests/PitchSpellingTests.swift b/Tests/LyrebirdTests/PitchSpellingTests.swift index d9980ad..6432ad3 100644 --- a/Tests/LyrebirdTests/PitchSpellingTests.swift +++ b/Tests/LyrebirdTests/PitchSpellingTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Pitch spelling — Letter + Accidental + NoteName preserve enharmonic distinctions") struct PitchSpellingTests { diff --git a/Tests/LyrebirdTests/PlateReverbTests.swift b/Tests/LyrebirdTests/PlateReverbTests.swift index 357e0f5..ad07968 100644 --- a/Tests/LyrebirdTests/PlateReverbTests.swift +++ b/Tests/LyrebirdTests/PlateReverbTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PlateReverb.Audio — Dattorro plate reverb") struct PlateReverbTests { diff --git a/Tests/LyrebirdTests/PlayBufferTests.swift b/Tests/LyrebirdTests/PlayBufferTests.swift index 5ce30c0..631d654 100644 --- a/Tests/LyrebirdTests/PlayBufferTests.swift +++ b/Tests/LyrebirdTests/PlayBufferTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("PlayBuffer") struct PlayBufferTests { diff --git a/Tests/LyrebirdTests/PolyBLEPHelperTests.swift b/Tests/LyrebirdTests/PolyBLEPHelperTests.swift index 870f05a..9572881 100644 --- a/Tests/LyrebirdTests/PolyBLEPHelperTests.swift +++ b/Tests/LyrebirdTests/PolyBLEPHelperTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - polyBLEP / polyBLAMP unit tests +@MainActor @Suite("PolyBLEP helpers") struct PolyBLEPHelperTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdEventListBuildFromFileTests.swift b/Tests/LyrebirdTests/Process/LyrebirdEventListBuildFromFileTests.swift index f965ed2..1fab1d6 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdEventListBuildFromFileTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdEventListBuildFromFileTests.swift @@ -70,6 +70,7 @@ private func removeTempDir(_ url: URL) { // MARK: - Suite +@MainActor @Suite("LyrebirdEventListBuildFromFile") struct LyrebirdEventListBuildFromFileTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdEventListPrePostGroupTests.swift b/Tests/LyrebirdTests/Process/LyrebirdEventListPrePostGroupTests.swift index 522fd73..6fa60d8 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdEventListPrePostGroupTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdEventListPrePostGroupTests.swift @@ -37,6 +37,7 @@ private func makePrePostTestEngine() -> SynthesisEngine { ) } +@MainActor @Suite("LyrebirdEventList preMasterGroup / postMasterGroup") struct LyrebirdEventListPrePostGroupTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdEventListRecordingTests.swift b/Tests/LyrebirdTests/Process/LyrebirdEventListRecordingTests.swift index 819b85b..03a3258 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdEventListRecordingTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdEventListRecordingTests.swift @@ -210,6 +210,7 @@ private func removeTempDir(_ url: URL) { // MARK: - Suite +@MainActor @Suite("LyrebirdEventListRecording") struct LyrebirdEventListRecordingTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdEventListTests.swift b/Tests/LyrebirdTests/Process/LyrebirdEventListTests.swift index bedbaf3..944c91e 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdEventListTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdEventListTests.swift @@ -140,6 +140,7 @@ private final class Box: @unchecked Sendable { // MARK: - Suite +@MainActor @Suite("LyrebirdEventList") struct LyrebirdEventListTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdEventListTimelineTests.swift b/Tests/LyrebirdTests/Process/LyrebirdEventListTimelineTests.swift index aff03d5..9cbf2bc 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdEventListTimelineTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdEventListTimelineTests.swift @@ -92,6 +92,7 @@ private func makeSimpleEventList( // MARK: - Suite +@MainActor @Suite("LyrebirdEventListTimeline") struct LyrebirdEventListTimelineTests { diff --git a/Tests/LyrebirdTests/Process/LyrebirdProcessReleaseNodeHoldTest.swift b/Tests/LyrebirdTests/Process/LyrebirdProcessReleaseNodeHoldTest.swift index d6716e9..8940bf7 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdProcessReleaseNodeHoldTest.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdProcessReleaseNodeHoldTest.swift @@ -21,6 +21,7 @@ import Foundation /// /// must hold at the peak value (1.0) indefinitely while gate > 0, not at /// `levels[releaseNode + 1] = levels[2] = 0` (the pre-Phase-162 behavior). +@MainActor @Suite("LyrebirdProcess envelope holds at releaseNode level index") struct LyrebirdProcessReleaseNodeHoldTest { diff --git a/Tests/LyrebirdTests/Process/LyrebirdProcessTests.swift b/Tests/LyrebirdTests/Process/LyrebirdProcessTests.swift index c26e8dc..7e32488 100644 --- a/Tests/LyrebirdTests/Process/LyrebirdProcessTests.swift +++ b/Tests/LyrebirdTests/Process/LyrebirdProcessTests.swift @@ -99,6 +99,7 @@ private final class TestBlockDriver: @unchecked Sendable { // MARK: - Suite +@MainActor @Suite("LyrebirdProcess") struct LyrebirdProcessTests { @@ -426,8 +427,9 @@ struct LyrebirdProcessTests { envelope: sustainedEnvelope(), numChannels: 1, body: { ctx in - let s1: SilentSynth = SilentSynth() - let s2: SilentSynth = SilentSynth() + let (s1, s2): (SilentSynth, SilentSynth) = await MainActor.run { + (SilentSynth(), SilentSynth()) + } ctx.add(s1, at: .head) ctx.add(s2, at: .tail) // Allow main-thread dispatches from ctx.add to land and the engine diff --git a/Tests/LyrebirdTests/RBJFilterTests.swift b/Tests/LyrebirdTests/RBJFilterTests.swift index 61ac160..88f429b 100644 --- a/Tests/LyrebirdTests/RBJFilterTests.swift +++ b/Tests/LyrebirdTests/RBJFilterTests.swift @@ -25,6 +25,7 @@ private func dftMag(samples: [Double], freq: Double, sampleRate: Double) -> Doub // MARK: - RBJFilterTests +@MainActor @Suite("RBJFilters") struct RBJFilterTests { diff --git a/Tests/LyrebirdTests/RTBufferSlotTests.swift b/Tests/LyrebirdTests/RTBufferSlotTests.swift index 9c7422f..081dfb2 100644 --- a/Tests/LyrebirdTests/RTBufferSlotTests.swift +++ b/Tests/LyrebirdTests/RTBufferSlotTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("RTBufferSlot") struct RTBufferSlotTests { diff --git a/Tests/LyrebirdTests/RangeMapperTests.swift b/Tests/LyrebirdTests/RangeMapperTests.swift index 7fda96d..ae10792 100644 --- a/Tests/LyrebirdTests/RangeMapperTests.swift +++ b/Tests/LyrebirdTests/RangeMapperTests.swift @@ -9,6 +9,7 @@ import Darwin import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("RangeMapper — bipolar curve mapping") struct RangeMapperTests { diff --git a/Tests/LyrebirdTests/RateRampTests.swift b/Tests/LyrebirdTests/RateRampTests.swift index 0ee5a88..a837fd3 100644 --- a/Tests/LyrebirdTests/RateRampTests.swift +++ b/Tests/LyrebirdTests/RateRampTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("RateRamp") struct RateRampTests { diff --git a/Tests/LyrebirdTests/RecordBufferTests.swift b/Tests/LyrebirdTests/RecordBufferTests.swift index b1a11ef..453d5f8 100644 --- a/Tests/LyrebirdTests/RecordBufferTests.swift +++ b/Tests/LyrebirdTests/RecordBufferTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("RecordBuffer") struct RecordBufferTests { diff --git a/Tests/LyrebirdTests/ReplaceOutAudioGeneratorTests.swift b/Tests/LyrebirdTests/ReplaceOutAudioGeneratorTests.swift index cd2efd6..43c3d8a 100644 --- a/Tests/LyrebirdTests/ReplaceOutAudioGeneratorTests.swift +++ b/Tests/LyrebirdTests/ReplaceOutAudioGeneratorTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ReplaceOut.Audio") struct ReplaceOutAudioGeneratorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 16) diff --git a/Tests/LyrebirdTests/ReplaceOutControlGeneratorTests.swift b/Tests/LyrebirdTests/ReplaceOutControlGeneratorTests.swift index 01702ad..5887561 100644 --- a/Tests/LyrebirdTests/ReplaceOutControlGeneratorTests.swift +++ b/Tests/LyrebirdTests/ReplaceOutControlGeneratorTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ReplaceOut.Control") struct ReplaceOutControlGeneratorTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 16) diff --git a/Tests/LyrebirdTests/ResonatingFilterTests.swift b/Tests/LyrebirdTests/ResonatingFilterTests.swift index 5359ab5..d2862b6 100644 --- a/Tests/LyrebirdTests/ResonatingFilterTests.swift +++ b/Tests/LyrebirdTests/ResonatingFilterTests.swift @@ -24,6 +24,7 @@ private func dftMag(samples: [Double], freq: Double, sampleRate: Double) -> Doub // MARK: - ResonatingFilterTests +@MainActor @Suite("ResonatingFilter") struct ResonatingFilterTests { @@ -125,6 +126,7 @@ struct ResonatingFilterTests { // MARK: - RingingFilterTests +@MainActor @Suite("RingingFilter") struct RingingFilterTests { @@ -232,6 +234,7 @@ struct RingingFilterTests { // MARK: - CombFilterTests +@MainActor @Suite("CombFilter") struct CombFilterTests { @@ -335,6 +338,7 @@ struct CombFilterTests { // MARK: - AllpassFilterTests +@MainActor @Suite("AllpassFilter") struct AllpassFilterTests { @@ -458,6 +462,7 @@ struct AllpassFilterTests { // MARK: - DelayInterpolation allpass mode +@MainActor @Suite("DelayInterpolationAllpass") struct DelayInterpolationAllpassTests { diff --git a/Tests/LyrebirdTests/ResonatorBankTests.swift b/Tests/LyrebirdTests/ResonatorBankTests.swift index 5e344bb..ab91f69 100644 --- a/Tests/LyrebirdTests/ResonatorBankTests.swift +++ b/Tests/LyrebirdTests/ResonatorBankTests.swift @@ -32,6 +32,7 @@ private func makeBank(_ triplets: [(Double, Double, Double)]) -> LyrebirdBuffer return buf } +@MainActor @Suite("ResonatorBank") struct ResonatorBankTests { diff --git a/Tests/LyrebirdTests/RootRegisteringTests.swift b/Tests/LyrebirdTests/RootRegisteringTests.swift index b204b12..6a0a5be 100644 --- a/Tests/LyrebirdTests/RootRegisteringTests.swift +++ b/Tests/LyrebirdTests/RootRegisteringTests.swift @@ -163,6 +163,7 @@ private final class ExternallyConstructedOutSynth: SynthesizerBase { // MARK: - Tests +@MainActor @Suite("RootRegistering — auto-register side-effect generators in build()") struct RootRegisteringTests { diff --git a/Tests/LyrebirdTests/SPSCQueueTests.swift b/Tests/LyrebirdTests/SPSCQueueTests.swift index b10b987..f669a59 100644 --- a/Tests/LyrebirdTests/SPSCQueueTests.swift +++ b/Tests/LyrebirdTests/SPSCQueueTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SPSCQueue") struct SPSCQueueTests { diff --git a/Tests/LyrebirdTests/SVFTests.swift b/Tests/LyrebirdTests/SVFTests.swift index 12287f3..442f0fd 100644 --- a/Tests/LyrebirdTests/SVFTests.swift +++ b/Tests/LyrebirdTests/SVFTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - SVFTests +@MainActor @Suite("SVF") struct SVFTests { diff --git a/Tests/LyrebirdTests/SampleAndHoldTests.swift b/Tests/LyrebirdTests/SampleAndHoldTests.swift index 03507cb..74e1d74 100644 --- a/Tests/LyrebirdTests/SampleAndHoldTests.swift +++ b/Tests/LyrebirdTests/SampleAndHoldTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SampleAndHold.Audio") struct SampleAndHoldAudioTests { @@ -101,6 +102,7 @@ struct SampleAndHoldAudioTests { } } +@MainActor @Suite("SampleAndHold.Control") struct SampleAndHoldControlTests { diff --git a/Tests/LyrebirdTests/ScannedSynthesizerTests.swift b/Tests/LyrebirdTests/ScannedSynthesizerTests.swift index b6ba368..fef7840 100644 --- a/Tests/LyrebirdTests/ScannedSynthesizerTests.swift +++ b/Tests/LyrebirdTests/ScannedSynthesizerTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ScannedSynthesizer") struct ScannedSynthesizerTests { diff --git a/Tests/LyrebirdTests/SchedulingTests.swift b/Tests/LyrebirdTests/SchedulingTests.swift index 215013e..ab35523 100644 --- a/Tests/LyrebirdTests/SchedulingTests.swift +++ b/Tests/LyrebirdTests/SchedulingTests.swift @@ -13,6 +13,7 @@ final class MockSynth: Synthesizer { // MARK: - SampleTime Suite +@MainActor @Suite("SampleTime") struct SampleTimeTests { @@ -47,6 +48,7 @@ struct SampleTimeTests { // MARK: - Sub-Block Splitting Suite +@MainActor @Suite("Sub-Block Splitting") struct SubBlockSplittingTests { @@ -165,6 +167,7 @@ struct SubBlockSplittingTests { // MARK: - Scheduling API Suite +@MainActor @Suite("Scheduling API") struct SchedulingAPITests { diff --git a/Tests/LyrebirdTests/ScopeTests.swift b/Tests/LyrebirdTests/ScopeTests.swift index e9299ed..65735b8 100644 --- a/Tests/LyrebirdTests/ScopeTests.swift +++ b/Tests/LyrebirdTests/ScopeTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ScopeCapture") final class ScopeTests { diff --git a/Tests/LyrebirdTests/ScorePlayerTests.swift b/Tests/LyrebirdTests/ScorePlayerTests.swift index e964348..fc84b4a 100644 --- a/Tests/LyrebirdTests/ScorePlayerTests.swift +++ b/Tests/LyrebirdTests/ScorePlayerTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("ScorePlayer — clock-driven Score playback") struct ScorePlayerTests { diff --git a/Tests/LyrebirdTests/ScoreSMFBridgeTests.swift b/Tests/LyrebirdTests/ScoreSMFBridgeTests.swift index a6e9e3e..ee959c8 100644 --- a/Tests/LyrebirdTests/ScoreSMFBridgeTests.swift +++ b/Tests/LyrebirdTests/ScoreSMFBridgeTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Score ↔ SMF bidirectional bridge") struct ScoreSMFBridgeTests { diff --git a/Tests/LyrebirdTests/ScoreTests.swift b/Tests/LyrebirdTests/ScoreTests.swift index 314ea1d..db06b71 100644 --- a/Tests/LyrebirdTests/ScoreTests.swift +++ b/Tests/LyrebirdTests/ScoreTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Score — note/rest/chord/tuplet flattening") struct ScoreTests { diff --git a/Tests/LyrebirdTests/SendTriggerTests.swift b/Tests/LyrebirdTests/SendTriggerTests.swift index b657e73..e738220 100644 --- a/Tests/LyrebirdTests/SendTriggerTests.swift +++ b/Tests/LyrebirdTests/SendTriggerTests.swift @@ -10,6 +10,7 @@ import Foundation // MARK: - SendTrigger.Audio +@MainActor @Suite("SendTrigger.Audio") struct SendTriggerAudioTests { @@ -142,6 +143,7 @@ struct SendTriggerAudioTests { // MARK: - SendTrigger.Control +@MainActor @Suite("SendTrigger.Control") struct SendTriggerControlTests { @@ -228,6 +230,7 @@ struct SendTriggerControlTests { // MARK: - NRT integration +@MainActor @Suite("SendTrigger NRT") struct SendTriggerNRTTests { diff --git a/Tests/LyrebirdTests/SequencerStepTests.swift b/Tests/LyrebirdTests/SequencerStepTests.swift index 7319540..1035cf0 100644 --- a/Tests/LyrebirdTests/SequencerStepTests.swift +++ b/Tests/LyrebirdTests/SequencerStepTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SequencerStep") struct SequencerStepTests { diff --git a/Tests/LyrebirdTests/SignalChangedTests.swift b/Tests/LyrebirdTests/SignalChangedTests.swift index d9a20fd..ab9cfef 100644 --- a/Tests/LyrebirdTests/SignalChangedTests.swift +++ b/Tests/LyrebirdTests/SignalChangedTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SignalChanged.Audio") struct SignalChangedAudioTests { @@ -107,6 +108,7 @@ struct SignalChangedAudioTests { } } +@MainActor @Suite("SignalChanged.Control") struct SignalChangedControlTests { @@ -157,6 +159,7 @@ struct SignalChangedControlTests { } } +@MainActor @Suite("SignalChanged generator-driven threshold") struct SignalChangedGeneratorThresholdTests { diff --git a/Tests/LyrebirdTests/SignalGraphIntegrationTests.swift b/Tests/LyrebirdTests/SignalGraphIntegrationTests.swift index 9d8116b..be36e2a 100644 --- a/Tests/LyrebirdTests/SignalGraphIntegrationTests.swift +++ b/Tests/LyrebirdTests/SignalGraphIntegrationTests.swift @@ -106,6 +106,7 @@ private func rms(_ samples: ArraySlice) -> Double { // MARK: - OscSin integration +@MainActor @Suite("OscSin engine integration") struct OscSinEngineIntegrationTests { let blockSize: Int = 64 @@ -180,6 +181,7 @@ struct OscSinEngineIntegrationTests { // MARK: - Filter chain integration +@MainActor @Suite("Filter chain integration") struct FilterChainIntegrationTests { let blockSize: Int = 512 @@ -228,6 +230,7 @@ struct FilterChainIntegrationTests { // MARK: - Delay line integration +@MainActor @Suite("Delay line integration") struct DelayLineIntegrationTests { let blockSize: Int = 64 @@ -299,6 +302,7 @@ struct DelayLineIntegrationTests { // MARK: - Bus accumulation +@MainActor @Suite("Bus accumulation integration") struct BusAccumulationIntegrationTests { let blockSize: Int = 64 @@ -383,6 +387,7 @@ struct BusAccumulationIntegrationTests { // MARK: - Parameter modulation integration +@MainActor @Suite("Parameter modulation integration") struct ParameterModulationIntegrationTests { let blockSize: Int = 64 diff --git a/Tests/LyrebirdTests/SpatialDistanceTests.swift b/Tests/LyrebirdTests/SpatialDistanceTests.swift index a72690e..5a5d82e 100644 --- a/Tests/LyrebirdTests/SpatialDistanceTests.swift +++ b/Tests/LyrebirdTests/SpatialDistanceTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpatialDistance") struct SpatialDistanceTests { diff --git a/Tests/LyrebirdTests/SpectralAutoPullTests.swift b/Tests/LyrebirdTests/SpectralAutoPullTests.swift index 17bd480..f7124ee 100644 --- a/Tests/LyrebirdTests/SpectralAutoPullTests.swift +++ b/Tests/LyrebirdTests/SpectralAutoPullTests.swift @@ -13,6 +13,7 @@ import Foundation /// `SpectralChain.Audio` evaluation themselves — callers do not need to add /// the chain via `addOutputGenerator(...)` or to manually call /// `chain.calculatedSamples(...)` each block. +@MainActor @Suite("Spectral consumer auto-pull") struct SpectralAutoPullTests { diff --git a/Tests/LyrebirdTests/SpectralBinDelayTests.swift b/Tests/LyrebirdTests/SpectralBinDelayTests.swift index 699fac2..8854e0c 100644 --- a/Tests/LyrebirdTests/SpectralBinDelayTests.swift +++ b/Tests/LyrebirdTests/SpectralBinDelayTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralBinDelay") struct SpectralBinDelayTests { diff --git a/Tests/LyrebirdTests/SpectralBlurTests.swift b/Tests/LyrebirdTests/SpectralBlurTests.swift index 59671dc..17d4b03 100644 --- a/Tests/LyrebirdTests/SpectralBlurTests.swift +++ b/Tests/LyrebirdTests/SpectralBlurTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralBlur") struct SpectralBlurTests { diff --git a/Tests/LyrebirdTests/SpectralBrickwallTests.swift b/Tests/LyrebirdTests/SpectralBrickwallTests.swift index f6133b3..60f0872 100644 --- a/Tests/LyrebirdTests/SpectralBrickwallTests.swift +++ b/Tests/LyrebirdTests/SpectralBrickwallTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralBrickwall") struct SpectralBrickwallTests { diff --git a/Tests/LyrebirdTests/SpectralChainTests.swift b/Tests/LyrebirdTests/SpectralChainTests.swift index 92b8476..6fff400 100644 --- a/Tests/LyrebirdTests/SpectralChainTests.swift +++ b/Tests/LyrebirdTests/SpectralChainTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralChain.Audio — basic shape") struct SpectralChainBasicTests { @Test func rateIsAudio() { @@ -40,6 +41,7 @@ import Foundation } } +@MainActor @Suite("SpectralChain.Audio — analysis hop") struct SpectralChainAnalysisHopTests { @Test func dcBinDominatesForConstantInput() throws { @@ -210,6 +212,7 @@ import Foundation } } +@MainActor @Suite("SpectralChain.Audio — resynthesis") struct SpectralChainResynthesisTests { @Test func monoResynthesisReachesUnityGainForDC() throws { @@ -266,6 +269,7 @@ import Foundation } } +@MainActor @Suite("SpectralChain.Audio — synthOnly mode") struct SpectralChainSynthOnlyTests { /// Build a frame buffer with a constant non-zero DC magnitude on every diff --git a/Tests/LyrebirdTests/SpectralComplexClosureTests.swift b/Tests/LyrebirdTests/SpectralComplexClosureTests.swift index 5a98e6b..66987df 100644 --- a/Tests/LyrebirdTests/SpectralComplexClosureTests.swift +++ b/Tests/LyrebirdTests/SpectralComplexClosureTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralComplexClosure") struct SpectralComplexClosureTests { diff --git a/Tests/LyrebirdTests/SpectralConvolveTests.swift b/Tests/LyrebirdTests/SpectralConvolveTests.swift index 60d6c85..5010ba5 100644 --- a/Tests/LyrebirdTests/SpectralConvolveTests.swift +++ b/Tests/LyrebirdTests/SpectralConvolveTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralConvolve") struct SpectralConvolveTests { diff --git a/Tests/LyrebirdTests/SpectralCrossMapTests.swift b/Tests/LyrebirdTests/SpectralCrossMapTests.swift index 114336d..cf9b740 100644 --- a/Tests/LyrebirdTests/SpectralCrossMapTests.swift +++ b/Tests/LyrebirdTests/SpectralCrossMapTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralCrossMap") struct SpectralCrossMapTests { diff --git a/Tests/LyrebirdTests/SpectralDiffuseTests.swift b/Tests/LyrebirdTests/SpectralDiffuseTests.swift index 8221989..d1f50c5 100644 --- a/Tests/LyrebirdTests/SpectralDiffuseTests.swift +++ b/Tests/LyrebirdTests/SpectralDiffuseTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralDiffuse") struct SpectralDiffuseTests { diff --git a/Tests/LyrebirdTests/SpectralFeatureTests.swift b/Tests/LyrebirdTests/SpectralFeatureTests.swift index 7fe5c57..729626a 100644 --- a/Tests/LyrebirdTests/SpectralFeatureTests.swift +++ b/Tests/LyrebirdTests/SpectralFeatureTests.swift @@ -24,6 +24,7 @@ private let testBlockSize: Int = 64 // MARK: - SpectralCentroid.Control +@MainActor @Suite("SpectralCentroid.Control") struct SpectralCentroidTests { @@ -99,6 +100,7 @@ struct SpectralCentroidTests { // MARK: - SpectralFlatness.Control +@MainActor @Suite("SpectralFlatness.Control") struct SpectralFlatnessTests { @@ -179,6 +181,7 @@ struct SpectralFlatnessTests { // MARK: - SpectralSpread.Control +@MainActor @Suite("SpectralSpread.Control") struct SpectralSpreadTests { @@ -240,6 +243,7 @@ struct SpectralSpreadTests { // MARK: - SpectralFlux.Control +@MainActor @Suite("SpectralFlux.Control") struct SpectralFluxTests { @@ -306,6 +310,7 @@ struct SpectralFluxTests { // MARK: - SpectralEntropy.Control +@MainActor @Suite("SpectralEntropy.Control") struct SpectralEntropyTests { @@ -383,6 +388,7 @@ struct SpectralEntropyTests { // MARK: - SpectralRolloff.Control +@MainActor @Suite("SpectralRolloff.Control") struct SpectralRolloffTests { diff --git a/Tests/LyrebirdTests/SpectralFormantShiftTests.swift b/Tests/LyrebirdTests/SpectralFormantShiftTests.swift index 3748410..fa6b0bb 100644 --- a/Tests/LyrebirdTests/SpectralFormantShiftTests.swift +++ b/Tests/LyrebirdTests/SpectralFormantShiftTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralFormantShift") struct SpectralFormantShiftTests { diff --git a/Tests/LyrebirdTests/SpectralGateTests.swift b/Tests/LyrebirdTests/SpectralGateTests.swift index b64eae4..b3da302 100644 --- a/Tests/LyrebirdTests/SpectralGateTests.swift +++ b/Tests/LyrebirdTests/SpectralGateTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralGate") struct SpectralGateTests { diff --git a/Tests/LyrebirdTests/SpectralHarmonicEnhanceTests.swift b/Tests/LyrebirdTests/SpectralHarmonicEnhanceTests.swift index 3476e91..43461b0 100644 --- a/Tests/LyrebirdTests/SpectralHarmonicEnhanceTests.swift +++ b/Tests/LyrebirdTests/SpectralHarmonicEnhanceTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralHarmonicEnhance") struct SpectralHarmonicEnhanceTests { diff --git a/Tests/LyrebirdTests/SpectralMagnitudeMapTests.swift b/Tests/LyrebirdTests/SpectralMagnitudeMapTests.swift index aa7718d..d8ac6df 100644 --- a/Tests/LyrebirdTests/SpectralMagnitudeMapTests.swift +++ b/Tests/LyrebirdTests/SpectralMagnitudeMapTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralMagnitudeMap") struct SpectralMagnitudeMapTests { diff --git a/Tests/LyrebirdTests/SpectralNoiseFilterTests.swift b/Tests/LyrebirdTests/SpectralNoiseFilterTests.swift index 2b8848c..4da946f 100644 --- a/Tests/LyrebirdTests/SpectralNoiseFilterTests.swift +++ b/Tests/LyrebirdTests/SpectralNoiseFilterTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralNoiseFilter") struct SpectralNoiseFilterTests { diff --git a/Tests/LyrebirdTests/SpectralPartialFilterTests.swift b/Tests/LyrebirdTests/SpectralPartialFilterTests.swift index 8dc52cb..34c256c 100644 --- a/Tests/LyrebirdTests/SpectralPartialFilterTests.swift +++ b/Tests/LyrebirdTests/SpectralPartialFilterTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralPartialFilter") struct SpectralPartialFilterTests { diff --git a/Tests/LyrebirdTests/SpectralPhaseShiftTests.swift b/Tests/LyrebirdTests/SpectralPhaseShiftTests.swift index b8bccad..37a0d7b 100644 --- a/Tests/LyrebirdTests/SpectralPhaseShiftTests.swift +++ b/Tests/LyrebirdTests/SpectralPhaseShiftTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralPhaseShift") struct SpectralPhaseShiftTests { diff --git a/Tests/LyrebirdTests/SpectralPlayBufTests.swift b/Tests/LyrebirdTests/SpectralPlayBufTests.swift index 18f0cd5..80ec734 100644 --- a/Tests/LyrebirdTests/SpectralPlayBufTests.swift +++ b/Tests/LyrebirdTests/SpectralPlayBufTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Spectral Frame Buffer Playback") struct SpectralPlayBufferTests { diff --git a/Tests/LyrebirdTests/SpectralPolarClosureTests.swift b/Tests/LyrebirdTests/SpectralPolarClosureTests.swift index 5c73b13..64bb5d6 100644 --- a/Tests/LyrebirdTests/SpectralPolarClosureTests.swift +++ b/Tests/LyrebirdTests/SpectralPolarClosureTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralPolarClosure") struct SpectralPolarClosureTests { diff --git a/Tests/LyrebirdTests/SpectralProcessor2Tests.swift b/Tests/LyrebirdTests/SpectralProcessor2Tests.swift index 14696b9..39d136a 100644 --- a/Tests/LyrebirdTests/SpectralProcessor2Tests.swift +++ b/Tests/LyrebirdTests/SpectralProcessor2Tests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralProcessor2 dispatch") struct SpectralProcessor2Tests { diff --git a/Tests/LyrebirdTests/SpectralStereoDiffuseTests.swift b/Tests/LyrebirdTests/SpectralStereoDiffuseTests.swift index 00211d4..79f69e4 100644 --- a/Tests/LyrebirdTests/SpectralStereoDiffuseTests.swift +++ b/Tests/LyrebirdTests/SpectralStereoDiffuseTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralStereoDiffuse — shape") struct SpectralStereoDiffuseShapeTests { @Test func outputChannelCountIsTwo() { @@ -29,6 +30,7 @@ import Foundation } } +@MainActor @Suite("SpectralStereoDiffuse — magnitude conservation + bypass") struct SpectralStereoDiffuseMagnitudeTests { @Test func amountZeroIsExactBypass() { @@ -86,6 +88,7 @@ import Foundation } } +@MainActor @Suite("SpectralStereoDiffuse — channel decorrelation") struct SpectralStereoDiffuseDecorrelationTests { @Test func channelsDifferAtAmountOne() { diff --git a/Tests/LyrebirdTests/SpectralTiltTests.swift b/Tests/LyrebirdTests/SpectralTiltTests.swift index 492b41d..e7afe4b 100644 --- a/Tests/LyrebirdTests/SpectralTiltTests.swift +++ b/Tests/LyrebirdTests/SpectralTiltTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectralTilt") struct SpectralTiltTests { diff --git a/Tests/LyrebirdTests/SpectrumCaptureTests.swift b/Tests/LyrebirdTests/SpectrumCaptureTests.swift index e11632f..91a143d 100644 --- a/Tests/LyrebirdTests/SpectrumCaptureTests.swift +++ b/Tests/LyrebirdTests/SpectrumCaptureTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpectrumCapture") final class SpectrumCaptureTests { diff --git a/Tests/LyrebirdTests/SpringReverbTests.swift b/Tests/LyrebirdTests/SpringReverbTests.swift index e36a454..cc6fffa 100644 --- a/Tests/LyrebirdTests/SpringReverbTests.swift +++ b/Tests/LyrebirdTests/SpringReverbTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SpringReverb.Audio — spring-tank reverb") struct SpringReverbTests { diff --git a/Tests/LyrebirdTests/StdlibGeneratorTests.swift b/Tests/LyrebirdTests/StdlibGeneratorTests.swift index a057176..670a1e7 100644 --- a/Tests/LyrebirdTests/StdlibGeneratorTests.swift +++ b/Tests/LyrebirdTests/StdlibGeneratorTests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - OscSin Tests +@MainActor @Suite("OscSin") struct OscSinTests { let blockSize: Int = 64 @@ -201,6 +202,7 @@ struct OscSinTests { // MARK: - Impulse Tests +@MainActor @Suite("Impulse") struct ImpulseTests { let blockSize: Int = 64 @@ -268,6 +270,7 @@ struct ImpulseTests { // MARK: - WhiteNoise Tests +@MainActor @Suite("WhiteNoise") struct WhiteNoiseTests { let blockSize: Int = 256 @@ -341,6 +344,7 @@ struct WhiteNoiseTests { // MARK: - LFStepNoise Tests +@MainActor @Suite("LFStepNoise") struct LFStepNoiseTests { // Use blockSize=100, sampleRate=100 → 1 second = 1 block, easy math @@ -418,6 +422,7 @@ struct LFStepNoiseTests { // MARK: - LFLineNoise Tests +@MainActor @Suite("LFLineNoise") struct LFLineNoiseTests { let engine: SynthesisEngine @@ -485,6 +490,7 @@ struct LFLineNoiseTests { // MARK: - PinkNoise Tests +@MainActor @Suite("PinkNoise") struct PinkNoiseTests { let blockSize: Int = 256 @@ -568,6 +574,7 @@ struct PinkNoiseTests { // MARK: - BrownNoise Tests +@MainActor @Suite("BrownNoise") struct BrownNoiseTests { let blockSize: Int = 256 @@ -662,6 +669,7 @@ struct BrownNoiseTests { // MARK: - GrayNoise Tests +@MainActor @Suite("GrayNoise") struct GrayNoiseTests { let blockSize: Int = 512 @@ -754,6 +762,7 @@ struct GrayNoiseTests { // MARK: - ClipNoise Tests +@MainActor @Suite("ClipNoise") struct ClipNoiseTests { let blockSize: Int = 512 @@ -830,6 +839,7 @@ struct ClipNoiseTests { // MARK: - Dust Tests +@MainActor @Suite("Dust") struct DustTests { // Use sampleRate=48000 and blockSize=512 to match the deterministic test setup. @@ -941,6 +951,7 @@ struct DustTests { // MARK: - Dust2 Tests +@MainActor @Suite("Dust2") struct Dust2Tests { let blockSize: Int = 512 @@ -1051,6 +1062,7 @@ struct Dust2Tests { // MARK: - FirstOrderSection Tests +@MainActor @Suite("FirstOrderSection") struct FirstOrderSectionTests { let blockSize: Int = 8 @@ -1120,6 +1132,7 @@ struct FirstOrderSectionTests { // MARK: - SecondOrderSection Tests +@MainActor @Suite("SecondOrderSection") struct SecondOrderSectionTests { let blockSize: Int = 8 @@ -1176,6 +1189,7 @@ struct SecondOrderSectionTests { // MARK: - RBJBandPass Tests +@MainActor @Suite("RBJBandPass") struct RBJBandPassTests { let blockSize: Int = 512 @@ -1294,6 +1308,7 @@ struct RBJBandPassTests { // MARK: - Envelope.valueAtTime Tests +@MainActor @Suite("Envelope.valueAtTime") struct EnvelopeValueAtTimeTests { @@ -1423,6 +1438,7 @@ struct EnvelopeValueAtTimeTests { // MARK: - EnvelopeGen Tests +@MainActor @Suite("EnvelopeGen") struct EnvelopeGenTests { // blockSize=100, sampleRate=100 → 1s = 100 samples = 1 block, easy math @@ -1720,6 +1736,7 @@ struct EnvelopeGenTests { // MARK: - EnvelopeGen.Control Tests +@MainActor @Suite("EnvelopeGen.Control") struct EnvelopeGenControlTests { // blockSize=100, sampleRate=100 → 1s = 100 samples = 1 block @@ -1880,6 +1897,7 @@ struct EnvelopeGenControlTests { // MARK: - EnvelopeGen Gate / releaseNode Tests +@MainActor @Suite("EnvelopeGen.Gate") struct EnvelopeGenGateTests { // blockSize=100, sampleRate=100 → 1 sample = 0.01 s, 1 block = 1 s @@ -2142,6 +2160,7 @@ struct EnvelopeGenGateTests { // MARK: - EnvelopePoll Tests +@MainActor @Suite("EnvelopePoll") struct EnvelopePollTests { // blockSize=100, sampleRate=100 → 1 s = 100 samples; simple arithmetic @@ -2273,6 +2292,7 @@ struct EnvelopePollTests { // MARK: - Runtime Envelope Swap Tests +@MainActor @Suite("EnvelopeGen.SetEnvelope") struct EnvelopeGenSetEnvelopeTests { // blockSize=100, sampleRate=100 → 1 s = 100 samples per block @@ -2427,6 +2447,7 @@ struct EnvelopeGenSetEnvelopeTests { } } +@MainActor @Suite("EnvelopePoll.SetEnvelope") struct EnvelopePollSetEnvelopeTests { let engine: SynthesisEngine @@ -2488,6 +2509,7 @@ struct EnvelopePollSetEnvelopeTests { // MARK: - DelayLine Tests +@MainActor @Suite("DelayLine") struct DelayLineTests { let blockSize: Int = 64 @@ -2602,6 +2624,7 @@ struct DelayLineTests { // MARK: - DelayLineFeedback Tests +@MainActor @Suite("DelayLineFeedback") struct DelayLineFeedbackTests { let blockSize: Int = 64 @@ -2819,6 +2842,7 @@ private final class ImpulseAudioGen: GeneratorBase, AudioGenerator { // MARK: - Crackle Tests +@MainActor @Suite("Crackle") struct CrackleTests { let blockSize: Int = 256 @@ -2918,6 +2942,7 @@ struct CrackleTests { // MARK: - LFCurveNoise Tests +@MainActor @Suite("LFCurveNoise") struct LFCurveNoiseTests { // blockSize=100, sampleRate=100: simple math for step counts. diff --git a/Tests/LyrebirdTests/StepSequencerStructuralTests.swift b/Tests/LyrebirdTests/StepSequencerStructuralTests.swift index 164e511..5084190 100644 --- a/Tests/LyrebirdTests/StepSequencerStructuralTests.swift +++ b/Tests/LyrebirdTests/StepSequencerStructuralTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("StepSequencer — structural") struct StepSequencerStructuralTests { diff --git a/Tests/LyrebirdTests/StepSequencerTimingTests.swift b/Tests/LyrebirdTests/StepSequencerTimingTests.swift index 40469de..8ff431f 100644 --- a/Tests/LyrebirdTests/StepSequencerTimingTests.swift +++ b/Tests/LyrebirdTests/StepSequencerTimingTests.swift @@ -66,6 +66,7 @@ private func driveUntil( // MARK: - Tests +@MainActor @Suite("StepSequencer — timing") struct StepSequencerTimingTests { diff --git a/Tests/LyrebirdTests/SumChannelsAudioTests.swift b/Tests/LyrebirdTests/SumChannelsAudioTests.swift index 9c49e2f..7d88cc4 100644 --- a/Tests/LyrebirdTests/SumChannelsAudioTests.swift +++ b/Tests/LyrebirdTests/SumChannelsAudioTests.swift @@ -8,6 +8,7 @@ import Darwin import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("SumChannels.Audio") struct SumChannelsAudioTests { diff --git a/Tests/LyrebirdTests/Support/RTMarkTestHygiene.swift b/Tests/LyrebirdTests/Support/RTMarkTestHygiene.swift new file mode 100644 index 0000000..d9be3dc --- /dev/null +++ b/Tests/LyrebirdTests/Support/RTMarkTestHygiene.swift @@ -0,0 +1,27 @@ +// RTMarkTestHygiene.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Foundation +@testable import LyrebirdSynth + +/// Clear the `RTThreadIdentity` marker on the current thread. +/// +/// Driver render paths (`AUv3Driver.render`, `CoreAudioDriver.render`, …) call +/// `markCurrentThreadAsRT()` on entry — correct in production, where the render thread is a +/// dedicated, long-lived RT thread. Tests, however, drive those render paths synchronously +/// on a shared thread (the `@MainActor` main thread, or a cooperative-pool worker). The +/// marker then persists on that reused thread and can false-trip +/// `_lyrebirdAssertNotOnRTThread` in a later non-RT test (e.g. a `ValueComputable.compute()` +/// call) that the runtime hands the same thread. +/// +/// Any test that synchronously invokes a marking render path should call this afterwards +/// (typically via `defer` at the top of the test) so the thread is left clean. No-op in +/// release builds where the marker machinery compiles away. +func lyrebirdClearRTMarkAfterTestRender() { + #if DEBUG + RTThreadIdentity._clearCurrentThreadRTMarkForTesting() + #endif +} diff --git a/Tests/LyrebirdTests/SynthesisEngineConfigTests.swift b/Tests/LyrebirdTests/SynthesisEngineConfigTests.swift index fadfbb8..c8d0376 100644 --- a/Tests/LyrebirdTests/SynthesisEngineConfigTests.swift +++ b/Tests/LyrebirdTests/SynthesisEngineConfigTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - Pre-run config setters +@MainActor @Suite("Pre-run config setters") struct PreRunConfigSetterTests { @Test func setSampleRateWhenIdleUpdatesValue() throws { diff --git a/Tests/LyrebirdTests/SynthesisEngineStateListenerTests.swift b/Tests/LyrebirdTests/SynthesisEngineStateListenerTests.swift index a557c5c..8a4628d 100644 --- a/Tests/LyrebirdTests/SynthesisEngineStateListenerTests.swift +++ b/Tests/LyrebirdTests/SynthesisEngineStateListenerTests.swift @@ -87,6 +87,7 @@ private func isStopped(_ state: SynthesisEngineState) -> Bool { // MARK: - Tests +@MainActor @Suite("SynthesisEngineStateListener") struct SynthesisEngineStateListenerTests { diff --git a/Tests/LyrebirdTests/SynthesisEngineTests.swift b/Tests/LyrebirdTests/SynthesisEngineTests.swift index d420f68..e707d6c 100644 --- a/Tests/LyrebirdTests/SynthesisEngineTests.swift +++ b/Tests/LyrebirdTests/SynthesisEngineTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - Init State +@MainActor @Suite("Init state") struct InitStateTests { @Test func storesBlockSize() { let e: SynthesisEngine = makeTestEngine(blockSize: 256) @@ -46,6 +47,7 @@ import Testing // MARK: - Bus Allocation +@MainActor @Suite("Bus allocation") struct BusAllocationTests { @Test func audioBusCountAfterStart() throws { let e: SynthesisEngine = makeTestEngine(numAudioBuses: 128) @@ -81,6 +83,7 @@ import Testing // MARK: - Lifecycle +@MainActor @Suite("Lifecycle") struct LifecycleTests { @Test func isRunningAfterStart() throws { let e: SynthesisEngine = makeTestEngine() @@ -115,6 +118,7 @@ import Testing // MARK: - Bus Index Convention (SC layout) +@MainActor @Suite("Bus index convention") struct BusConventionTests { @Test func outputBusesAtIndexZero() throws { let e: SynthesisEngine = makeTestEngine(numOutputChannels: 2) @@ -145,6 +149,7 @@ import Testing // MARK: - processBlock Cycle Semantics +@MainActor @Suite("processBlock") struct ProcessBlockTests { @Test func audioBusesZeroedEachBlock() throws { let e: SynthesisEngine = makeTestEngine(blockSize: 4, numOutputChannels: 2, @@ -195,6 +200,7 @@ import Testing } } +@MainActor @Suite("pendingQueueDroppedCount") struct PendingQueueDropTests { private final class _Empty: SynthesizerBase { override func build() {} } diff --git a/Tests/LyrebirdTests/TemporalMarkovTests.swift b/Tests/LyrebirdTests/TemporalMarkovTests.swift index b935891..15b037c 100644 --- a/Tests/LyrebirdTests/TemporalMarkovTests.swift +++ b/Tests/LyrebirdTests/TemporalMarkovTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("TemporalMarkov") struct TemporalMarkovTests { diff --git a/Tests/LyrebirdTests/TemporalStreamTests.swift b/Tests/LyrebirdTests/TemporalStreamTests.swift index 23adc74..b2c80ff 100644 --- a/Tests/LyrebirdTests/TemporalStreamTests.swift +++ b/Tests/LyrebirdTests/TemporalStreamTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - TemporalParameter Tests +@MainActor @Suite("TemporalParameterTests") struct TemporalParameterTests { @@ -50,6 +51,7 @@ struct TemporalParameterTests { // MARK: - TemporalSequence Tests +@MainActor @Suite("TemporalSequenceTests") struct TemporalSequenceTests { @@ -121,6 +123,7 @@ struct TemporalSequenceTests { // MARK: - TemporalRandomPick Tests +@MainActor @Suite("TemporalRandomPickTests") struct TemporalRandomPickTests { @@ -162,6 +165,7 @@ struct TemporalRandomPickTests { // MARK: - TemporalTendency Tests +@MainActor @Suite("TemporalTendencyTests") struct TemporalTendencyTests { @@ -266,6 +270,7 @@ struct TemporalTendencyTests { // MARK: - TemporalBrownian Tests +@MainActor @Suite("TemporalBrownianTests") struct TemporalBrownianTests { @@ -354,6 +359,7 @@ struct TemporalBrownianTests { // MARK: - TemporalClosure Tests +@MainActor @Suite("TemporalClosureTests") struct TemporalClosureTests { @@ -413,6 +419,7 @@ struct TemporalClosureTests { // MARK: - TemporalStream Integration Tests +@MainActor @Suite("TemporalStreamTests") struct TemporalStreamTests { diff --git a/Tests/LyrebirdTests/ThreadSafetyTests.swift b/Tests/LyrebirdTests/ThreadSafetyTests.swift index df0cf2a..0c9ba3b 100644 --- a/Tests/LyrebirdTests/ThreadSafetyTests.swift +++ b/Tests/LyrebirdTests/ThreadSafetyTests.swift @@ -23,6 +23,7 @@ private struct UncheckedSendable: @unchecked Sendable { // MARK: - SPSC queue concurrency +@MainActor @Suite("SPSC queue concurrency") struct SPSCQueueConcurrencyTests { @@ -102,6 +103,7 @@ struct SPSCQueueConcurrencyTests { // MARK: - Parameter queue semantics +@MainActor @Suite("Parameter queue semantics") struct ParameterQueueSemanticsTests { @@ -200,6 +202,7 @@ struct ParameterQueueSemanticsTests { // MARK: - Graph modification queue semantics +@MainActor @Suite("Graph modification queue semantics") struct GraphModificationQueueSemanticsTests { @@ -281,6 +284,7 @@ struct GraphModificationQueueSemanticsTests { // MARK: - Concurrent parameter updates with processBlock +@MainActor @Suite("Concurrent parameter updates") struct ConcurrentParameterUpdateTests { diff --git a/Tests/LyrebirdTests/TimedDemandTests.swift b/Tests/LyrebirdTests/TimedDemandTests.swift index ec7a920..85c4b1e 100644 --- a/Tests/LyrebirdTests/TimedDemandTests.swift +++ b/Tests/LyrebirdTests/TimedDemandTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - RTTemporalParameter +@MainActor @Suite("RTTemporalParameter") struct RTTemporalParameterTests { @@ -63,6 +64,7 @@ struct RTTemporalParameterTests { // MARK: - TimedDemandGenerator bridge +@MainActor @Suite("TimedDemandGenerator bridge") struct TimedDemandGeneratorBridgeTests { @@ -103,6 +105,7 @@ struct TimedDemandGeneratorBridgeTests { // MARK: - TimedDemand.Audio +@MainActor @Suite("TimedDemand.Audio") struct TimedDemandAudioTests { @@ -298,6 +301,7 @@ struct TimedDemandAudioTests { // MARK: - TimedDemand.Control +@MainActor @Suite("TimedDemand.Control") struct TimedDemandControlTests { @@ -394,6 +398,7 @@ struct TimedDemandControlTests { // MARK: - DemandTemporalTendency +@MainActor @Suite("DemandTemporalTendency") struct DTemporalTendencyTests { @@ -549,6 +554,7 @@ struct DTemporalTendencyTests { // MARK: - DemandTemporalBrownian +@MainActor @Suite("DemandTemporalBrownian") struct DTemporalBrownianTests { diff --git a/Tests/LyrebirdTests/TriggerListenerTests.swift b/Tests/LyrebirdTests/TriggerListenerTests.swift index bc198a0..a5a0b62 100644 --- a/Tests/LyrebirdTests/TriggerListenerTests.swift +++ b/Tests/LyrebirdTests/TriggerListenerTests.swift @@ -8,6 +8,7 @@ import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("TriggerListener") struct TriggerListenerTests { diff --git a/Tests/LyrebirdTests/TriggeredRandomTests.swift b/Tests/LyrebirdTests/TriggeredRandomTests.swift index 52f43c5..a720a88 100644 --- a/Tests/LyrebirdTests/TriggeredRandomTests.swift +++ b/Tests/LyrebirdTests/TriggeredRandomTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("TriggeredRandom") struct TriggeredRandomTests { diff --git a/Tests/LyrebirdTests/TuneablePitchShiftTests.swift b/Tests/LyrebirdTests/TuneablePitchShiftTests.swift index 30051a6..34b3328 100644 --- a/Tests/LyrebirdTests/TuneablePitchShiftTests.swift +++ b/Tests/LyrebirdTests/TuneablePitchShiftTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("TuneablePitchShift") struct TuneablePitchShiftTests { diff --git a/Tests/LyrebirdTests/UnipolarRangeMapperTests.swift b/Tests/LyrebirdTests/UnipolarRangeMapperTests.swift index a03c6bd..ea9ed28 100644 --- a/Tests/LyrebirdTests/UnipolarRangeMapperTests.swift +++ b/Tests/LyrebirdTests/UnipolarRangeMapperTests.swift @@ -9,6 +9,7 @@ import Darwin import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("UnipolarRangeMapper — unipolar curve mapping") struct UnipolarRangeMapperTests { diff --git a/Tests/LyrebirdTests/ValidGeneratorInputTests.swift b/Tests/LyrebirdTests/ValidGeneratorInputTests.swift index 55c0334..fb1fbe6 100644 --- a/Tests/LyrebirdTests/ValidGeneratorInputTests.swift +++ b/Tests/LyrebirdTests/ValidGeneratorInputTests.swift @@ -7,6 +7,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("Double as ValidGeneratorInput") struct DoubleValidGeneratorInputTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -52,6 +53,7 @@ struct DoubleValidGeneratorInputTests { } } +@MainActor @Suite("Int as ValidGeneratorInput") struct IntValidGeneratorInputTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -80,6 +82,7 @@ struct IntValidGeneratorInputTests { } } +@MainActor @Suite("Closure as ValidGeneratorInput") struct ClosureTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) @@ -108,6 +111,7 @@ struct ClosureTests { } } +@MainActor @Suite("Generator as ValidGeneratorInput") struct GeneratorAsValidGeneratorInputTests { let engine: SynthesisEngine = makeTestEngine(blockSize: 8) diff --git a/Tests/LyrebirdTests/ValueCompute/RTThreadIdentityTests.swift b/Tests/LyrebirdTests/ValueCompute/RTThreadIdentityTests.swift index 22dab1b..65b35e1 100644 --- a/Tests/LyrebirdTests/ValueCompute/RTThreadIdentityTests.swift +++ b/Tests/LyrebirdTests/ValueCompute/RTThreadIdentityTests.swift @@ -5,6 +5,7 @@ // SPDX-License-Identifier: MIT import Testing +import Foundation import Darwin import Dispatch @testable import LyrebirdSynth @@ -27,13 +28,19 @@ struct RTThreadIdentityTests { #expect(RTThreadIdentity.isCurrentThreadRT == false) // Mark a *different* pthread, confirm via that thread's own read. - let markerSawRT: Bool = await withCheckedContinuation { continuation in - let queue: DispatchQueue = DispatchQueue(label: "RTThreadIdentityTests.marker") - queue.async { + // Use a one-shot detached `Thread` (NOT a `DispatchQueue`): a GCD worker pthread is + // recycled into the shared pool still carrying the RT marker, which can then + // false-trip `_lyrebirdAssertNotOnRTThread` in a later `.compute()` test the pool + // hands the same thread. A detached `Thread` terminates its pthread when the block + // returns, so the marker cannot leak; we also clear it defensively. + let markerSawRT: Bool = await withCheckedContinuation { (continuation: CheckedContinuation) in + let thread: Thread = Thread { RTThreadIdentity.markCurrentThreadAsRT() let observed: Bool = RTThreadIdentity.isCurrentThreadRT + lyrebirdClearRTMarkAfterTestRender() continuation.resume(returning: observed) } + thread.start() } #expect(markerSawRT == true) @@ -43,14 +50,16 @@ struct RTThreadIdentityTests { } @Test func markIsIdempotent() async { - let observedMarked: Bool = await withCheckedContinuation { continuation in - let queue: DispatchQueue = DispatchQueue(label: "RTThreadIdentityTests.idempotent") - queue.async { + let observedMarked: Bool = await withCheckedContinuation { (continuation: CheckedContinuation) in + let thread: Thread = Thread { RTThreadIdentity.markCurrentThreadAsRT() RTThreadIdentity.markCurrentThreadAsRT() RTThreadIdentity.markCurrentThreadAsRT() - continuation.resume(returning: RTThreadIdentity.isCurrentThreadRT) + let observed: Bool = RTThreadIdentity.isCurrentThreadRT + lyrebirdClearRTMarkAfterTestRender() + continuation.resume(returning: observed) } + thread.start() } #expect(observedMarked == true) } diff --git a/Tests/LyrebirdTests/ValueCompute/ValueComputableTests.swift b/Tests/LyrebirdTests/ValueCompute/ValueComputableTests.swift index 190ecbe..91286ac 100644 --- a/Tests/LyrebirdTests/ValueCompute/ValueComputableTests.swift +++ b/Tests/LyrebirdTests/ValueCompute/ValueComputableTests.swift @@ -7,6 +7,7 @@ import Testing @testable import LyrebirdSynth +@MainActor @Suite("ValueComputable") struct ValueComputableTests { diff --git a/Tests/LyrebirdTests/VectorOscillatorTests.swift b/Tests/LyrebirdTests/VectorOscillatorTests.swift index 3f09778..e08ea9c 100644 --- a/Tests/LyrebirdTests/VectorOscillatorTests.swift +++ b/Tests/LyrebirdTests/VectorOscillatorTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - VectorOscillatorTests +@MainActor @Suite("VectorOscillator") struct VectorOscillatorTests { diff --git a/Tests/LyrebirdTests/VoicePoolTests.swift b/Tests/LyrebirdTests/VoicePoolTests.swift index aeda21b..f75d6da 100644 --- a/Tests/LyrebirdTests/VoicePoolTests.swift +++ b/Tests/LyrebirdTests/VoicePoolTests.swift @@ -38,6 +38,7 @@ private func makePoolEngine() -> SynthesisEngine { // MARK: - Tests +@MainActor @Suite("VoicePool") struct VoicePoolTests { diff --git a/Tests/LyrebirdTests/WavetableMorphTests.swift b/Tests/LyrebirdTests/WavetableMorphTests.swift index 47fa7d0..386b702 100644 --- a/Tests/LyrebirdTests/WavetableMorphTests.swift +++ b/Tests/LyrebirdTests/WavetableMorphTests.swift @@ -9,6 +9,7 @@ import Testing // MARK: - WavetableMorphTests +@MainActor @Suite("WavetableMorph") struct WavetableMorphTests { diff --git a/Tests/LyrebirdTests/iOSAudioDriverTests.swift b/Tests/LyrebirdTests/iOSAudioDriverTests.swift index de84abb..0dc6b79 100644 --- a/Tests/LyrebirdTests/iOSAudioDriverTests.swift +++ b/Tests/LyrebirdTests/iOSAudioDriverTests.swift @@ -8,6 +8,7 @@ import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth +@MainActor @Suite("iOSAudioDriver") struct iOSAudioDriverTests { @Test func canInstantiate() { @@ -26,6 +27,7 @@ import Testing } } +@MainActor @Suite("iOSAudioError") struct iOSAudioErrorTests { @Test func instantiationFailedCarriesStatus() { diff --git a/Tests/LyrebirdUITests/LyrebirdEnvelopeViewTests.swift b/Tests/LyrebirdUITests/LyrebirdEnvelopeViewTests.swift index 369852e..e6ee3ba 100644 --- a/Tests/LyrebirdUITests/LyrebirdEnvelopeViewTests.swift +++ b/Tests/LyrebirdUITests/LyrebirdEnvelopeViewTests.swift @@ -10,6 +10,7 @@ import LyrebirdSynth // MARK: - _regionForSegment +@MainActor @Suite("_regionForSegment") struct RegionForSegmentTests { // No loop or release — everything is preLoop @@ -64,6 +65,7 @@ import LyrebirdSynth // MARK: - _segmentBoundaryTimes +@MainActor @Suite("_segmentBoundaryTimes") struct SegmentBoundaryTimesTests { @Test func emptyDurations_returnsOnlyZero() { @@ -97,6 +99,7 @@ import LyrebirdSynth // MARK: - _envelopeYBounds +@MainActor @Suite("_envelopeYBounds") struct EnvelopeYBoundsTests { @Test func emptyLevels_returnsDefaultRange() { @@ -134,6 +137,7 @@ import LyrebirdSynth // MARK: - Envelope.valueAtTime boundary sampling +@MainActor @Suite("Envelope valueAtTime edge cases for plotting") struct EnvelopeValueAtTimePlottingTests { @Test func clampsBelowZero_returnsFirstLevel() { diff --git a/Tests/LyrebirdUITests/LyrebirdSynthViewTests.swift b/Tests/LyrebirdUITests/LyrebirdSynthViewTests.swift index bdc28dc..afe35db 100644 --- a/Tests/LyrebirdUITests/LyrebirdSynthViewTests.swift +++ b/Tests/LyrebirdUITests/LyrebirdSynthViewTests.swift @@ -16,6 +16,7 @@ private final class UIParamSynth: SynthesizerBase { override func build() { output(bus: 0, source: 0.0) } } +@MainActor @Suite("LyrebirdSynthView") struct LyrebirdSynthViewTests { @Test func discoverEnumeratesOnlyUIParamSlots() { diff --git a/Tests/LyrebirdUITests/MultiSliderTests.swift b/Tests/LyrebirdUITests/MultiSliderTests.swift index 488ae38..5095cb1 100644 --- a/Tests/LyrebirdUITests/MultiSliderTests.swift +++ b/Tests/LyrebirdUITests/MultiSliderTests.swift @@ -8,6 +8,7 @@ import Testing @testable import LyrebirdUI import LyrebirdSynth +@MainActor @Suite("MultiSlider") struct MultiSliderTests { diff --git a/Tests/LyrebirdUITests/UIParamNodeTests.swift b/Tests/LyrebirdUITests/UIParamNodeTests.swift index 7948405..dff55f4 100644 --- a/Tests/LyrebirdUITests/UIParamNodeTests.swift +++ b/Tests/LyrebirdUITests/UIParamNodeTests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - Init +@MainActor @Suite("UIParamNode init") struct UIParamNodeInitTests { @Test func initialValueStoredAsObservable() { @@ -66,6 +67,7 @@ import Testing // MARK: - Atomic update round-trip +@MainActor @Suite("UIParamNode atomic update") struct UIParamNodeAtomicTests { @Test func updateSetsObservableValue() { @@ -112,6 +114,7 @@ import Testing // MARK: - calculatedSamples interpolation +@MainActor @Suite("UIParamNode calculatedSamples") struct UIParamNodeCalcTests { @Test func flatBlockWhenValueUnchanged() throws { @@ -202,6 +205,7 @@ import Testing // MARK: - ValidGeneratorInput wiring +@MainActor @Suite("UIParamNode as ValidGeneratorInput") struct UIParamNodeWiringTests { @Test func usableAsSourceParameter() throws { @@ -258,6 +262,7 @@ import Testing // MARK: - Source-swap +@MainActor @Suite("UIParamNode source swap") struct UIParamNodeSourceSwapTests { @Test func sourceAssignmentRoutesThroughCalculatedSamples() { diff --git a/Tests/LyrebirdUITests/UIParamTests.swift b/Tests/LyrebirdUITests/UIParamTests.swift index 5f8009b..93afc3c 100644 --- a/Tests/LyrebirdUITests/UIParamTests.swift +++ b/Tests/LyrebirdUITests/UIParamTests.swift @@ -10,6 +10,7 @@ import Testing // MARK: - @UIParam property wrapper +@MainActor @Suite("@UIParam property wrapper") struct UIParamTests { @Test func wrappedValueReturnsInitialValue() { @@ -102,6 +103,7 @@ import Testing // MARK: - @UIParam in a SynthesizerBase subclass +@MainActor @Suite("@UIParam in synthesizer") struct UIParamInSynthTests { final class ToneWithParam: SynthesizerBase { diff --git a/docs/00-working-order.md b/docs/00-working-order.md index 939b04a..f15547f 100644 --- a/docs/00-working-order.md +++ b/docs/00-working-order.md @@ -226,6 +226,216 @@ Full details in `docs/01-completed-working-order.md`. Phases ordered by dependency and value/effort. Each phase needs tests before moving on. +### Phase 201 — Swift 6 main-actor isolation for `Synthesizer` (zero-annotation consumer subclassing) + +**Goal.** A consumer building under Xcode 26's default +`SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` must be able to subclass +`SynthesizerBase` with **no concurrency annotations**: + +```swift +import LyrebirdSynth + +final class ToneSynth: SynthesizerBase { // no nonisolated, no @preconcurrency + @UIParam var freq: Double = 440 + override func build() { + output(bus: 0, source: OscSin.Audio(freq: $freq) * 0.2) + } +} +``` + +This must hold for the **core package, Quartet (local-path reference), and Test +(remote gitea reference)** simultaneously — those three are the acceptance gate. + +**Problem (reproduced).** Core compiles in Swift 5 language mode, so +`SynthesizerBase.build()` / `init()` are *nonisolated*. A consumer whose project +defaults to `@MainActor` makes its subclass's `build()`/`init()` main-actor +isolated → **"main actor-isolated method has different actor isolation from +nonisolated overridden declaration."** Today's only workarounds live on the +consumer (`nonisolated override func build()`, `@preconcurrency`, +`nonisolated override init()`) — exactly what we will not ship. Verified: no +core annotation that keeps `build` nonisolated fixes it (the consumer's own +default-isolation governs its own override declaration). The fix is to make the +*language-side* surface of `Synthesizer` **main-actor isolated** so the +consumer's MainActor default *matches* instead of conflicts, while the single +RT entry point (`evaluate`) stays `nonisolated`. + +**Isolation split — the core design.** `Synthesizer` has exactly one RT-thread +entry point; everything else is language-side (main thread): + +| Member | Thread | Phase 201 isolation | +|---|---|---| +| `build()` | main (called once at add) | `@MainActor` | +| `release(engine:)` | main only (doc-stated) | `@MainActor` | +| `free(engine:)` | main only (doc-stated) | `@MainActor` | +| `evaluate(graph:count:)` | **RT render thread** | **`nonisolated`** | +| `@LiveParam` / `@UIParam` setters | main / atomic store | inherit main; atomic store is already cross-thread-safe | + +`evaluate()` reads only two members: `parameterTable` (immutable `let`) and +`outputGenerators` (`var`, written in `build()` on main, read on RT after the +add-event barrier). Both are touched cross-thread **safely today** via the +engine's existing scheduling contract (the add event is applied on the RT thread +only after `build()` has fully returned on main — a happens-before edge through +the SPSC `pendingQueue`). Phase 201 makes that contract explicit to the compiler +with `nonisolated(unsafe)` on exactly those two stored properties, with a +comment citing the barrier. No new runtime synchronisation is added — the safety +argument is the one already in `ARCHITECTURE.md` §2/§9. + +**Plan of work.** + +1. **Protocol (`Synthesizer.swift`).** Annotate the protocol so language-side + requirements are `@MainActor` and `evaluate` is `nonisolated`. Options to + evaluate during implementation (pick whichever the compiler accepts most + cleanly): `@MainActor protocol Synthesizer` with `nonisolated func + evaluate(...)`, vs. per-requirement isolation. Update the default-extension + implementations (`evaluate` no-op, `release` throws, `free`) to match. + +2. **`SynthesizerBase.swift`.** Mark the class `@MainActor`. Mark + `evaluate(graph:count:)` `nonisolated final`. Mark `parameterTable` and + `outputGenerators` `nonisolated(unsafe)` (the only state `evaluate` reads), + each with a `// RT-read after add-barrier; see ARCHITECTURE.md §9` comment. + Confirm `@LiveParam`/`@UIParam` wrapper-backed properties still compile (the + earlier whole-class-`nonisolated` experiment failed *because* wrappers reject + `nonisolated`; `@MainActor` does not have that problem — verify). + +3. **`Group` / `ParallelGroup` (`NodeTree/`).** Both conform to `Synthesizer` + and call `evaluate` on the RT thread. Apply the same split: `build`/`release`/ + `free` main-actor, `evaluate` `nonisolated`. `ParallelGroup.evaluate` uses + `concurrentPerform` over children — confirm the child `evaluate` calls remain + `nonisolated` end-to-end (no hop). + +4. **Engine call sites.** `SynthesisEngine.processBlock` → `rootGroup.evaluate` + runs on the RT thread and must reach `evaluate` with no actor hop. Verify the + whole RT call chain (`processBlock` → `Group.evaluate` → + `synth.evaluate` → `Generator.calculatedSamples`) is `nonisolated`. The + engine itself is not an actor; ensure nothing forces a `MainActor.assumeIsolated` + or `await` onto the RT path (that would be a correctness/perf regression — a + hard fail for this phase). + +5. **Other in-core conformers.** Audit the conformers that implement + `Synthesizer` directly rather than via `SynthesizerBase` (e.g. `VoicePool`, + AUv3 `LyrebirdAudioUnit` / `LyrebirdAUVoicePoolBinding`, any others surfaced + by `grep ": Synthesizer"`). Each needs the same `evaluate`-nonisolated split. + AUv3 is the riskiest (its render block is already a separate isolation + domain) — give it explicit attention. + +6. **Language-mode decision.** Determine whether the core `LyrebirdSynth` target + should move to `.swiftLanguageMode(.v6)` (so the isolation is baked into the + module's binary interface and propagates to consumers regardless of their + mode) or stay `.v5` with explicit annotations. Prefer keeping `.v5` if + explicit `@MainActor`/`nonisolated` annotations suffice — a full v6 migration + of the whole module is a much larger lift and out of scope unless required to + make the consumer experience clean. **Spike this first** — it determines the + size of the rest of the phase. + +7. **`LyrebirdUI`.** Currently `.v5` to dodge SwiftUI/AppKit actor diagnostics. + `@UIParam` lives here. Confirm the isolation split doesn't force a `.v6` + migration of `LyrebirdUI`; if `@UIParam`-bearing synths need anything, capture + it. + +**Acceptance criteria (all three must pass with NO consumer-side concurrency +annotations):** + +- **Core:** `swift test --no-parallel` green; `(cd LiveCompile && swift test + --no-parallel)` 34/34. RT path verified to have no actor hop (inspect, and + confirm no perf regression on the core synthesis benchmark). +- **Quartet** (local-path ref): builds + runs; its `SynthesizerBase` subclasses + carry no `nonisolated`/`@preconcurrency`. Remove any such annotations Quartet + currently has and confirm it still builds. +- **Test** (remote gitea ref, Xcode-26 `MainActor` default): the plain + `final class ToneSynth: SynthesizerBase { override func build() {…} }` builds + and runs with zero annotations. Revert the `@preconcurrency` / + `nonisolated override init` / `nonisolated override func build` that + Claude-in-Xcode added. +- A **regression fixture**: an SPM consumer target built with + `-default-isolation MainActor` + `.swiftLanguageMode(.v6)` (the repro from + the Phase-201 investigation) compiles an unannotated `SynthesizerBase` + subclass. Keep this as a committed smoke test so the guarantee doesn't silently + regress. + +**Risks / watch-items.** +- `nonisolated(unsafe)` is a promise to the compiler — the `/lyrebird_review` + RT-safety pass must explicitly bless the two properties it lands on, citing the + add-barrier. Do not broaden it beyond `parameterTable` + `outputGenerators` + without re-justifying. +- If the protocol-level `@MainActor` forces awaits onto any existing internal + call site that currently runs sync on a background queue (routines, NRT batch), + that's in-scope to fix — those are language-side and can be `@MainActor` or + explicitly hopped, but must not touch the RT path. +- Docs: once landed, update `GettingStarted.md` / `INSTALLATION_AND_USAGE.md` to + show the clean zero-annotation subclass as *the* pattern, and drop the + interim "use `nonisolated final class`" guidance if it was added. + +**Branch:** `phase-201-mainactor-isolation` off `main`. Standard phase +checklist + `/lyrebird_review` before merge. After merge, re-snapshot to gitea +and re-tag (the gitea 1.0.0 is unreleased, so it can absorb this). + +**Investigation notes (from the session that wrote this plan — don't re-run these).** + +*Exact failure (reproduced).* Consumer error under Xcode 26 MainActor default: +``` +error: main actor-isolated instance method 'build()' has different actor isolation + from nonisolated overridden declaration +error: main actor-isolated initializer 'init()' has different actor isolation + from nonisolated overridden declaration +``` +Source: `SynthesizerBase.build()` / `init()` are nonisolated (core is Swift 5 +mode); consumer's project default makes the *subclass's* override `@MainActor`; +override-vs-base isolation mismatch. + +*Reproduction recipe (use verbatim as the Phase 201 regression fixture).* A +throwaway SPM consumer at `/tmp`, depending on the package via local path: +```swift +// Package.swift target settings that reproduce Xcode 26's new-project default: +swiftSettings: [ + .swiftLanguageMode(.v6), + .unsafeFlags(["-default-isolation", "MainActor"]), +] +``` +```swift +// Sources/App/main.swift — the unannotated subclass that MUST compile post-201: +import LyrebirdSynth +final class ToneSynth: SynthesizerBase { + override func build() { output(bus: 0, source: OscSin.Audio(freq: 440) * 0.2) } +} +let s = ToneSynth(); print("ok \(s)") +``` +Note: `.defaultIsolation(MainActor.self)` in the manifest is **unavailable** in +this SwiftPM toolchain (`error: 'defaultIsolation' is unavailable`) — must use +the raw `-default-isolation MainActor` unsafeFlag as above. + +*Approaches already tried and RULED OUT (don't repeat):* +1. `nonisolated` on base `init()` + `build()` — **fails.** Consumer's override + still gets `@MainActor` from its own project default; mismatch persists. (The + error even confirms the base is "nonisolated" — proving the problem is the + consumer side, not the base.) +2. `nonisolated` on the **class** declaration (`open nonisolated class + SynthesizerBase`) — **fails to compile core**: `'nonisolated' is not + supported on properties with property wrappers` (the `@LiveParam`/`@UIParam` + stored properties). Whole-class `nonisolated` is a dead end. +3. `nonisolated` on the **protocol requirement** (`Synthesizer.build`) + base — + **fails the same way** as (1). +4. `@MainActor` on the class + `nonisolated final func evaluate(...)` — **right + direction, but surfaced the real work**: 9 errors, all from `evaluate()` + reading `parameterTable` and `outputGenerators` from a nonisolated context + while the class is MainActor (`#ConformanceIsolation` + "main actor-isolated + property can not be referenced from a nonisolated context"). This is exactly + why the plan lands `nonisolated(unsafe)` on those **two** properties — they + are the entire RT-read surface of `evaluate()`. Nothing else in the class is + read on the RT thread. + +*Verified-working interim (NOT what we ship, but proves the seam):* the consumer +single-annotation form `nonisolated final class ToneSynth: SynthesizerBase { … }` +compiles cleanly (`Build complete`). Confirms one annotation on the *type* is +enough — Phase 201's job is to move that necessity into the core so the consumer +needs zero. + +*RT-read surface (confirmed by reading `evaluate()`):* `evaluate(graph:count:)` +references exactly `parameterTable` (immutable `let`) and `outputGenerators` +(`var`, written in `build()` on main, read on RT). No other stored property is +touched on the RT thread. The `nonisolated(unsafe)` blast radius is precisely +these two. + + ### Phase 104 — AUv3 Plugin Export Ship a `SynthesizerBase` subclass as an AudioUnit v3 (.appex) plugin loadable diff --git a/docs/01-completed-working-order.md b/docs/01-completed-working-order.md index 145b5f0..5ea190d 100644 --- a/docs/01-completed-working-order.md +++ b/docs/01-completed-working-order.md @@ -9852,3 +9852,79 @@ commits total; one session. - `8fb88e0` Phase 198.8-198.10: drop dead .duplicateDevice case, add F11 TODO, delete POST_197_FIXES.md - `216650a` Phase 198 review fix: Task.isCancelled guard for build-thrown CancellationError + regression test - `84961ae` Phase 198 re-review nits: rethrow caught CancellationError, robust >= 1 result count, onTermination comment + +--- + +## Phase 203 — `LiveCompile` UI to Swift 6 language mode + +**Goal.** Flip the last two `.swiftLanguageMode(.v5)` pins in the repo — +`LyrebirdLiveCompileUI` and `LyrebirdLiveCompileUITests` in +`LiveCompile/Package.swift` — to Swift 6 language mode, so the entire codebase +(core + UI + CLI + LiveCompile + tests + the regression-fixture consumer) is +uniformly v6 and can track Swift 7/8+. This is the only target left on `.v5` +after Phase 202; unlike `LyrebirdUI`/`LyrebirdCLI` (pure caution, flipped with +zero changes in 202), this one has a real — but small — concurrency issue. + +**The one real error (spiked + confirmed).** At v6 the only build error is: +``` +LyrebirdScratchModel.swift:149:31: error: sending 'self.session' risks causing +data races [#SendingRisksDataRace] +``` +`LyrebirdScratchModel` is `@MainActor` (an `ObservableObject`); its +`run(additive:)` calls `await session.compileAndRunAsync(...)`. `LiveSession` is +a plain non-`Sendable` `final class`, so passing it into the `nonisolated async` +method from the main actor (where it is also retained) is flagged as a send race. + +**The fix (minimal, spiked → 0 errors).** Mark `LiveSession` `@unchecked +Sendable`. It is already thread-safe by construction: +- `engine` + all `-I`/`-L`/`-l`/`rpath` config are immutable `let`. +- The only mutable graph state (`trackedSynths`, `loadedSnippets`) is guarded by + `trackingLock: NSLock` at every access (`track`, `clearTracked`, + `trackedSynthCount`, `runEntry`). +- `reportedSampleRate` / `lastSnippetMessage` are test-only side channels written + from the single in-flight snippet entry (documented one-invocation-at-a-time + precondition). + +Spike: `LiveSession: @unchecked Sendable` + flipping both UI targets to v6 → +`swift build --build-tests` reports **0 errors** for the `LiveCompile` sub-package. + +**Plan of work.** +1. **`LiveSession.swift`** — add `: @unchecked Sendable` to the class with a doc + block justifying it (immutable config + lock-guarded mutable state). Tighten + the two test-only side-channel `var`s: either guard them under `trackingLock` + too, or mark them clearly single-writer/test-only so the `@unchecked` promise + is fully accurate (decide during implementation — guarding is cheap and + removes the only unprotected `var`s). +2. **`LiveCompile/Package.swift`** — remove `.swiftLanguageMode(.v5)` from + `LyrebirdLiveCompileUI` and `LyrebirdLiveCompileUITests` (drop the trailing + comma on the preceding `path:` line, as in the Phase 202 flips). +3. **Verify snippet runtime threading.** `compileAndRunAsync` is `nonisolated`: + it compiles off-main via `Task.detached`, then resumes on the generic + executor (NOT the caller's main actor) to call `runEntry` → the snippet's + `context.play(...)`. `SnippetContext.play` is `@MainActor` (Phase 201). + Confirm a live snippet still adds synths correctly post-flip — either the + snippet path already hops correctly, or `runEntry`/`play` needs the + `lyrebirdRunMainActorMutation` bridge treatment. **Check this at runtime, not + just at compile time** (the doc comment claims "snippet entry executes on the + caller's actor" — verify that claim holds, since a `nonisolated async` method + does not resume on the caller's actor). +4. **Docs.** `LiveCompile/.../LiveCoding.md` and any LiveCompile README — drop + `.v5` mentions if present (none found in a quick grep, but recheck). + +**Acceptance.** +- `(cd LiveCompile && swift build)` and `(cd LiveCompile && swift test)` green at + v6 (current baseline: 36/36). +- A live-compiled snippet that calls `context.play(_:)` actually adds and renders + a synth (manual run of `LyrebirdScratchDemo`, or an integration test in + `LyrebirdLiveCompileTests` that drives `compileAndRunAsync` and asserts + `trackedSynthCount` increments). +- `grep -rn "swiftLanguageMode(.v5)"` across the repo (excl. `legacy/`, + `.build/`) returns **zero** hits. + +**Effort.** Small — likely a single-commit phase (one `@unchecked Sendable` line + +optional lock tidy + 2 Package.swift edits + a runtime-verification test). The +only open risk is item 3 (snippet `@MainActor play` from the off-main resume), +which the runtime check resolves. + +**Branch:** `phase-203-livecompile-swift6` off `main`. Standard checklist + +`/lyrebird_review` before merge. diff --git a/docs/tooling/targets.md b/docs/tooling/targets.md index 2c97914..a37bda3 100644 --- a/docs/tooling/targets.md +++ b/docs/tooling/targets.md @@ -30,7 +30,7 @@ Optional GUI module. Import alongside `Lyrebird` when you need parameter control import LyrebirdUI ``` -Provides: `LyrebirdWindow` (AppKit/SwiftUI host), `@SynthParam` property wrapper, and pre-built slider/knob views. Uses Swift 5 language mode to avoid actor-isolation diagnostics in SwiftUI/AppKit interop. +Provides: `LyrebirdWindow` (AppKit/SwiftUI host), `@SynthParam` property wrapper, and pre-built slider/knob views. Builds under Swift 6 language mode (Phase 202). **Rule:** never import `LyrebirdUI` in `Lyrebird` — GUI code must stay in this module only. @@ -49,7 +49,7 @@ lyrebird export MySynth # generate a SynthesizerBase template lyrebird repl # start Swift REPL with Lyrebird importable ``` -Provides an interactive `lyrebird>` shell (via LineNoise) with history and tab completion. Uses Swift 5 language mode — LineNoise predates Swift 6 concurrency annotations. +Provides an interactive `lyrebird>` shell (via LineNoise) with history and tab completion. Builds under Swift 6 language mode (Phase 202). See [cli-guide.md](cli-guide.md) for a full walkthrough. @@ -110,12 +110,12 @@ swift test ``` LyrebirdC └── Lyrebird (links CoreAudio, AudioToolbox, Accelerate) - ├── LyrebirdUI (SwiftUI + AppKit, Swift 5 mode) + ├── LyrebirdUI (SwiftUI + AppKit) ├── LyrebirdDemo ├── LyrebirdBenchmark └── LyrebirdUIDemo (also links LyrebirdUI) -LyrebirdCLI (links LineNoise, Swift 5 mode) +LyrebirdCLI (links LineNoise) ``` --- diff --git a/docs/ui/gui-system.md b/docs/ui/gui-system.md index 7ab6d84..47a5ec4 100644 --- a/docs/ui/gui-system.md +++ b/docs/ui/gui-system.md @@ -294,9 +294,10 @@ Sources/ └── ParameterLabel.swift ``` -`LyrebirdUI` uses `.swiftLanguageMode(.v5)` — the same rationale as `LyrebirdCLI` — -to avoid Swift 6 actor-isolation diagnostics in SwiftUI/AppKit interop until the -concurrency model for UI is fully audited. +`LyrebirdUI` builds under Swift 6 language mode (Phase 202) — cleanly, with no +actor-isolation diagnostics. The earlier `.swiftLanguageMode(.v5)` pin was removed once +the core `Synthesizer` isolation surface landed (Phase 201); the SwiftUI/AppKit interop +needed no special handling. --- diff --git a/scripts/check-swift6-consumer.sh b/scripts/check-swift6-consumer.sh new file mode 100755 index 0000000..9ed932c --- /dev/null +++ b/scripts/check-swift6-consumer.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# check-swift6-consumer.sh +# +# Phase 201/202 guard: proves the zero-annotation consumer guarantee still holds. +# +# Builds the committed regression fixture, an SPM consumer pinned to +# `.swiftLanguageMode(.v6)` + `-default-isolation MainActor` (Xcode 26's new-project +# default), which subclasses `SynthesizerBase` and overrides `build()` with NO concurrency +# annotations. If the core's `@MainActor` isolation surface ever regresses, this fails to +# compile with: +# "main actor-isolated instance method 'build()' has different actor isolation +# from nonisolated overridden declaration" +# +# Run manually or from CI. Exit 0 = guarantee intact. +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" + +echo "[1/2] Building core package under Swift 6 language mode..." +(cd "$ROOT" && swift build) + +echo "[2/2] Building zero-annotation MainActor-default consumer fixture..." +(cd "$ROOT/RegressionFixtures/MainActorConsumer" && swift build) + +echo "OK: Swift 6 + MainActor-default consumer compiles with zero annotations."