bugfixes, better MusicXML support and 1.1.0

This commit is contained in:
2026-06-10 08:41:07 -07:00
parent 6d3a0930a1
commit f59fd3b55a
228 changed files with 32271 additions and 2586 deletions
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 142 core
// LyrebirdLiveCompile — core
//
// `CompiledSnippet` owns the `dlopen` handle and the resolved entry function
// pointer for one snippet's dylib. Held by the live session for the lifetime of
@@ -35,7 +35,7 @@ public final class CompiledSnippet: @unchecked Sendable {
/// Path to the dylib that was `dlopen`'d.
public let dylibPath: String
/// Resolved entry function pointer. Calling this is Phase 143's job.
/// Resolved entry function pointer. The snippet harness calls this.
public let entry: SnippetEntry
/// Raw `dlopen` handle. Kept so the OS keeps the dylib mapped.
@@ -4,13 +4,13 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 144
// LyrebirdLiveCompile
//
// One parsed `swiftc` diagnostic, with `line` already mapped from the wrapped-
// snippet coordinate space back to the user's snippet coordinate space (via the
// `userBodyLineOffset` from `SnippetHarness.wrap(userBody:)`).
//
// The editor in Phase 145 (`LyrebirdScratchView`) renders diagnostics in its
// The editor (`LyrebirdScratchView`) renders diagnostics in its
// margin gutter using `(line, column)` directly.
#if os(macOS)
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 144
// LyrebirdLiveCompile
//
// `DiagnosticParser.parse(stderr:userBodyLineOffset:)` walks the swiftc stderr
// stream line by line, extracts diagnostics matching the standard
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 144
// LyrebirdLiveCompile
//
// Severity classifier for a parsed swiftc diagnostic line.
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 142 core
// LyrebirdLiveCompile — core
//
// Errors raised by `LiveCompiler.compile(source:)`. RT path never sees these:
// compilation is a main-thread (or background-queue) operation that runs long
@@ -4,12 +4,12 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 142 core
// LyrebirdLiveCompile — core
//
// `LiveCompiler.compile(source:)` shells out to `swiftc -emit-library`, then
// `dlopen`s the resulting dylib and resolves the snippet entry symbol. No UI,
// no `SynthesisEngine` binding (those land in phases 143–146). macOS only —
// iOS cannot exec swiftc.
// no `SynthesisEngine` binding (those are handled by the harness and session
// layers). macOS only — iOS cannot exec swiftc.
import Foundation
#if os(macOS)
@@ -34,8 +34,8 @@ public enum LiveCompiler {
///
/// - Parameters:
/// - source: Full Swift source, including the `@_cdecl("lyrebird_snippet_entry")`
/// entry. Phase 143's `SnippetHarness` will wrap user input in a preamble that
/// provides this; Phase 142 callers (incl. tests) write the full file.
/// entry. `SnippetHarness` wraps user input in a preamble that provides
/// this; direct callers (incl. tests) write the full file.
/// - extraSwiftcArgs: Extra args appended to the `swiftc` invocation. Tests use
/// this for `-suppress-warnings` etc. Production callers leave empty.
/// - Returns: `CompiledSnippet` holding the dlopen handle and entry pointer.
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 143
// LyrebirdLiveCompile
//
// `LiveSession` owns the `SynthesisEngine` and tracks every `Synthesizer` that
// each snippet `play(_:)`s, so the next non-additive re-evaluation can
@@ -23,7 +23,7 @@ import LyrebirdSynth
/// Snippets receive a `SnippetContext` bound to this session through
/// `compileAndRun(_:additive:)`.
///
/// `@unchecked Sendable` (Phase 203): a `LiveSession` is shared between its `@MainActor`
/// `@unchecked Sendable`: 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:
///
@@ -70,7 +70,7 @@ public final class LiveSession: @unchecked Sendable {
engine: SynthesisEngine,
importPaths: [URL] = LiveSession.defaultImportPaths(),
librarySearchPaths: [URL] = LiveSession.defaultLibrarySearchPaths(),
libraries: [String] = ["LyrebirdDynamic", "LyrebirdLiveCompile"],
libraries: [String] = ["LyrebirdDynamic", "LyrebirdLiveCompileDynamic"],
rpaths: [URL] = LiveSession.defaultRpaths()
) {
self.engine = engine
@@ -91,7 +91,7 @@ public final class LiveSession: @unchecked Sendable {
/// (⌘⇧↩ 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`: 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.
@@ -112,8 +112,8 @@ public final class LiveSession: @unchecked Sendable {
/// 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
/// Running the entry on the main actor matters: the snippet's
/// `context.play(_:)` calls `engine.add(_:)`, which is `@MainActor` 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.
@@ -288,7 +288,7 @@ public final class LiveSession: @unchecked Sendable {
///
/// Searches, in order:
/// 1. Walks up from `Bundle(for: LiveSession.self).bundleURL` — this resolves
/// to the directory holding `libLyrebirdLiveCompile.dylib` at runtime,
/// to the directory holding `libLyrebirdLiveCompileDynamic.dylib` at runtime,
/// which is the SPM debug/release dir.
/// 2. Walks up from `Bundle.main.executableURL` — fallback for the case
/// where the host bundles the dylibs into an `.app`.
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 144
// LyrebirdLiveCompile
//
// `LiveSession.compileAndRun(_:additive:)` throws this richer error so callers
// see diagnostics pre-mapped to user-snippet coordinates. Other `LiveCompileError`
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 143
// LyrebirdLiveCompile
//
// `SnippetContext` is the public API surface the user's snippet talks to. The
// host (via `LiveSession.compileAndRun`) constructs one of these, passes the
@@ -4,16 +4,15 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 142 core
// LyrebirdLiveCompile — core
//
// C ABI signature of the snippet's exported entry point.
#if os(macOS)
/// Snippets export this symbol via `@_cdecl("lyrebird_snippet_entry")`. Phase
/// 143 will pass a pointer to a `LiveSession` (or harness context) here;
/// Phase 142 only requires that snippets can declare a function matching this
/// signature.
/// Snippets export this symbol via `@_cdecl("lyrebird_snippet_entry")`. The host
/// passes a pointer to a `LiveSession` (or harness context) here; snippets need
/// only declare a function matching this signature.
public typealias SnippetEntry = @convention(c) (UnsafeMutableRawPointer?) -> Void
#endif
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 143
// LyrebirdLiveCompile
//
// `SnippetHarness.wrap(userBody:)` produces the full Swift source that
// `LiveCompiler.compile(source:)` feeds to swiftc. The preamble imports the
@@ -18,9 +18,9 @@ public enum SnippetHarness {
/// Wraps `userBody` in the standard preamble.
///
/// The user body runs inside `MainActor.assumeIsolated { … }` (Phase 203): snippets call
/// The user body runs inside `MainActor.assumeIsolated { … }`: snippets call
/// `@MainActor` API — `context.play(_:)` and `SynthesizerBase` subclass construction
/// (both `@MainActor` since Phase 201) — which would not compile from the nonisolated
/// (both `@MainActor`) — 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`;
@@ -4,11 +4,11 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdLiveCompile — Phase 143
// LyrebirdLiveCompile
//
// Output of `SnippetHarness.wrap(userBody:)`. Carries the full Swift source
// that `swiftc` will compile, plus the 1-based line number on which the user's
// body begins. Phase 144's diagnostic parser subtracts `userBodyLineOffset - 1`
// body begins. The diagnostic parser subtracts `userBodyLineOffset - 1`
// from each swiftc-reported line so error rows point back at the row the user
// typed.
@@ -1,86 +0,0 @@
# Live coding with `LyrebirdScratchView`
A SwiftUI scratchpad for hot-swapping snippets through `LyrebirdLiveCompile`.
## Overview
`LyrebirdScratchView` pairs an `NSTextView`-backed Swift editor with a `LiveSession`
that owns the audio engine. Pressing **⌘↩** wraps the snippet body in the standard
harness, shells out to `swiftc`, `dlopen`s the resulting dylib, and calls the
snippet's `lyrebird_snippet_entry` with a `SnippetContext` bound to the session.
Synthesizers played via `context.play(_:)` are tracked, so the next non-additive
run replaces them. **⌘⇧↩** layers a new snippet on top of the prior ones.
Compile diagnostics from a failing snippet are parsed by `DiagnosticParser`
and rendered beneath the editor with line numbers already remapped from the wrapped
source back to the user's snippet coordinates.
The view is macOS-only — `LyrebirdLiveCompile` shells out to `swiftc`, which is
unavailable on iOS. The nested `LiveCompile/` sub-package declares
`platforms: [.macOS(.v15)]` and cannot be added to an iOS target.
## Hosting
```swift
import LyrebirdSynth
import LyrebirdUI // LyrebirdWindow
import LyrebirdLiveCompile // LiveSession
import LyrebirdLiveCompileUI // LyrebirdScratchView
let engine = SynthesisEngine(/* … */)
try engine.start()
let session = LiveSession(engine: engine)
let window = LyrebirdWindow(title: "Lyrebird Scratch", width: 640, height: 480)
window.open {
LyrebirdScratchView(session: session)
}
```
## Keyboard shortcuts
| Shortcut | Action |
|----------|--------|
| ⌘↩ | Compile + run. Removes synths from the previous run before executing. |
| ⌘⇧↩ | Compile + run additively. Keeps previously played synths in the engine. |
The toolbar exposes both as buttons plus a `Clear Synths` button that calls
`LiveSession.clearTracked()` directly.
## Snippet API surface
A snippet has one local in scope:
```swift
context: SnippetContext
```
`SnippetContext` is intentionally minimal in v1:
- `context.engine` — the host `SynthesisEngine`.
- `context.play(_:)` — add a `Synthesizer` to the engine and register it for
cleanup on the next non-additive run.
- `context.reportMessage(_:)` — write back to the host (used by tests; handy for
`print`-style probes during development).
## Threading
All UI is `@MainActor`-isolated. `LiveSession.compileAndRun` is invoked
synchronously inside the button action, so the editor freezes for the duration
of the `swiftc` invocation (≈ 1 second cold, much faster on warm cache). v1
accepts that trade-off; an off-main compile path is on the polish list.
## Limitations
- macOS only.
- No syntax highlighting, code completion, or line-number gutter (deferred).
- Compiled dylibs are leaked by design — types in a loaded snippet may still be
referenced by tracked synths; unloading is unsafe.
- The host `.app` must not be sandboxed and must allow library validation to be
disabled, since `swiftc` is invoked via `Process` and the resulting unsigned
dylib is `dlopen`'d.
## Topics
- ``LyrebirdScratchView``
- ``LyrebirdScratchModel``
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdUI/LiveCompile — Phase 145
// LyrebirdUI/LiveCompile
//
// Backing model for `LyrebirdScratchView`. Owns the editable snippet text, the
// most recent compile result, and the host `LiveSession`. Pulled out of the
@@ -16,7 +16,11 @@
import Foundation
import CoreGraphics
import LyrebirdSynth
import LyrebirdLiveCompile
// Re-exported so consumers that link only the `LyrebirdLiveCompileUI` product
// (e.g. the LyrebirdScratchDemo app) get the `LyrebirdLiveCompile` API
// (`LiveSession`, …) without separately linking the `LyrebirdLiveCompile`
// dynamic product — which clashes in Xcode with the static target embed.
@_exported import LyrebirdLiveCompile
/// Observable backing model for `LyrebirdScratchView`.
///
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdUI/LiveCompile — Phase 145
// LyrebirdUI/LiveCompile
//
// `LyrebirdScratchView` — SwiftUI scratchpad editor for live-coded snippets.
// Wraps an `NSTextView` for the editor surface, drives a `LyrebirdScratchModel`
@@ -4,7 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// LyrebirdUI/LiveCompile — Phase 147
// LyrebirdUI/LiveCompile
//
// Vertical line-number gutter for `ScratchEditor`'s `NSTextView`. Installed as
// the scroll view's `verticalRulerView` so it tracks scroll position for free.