Lyrebird 2.0.0 — Linux support
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+781
@@ -0,0 +1,781 @@
|
||||
<!--
|
||||
LINUX_PLAN.md
|
||||
Lyrebird
|
||||
Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
SPDX-License-Identifier: MIT
|
||||
-->
|
||||
|
||||
# Lyrebird — Linux Support Plan
|
||||
|
||||
Hand-off plan for finishing Linux support. Branch:
|
||||
`feasibility/cross-platform-linux-windows`. Companion docs:
|
||||
`docs/cross-platform-feasibility.md` (how the port was done) and
|
||||
`docs/windows-support-plan.md` (Windows, deferred).
|
||||
|
||||
**A next agent can pick this up cold from this file.** Every item lists what,
|
||||
why, where (paths), first steps, and an acceptance check.
|
||||
|
||||
---
|
||||
|
||||
## 1. Current state (what already works)
|
||||
|
||||
The whole non-UI toolchain **cross-compiles to Linux**, verified from macOS:
|
||||
|
||||
| Target | musl SDK | glibc SDK |
|
||||
|---|---|---|
|
||||
| `LyrebirdSynth` (core engine + generators) | ✅ | ✅ |
|
||||
| `LyrebirdGraphDSL` | ✅ | ✅ |
|
||||
| `LyrebirdCLI` | ✗ (LineNoise `import Glibc`) | ✅ |
|
||||
|
||||
macOS/iOS builds are **byte-identical** to before the port (all Apple-only code
|
||||
is behind `#if canImport(...)` or re-exported by `LyrebirdDSP`). Full macOS
|
||||
suite (5644 tests) passes; the branch passed `/lyrebird_review` twice.
|
||||
|
||||
**Architecture that made this work** (do not undo):
|
||||
- `Sources/LyrebirdDSP/` — a target that `@_exported import`s Accelerate + the
|
||||
platform C-lib on Apple, and supplies portable scalar/FFT/biquad/vForce
|
||||
fallbacks off Apple. Generator/synth code writes `import LyrebirdDSP` (never
|
||||
`import Accelerate`/`import Darwin`) and carries **zero** platform `#if`.
|
||||
- Portable WAV codec (`Sources/Lyrebird/Buffers/Wav*.swift`) replaces
|
||||
`ExtAudioFile` off Apple.
|
||||
- Platform-abstraction files keep their own local `#if`: `MonotonicClock.swift`,
|
||||
`RTThreadIdentity.swift`, `PlatformCompat.swift` (OSStatus shim),
|
||||
`AudioFileFormat+AudioToolbox.swift`.
|
||||
|
||||
### How to build / verify Linux locally (from a Mac)
|
||||
|
||||
Two cross-compile SDKs are installed (reusable):
|
||||
|
||||
```bash
|
||||
# musl (static single binary; best for the core library)
|
||||
TC=~/Library/Developer/Toolchains/swift-6.3.3-RELEASE.xctoolchain/usr/bin/swift
|
||||
$TC build --swift-sdk aarch64-swift-linux-musl --target LyrebirdSynth --scratch-path .build-linux
|
||||
|
||||
# glibc / Ubuntu 24.04 (the target for CLI + real distros)
|
||||
$TC build --swift-sdk 6.3.3-RELEASE_ubuntu_noble_aarch64 --target LyrebirdCLI --scratch-path .build-glibc
|
||||
```
|
||||
|
||||
**Critical:** use the **swift.org** toolchain (path above), NOT Xcode's — the
|
||||
Static Linux SDK's `Foundation.swiftmodule` was built by swift.org's compiler and
|
||||
a mismatch buries the real errors under ~1244 bogus "Foundation compiled by older
|
||||
compiler" errors.
|
||||
|
||||
The glibc SDK was generated with `swift-sdk-generator` (swift.org ships no
|
||||
prebuilt glibc bundle). To regenerate:
|
||||
`swift run swift-sdk-generator make-linux-sdk --distribution-name ubuntu --distribution-version 24.04 --swift-version 6.3.3-RELEASE`.
|
||||
|
||||
### Standing maintenance — after every `git merge main`
|
||||
|
||||
New generators land on main importing `Darwin`/`Accelerate` directly, which
|
||||
breaks Linux. Every merge:
|
||||
|
||||
```bash
|
||||
# 1. migrate any new unguarded imports to LyrebirdDSP:
|
||||
grep -rlnE "^import Accelerate|^import Darwin" Sources/Lyrebird --include='*.swift'
|
||||
# (skip RTThreadIdentity / MonotonicClock / DiskOutError — their Darwin is guarded)
|
||||
# 2. new direct `stderr` / `fputs` usage breaks Linux — Swift 6 flags the imported
|
||||
# C `stderr` global as "not concurrency-safe". Use the portable helper instead:
|
||||
# core -> lyrebirdPrintError(_:) (Sources/Lyrebird/Utilities/StandardError.swift)
|
||||
# LyrebirdCLI -> printError(_:) (Sources/LyrebirdCLI/StandardError.swift)
|
||||
grep -rnE "\bfputs\b|\bstderr\b" Sources/Lyrebird Sources/LyrebirdCLI --include='*.swift'
|
||||
# 3. delete Finder sync cruft that appears during merges:
|
||||
find Sources Tests -regex '.* [0-9]+\.swift' -delete
|
||||
# 4. rebuild Linux to confirm — cross-compile (both SDKs) AND, when Docker is
|
||||
# available, run the suite natively (matches CI exactly). The stock swift
|
||||
# image has no ALSA headers, so either add them (needed to compile
|
||||
# ALSAAudioDriver) or opt out:
|
||||
# docker build -t lyrebird-alsa - <<'DOCKERFILE'
|
||||
# FROM swift:6.3.3
|
||||
# RUN apt-get update && apt-get install -y --no-install-recommends libasound2-dev pkg-config
|
||||
# DOCKERFILE
|
||||
# docker run --rm -v "$PWD":/pkg -w /pkg lyrebird-alsa swift test
|
||||
# # …or, without the ALSA package:
|
||||
# docker run --rm -e LYREBIRD_DISABLE_ALSA=1 -v "$PWD":/pkg -w /pkg swift:6.3.3 swift test
|
||||
```
|
||||
|
||||
**Scaffolded projects need their own check.** `swift test` never compiles the
|
||||
source the CLI *emits*, so template regressions are invisible to it — that is
|
||||
how the `nrt`/`score` templates came to reference a `LyrebirdCLI`-internal
|
||||
symbol, and how they kept rendering to CAF (an Apple-only container that throws
|
||||
off Apple) while still compiling. The gated suite builds **and runs** every SPM
|
||||
template against this checkout:
|
||||
|
||||
```bash
|
||||
LYREBIRD_RUN_BUILD_TESTS=1 swift test --no-parallel --filter ProjectScaffolderBuild
|
||||
# …and inside the Linux container, where it matters most:
|
||||
# docker run --rm -v "$PWD":/pkg -w /pkg lyrebird-alsa \
|
||||
# bash -c 'LYREBIRD_RUN_BUILD_TESTS=1 swift test --no-parallel --filter ProjectScaffolderBuild'
|
||||
```
|
||||
|
||||
Run it after touching `ProjectScaffolder` or any public API a template uses.
|
||||
|
||||
**Two arch/build gotchas the CI bring-up already paid for:**
|
||||
|
||||
- **BitBucket runners are x86_64; the Mac + its local Docker are arm64.** Some
|
||||
breakage is x86-only and invisible on an arm64 box — e.g. C code that uses a
|
||||
Darwin-only `<fenv.h>` macro under an `#if defined(__x86_64__)` branch compiles
|
||||
on arm64 Linux (wrong branch, and note Linux arm64 predefines `__aarch64__`,
|
||||
**not** Apple's `__arm64__`) but breaks on x86 glibc. To reproduce CI exactly,
|
||||
emulate the runner arch locally:
|
||||
`docker run --rm --platform linux/amd64 -v "$PWD":/pkg -w /pkg swift:6.3.3 swift test`.
|
||||
- **A library-only build does not compile C target sources — only headers.**
|
||||
`swift build --target LyrebirdSynth` (a library) will not surface a bad
|
||||
`Sources/LyrebirdC/*.c`; the `.c` is compiled only when an executable/test
|
||||
links it. So the build *gate* can be green while `swift test` fails. Always
|
||||
verify with `swift test` (which links), not just the build gate.
|
||||
|
||||
### Verifying on macOS: always `swift test --no-parallel`
|
||||
|
||||
Plain `swift test` on macOS reports **~45 failures** on a clean tree. They are
|
||||
**not real** — `--no-parallel` is the project's canonical command
|
||||
(`docs/00-working-order.md` step 1) and the full suite passes under it.
|
||||
|
||||
The flakes are main-thread starvation, concentrated in `LyrebirdProcess`,
|
||||
`LyrebirdEventList*`, `RoutineTests` and `ActorIsolationGuardTests`: those tests
|
||||
dispatch to the main queue and then wait on a wall-clock timeout, while the
|
||||
parallel runner has `@MainActor` suites saturating main. Recognisable by the
|
||||
message shape — `got 0 of 3`, `.timedOut`, `Body should have entered`,
|
||||
`Expected ~0.2s between events, got 2.3s` — never a wrong numeric result.
|
||||
Parallel is also *slower* here (≈286 s vs ≈94 s), so there is no reason to use
|
||||
it. Phase 148 fixed an earlier batch in these same suites; residual
|
||||
parallel-only flakes are recorded in `docs/01-completed-working-order.md`.
|
||||
|
||||
**Do not debug these before re-running serially.** If a failure is suspected to
|
||||
be real, the cheap discriminator is a clean-tree baseline: `git worktree add
|
||||
<tmp> HEAD` and run the same command there — a failure present at HEAD is not
|
||||
yours.
|
||||
|
||||
Linux in-container runs (`docker run … swift test`) have not shown this; the
|
||||
affected suites are macOS-host-only, so CI is unaffected.
|
||||
|
||||
### IDE for Linux
|
||||
**VS Code + the official Swift extension** (`swiftlang.swift-vscode`) —
|
||||
SourceKit-LSP, LLDB, test explorer, SPM. Best-maintained non-Xcode path.
|
||||
|
||||
---
|
||||
|
||||
## 2. Remaining work — prioritized
|
||||
|
||||
Ordered by value for a *usable* Linux Lyrebird. Items 1–3 make it real; 4–8 are
|
||||
capability/coverage.
|
||||
|
||||
**Status board** (update the box when an item lands; each item's own heading
|
||||
carries the same marker):
|
||||
|
||||
| # | Item | Priority | Status |
|
||||
|---|---|---|---|
|
||||
| 3 | Linux CI lane | HIGH | ✅ done — green on BitBucket |
|
||||
| 2 | Golden DSP tests on Linux | HIGH | ✅ done — 6 goldens green in CI |
|
||||
| 1 | `ALSAAudioDriver` (live audio) | HIGH | ◑ plays on hardware; deeper checks pending |
|
||||
| 6 | DiskIn + buffer file I/O | MEDIUM | ✅ done — WavFileReader backend |
|
||||
| 4 | MIDI on Linux | MEDIUM | ⚠️ built, untested on hardware |
|
||||
| 5 | OSC on Linux | MEDIUM | ✅ done — POSIX UDP, loopback-verified |
|
||||
| 8 | SwiftOpenUI GUI spike | EXPLORATION | ✅ drag works on hardware (@State + @Observable patch); patch PR-ready |
|
||||
| 7 | CLI on musl (LineNoise) | LOW | ☐ decision |
|
||||
|
||||
### Item 1 — `ALSAAudioDriver` (live audio) — HIGH — ⚠️ BUILT, NOT YET HEARD
|
||||
**What:** A driver conforming to `AudioDriver` that opens a Linux audio device
|
||||
and calls `engine.processBlock(inputSamples:)` from a render thread.
|
||||
**Why:** Without it, Linux only does offline NRT-to-WAV. This is the capability
|
||||
that makes Linux usable.
|
||||
**Delivered:** `Sources/Lyrebird/AudioDrivers/ALSAAudioDriver.swift` — a
|
||||
blocking `snd_pcm_writei` loop on a dedicated thread, the shape the plan
|
||||
recommended (no callback re-entrancy, no ALSA async-handler restrictions,
|
||||
back-pressure straight from the device). **Full reference:
|
||||
`docs/engine/alsa-audio-driver.md`** — transport, duplex, xrun policy,
|
||||
lifecycle, and the build requirement; that document is canonical, this section
|
||||
is the plan-level summary.
|
||||
|
||||
**Do not name a driver in portable code** — call `makeDefaultAudioDriver()`
|
||||
(`AudioDrivers/DefaultAudioDriver.swift`), which resolves to `iOSAudioDriver` /
|
||||
`CoreAudioDriver` / `ALSAAudioDriver` / `OfflineDriver` from *inside* the
|
||||
module. Which drivers exist is not a function of the OS alone (a Linux build
|
||||
without libasound, or one cross-compiled from macOS, has no ALSA), so a
|
||||
consumer-side `#if` is guessing. `isLiveAudioAvailable` reports whether the
|
||||
build has any live backend at all.
|
||||
|
||||
- **Format** `SND_PCM_FORMAT_FLOAT_LE`, matching the engine's `Float` buses, so
|
||||
nothing in the path converts or dithers.
|
||||
- **Setup** via `snd_pcm_set_params` (ALSA's own convenience over the
|
||||
hw/sw-params dance), latency = `blockSize × periodsPerBuffer / sampleRate`.
|
||||
- **Duplex** when the engine asks for input channels: a capture PCM is opened
|
||||
and `snd_pcm_link`ed to playback so the two cannot drift; `linkedStreams`
|
||||
reports whether the kernel accepted the link.
|
||||
- **RT thread** marks itself via `RTThreadIdentity.markCurrentThreadAsRT()`,
|
||||
calls `enableFlushToZero()`, and requests `SCHED_FIFO` at 75 % of the policy
|
||||
range — denial is normal for an unprivileged process and is reported through
|
||||
`hasRealtimePriority` rather than failing the start.
|
||||
- **No allocation in the loop**: interleave/deinterleave staging buffers are
|
||||
raw pointers allocated in `setup(engine:)`.
|
||||
- **Xrun policy** is factored out into `ALSARecoveryAction.classify(_:)` —
|
||||
`-EINTR`/`-EAGAIN` retry, `-EPIPE`/`-ESTRPIPE` recover via `snd_pcm_recover`,
|
||||
anything else stops the loop and lands in `lastError`. The errno values are
|
||||
spelled out as Linux constants rather than taken from the host's `errno.h`,
|
||||
so the classification cannot differ per platform (`EAGAIN` is 11 on Linux, 35
|
||||
on Darwin) and the tests mean the same thing everywhere.
|
||||
|
||||
**Build requirement — libasound2-dev.** The `CALSA` system-library target
|
||||
(`Sources/CALSA/`) needs ALSA's headers. `Package.swift` adds that target only
|
||||
when the manifest is evaluated **on a Linux host**, so:
|
||||
- macOS/iOS builds never see it (verified: `swift build`/`swift test` unchanged).
|
||||
- **Cross-compiling to Linux from a Mac produces a binary with no live-audio
|
||||
driver** — the host is macOS, so `CALSA` is absent and the driver compiles
|
||||
away. Build natively on Linux to get audio out; cross-compiles remain
|
||||
offline-only.
|
||||
- A native Linux build without the package fails with
|
||||
`error: 'alsa/asoundlib.h' file not found` → `could not build C module 'CALSA'`.
|
||||
Fix: `apt-get install libasound2-dev pkg-config`, which the CI lane now does.
|
||||
Escape hatch for a box that deliberately has no audio stack:
|
||||
`LYREBIRD_DISABLE_ALSA=1 swift build` (verified — everything but the driver
|
||||
builds).
|
||||
|
||||
**Verified (headless):** 11 new tests in `LyrebirdPortableTests`, green on
|
||||
macOS and on Linux arm64 + x86_64:
|
||||
- interleave/deinterleave: frame order, missing channel → silence, short bus →
|
||||
padded, round-trip identity, extra channel dropped (all platforms — a
|
||||
transposed index here yields channel-swapped audio, not an error, which is
|
||||
exactly what nobody notices on a headless box);
|
||||
- `ALSARecoveryAction` classification of every branch (all platforms);
|
||||
- Linux-only: `start()` before `setup` throws `.notConfigured`; an unopenable
|
||||
device throws `.playbackDeviceOpenFailed` and leaves `lastError` clear;
|
||||
repeated/early `stop()` is safe; defaults and `suggestedControlBlockSize`.
|
||||
These also serve as the guard that the driver is actually *in* the build — if
|
||||
the `CALSA` dependency ever stops resolving, the whole file compiles away to
|
||||
nothing and every other test would still pass.
|
||||
|
||||
**Acceptance — basic playback CONFIRMED on hardware.** On an Ubuntu 24.04 arm64
|
||||
Parallels VM (2026-08-21), the `quickstart` template played its 10-second sine to
|
||||
the speakers via `makeDefaultAudioDriver()` → `ALSAAudioDriver`. The driver moves
|
||||
a real speaker — the headline capability is proven. Still to exercise on hardware:
|
||||
1. ~~sine to speakers~~ ✅ (confirmed at the template default rate; still worth a
|
||||
pass at both 44.1 and 48 kHz and a couple of block sizes);
|
||||
2. xrun recovery under load (the `-EPIPE` path is written but never taken);
|
||||
3. duplex: confirm `snd_pcm_link` succeeds on a real duplex device and that
|
||||
input reaches the engine;
|
||||
4. `SCHED_FIFO` grant under a `limits.conf`-configured user;
|
||||
5. latency sanity vs `periodsPerBuffer`.
|
||||
Basic output is no longer unproven; the robustness checks (2–5) remain open.
|
||||
|
||||
**Follow-ups, deliberately not done here:**
|
||||
- **PipeWire backend.** ALSA-through-PipeWire's compat layer works, but a native
|
||||
PipeWire driver is the better long-term desktop path. `AudioDriver` is the
|
||||
seam; nothing in this driver blocks it.
|
||||
- ~~**Scaffolder templates emit `CoreAudioDriver()`**~~ ✅ **done** — the CLI
|
||||
templates (`quickstart`, `basic`, `demo`) now emit
|
||||
`makeDefaultAudioDriver()`. The first attempt emitted the
|
||||
`#if canImport(AudioToolbox)` switch in the *generated* source; review caught
|
||||
that this breaks exactly where it matters — Windows, a cross-compiled Linux
|
||||
build, and `LYREBIRD_DISABLE_ALSA=1` all lack `ALSAAudioDriver`, so the
|
||||
emitted `#else` would not compile. Hence the library-side factory. The
|
||||
`ui-demo` and Xcode templates keep `CoreAudioDriver` deliberately: they import
|
||||
AppKit / are Xcode projects, so they are Apple-only by construction.
|
||||
Also fixed here: the `nrt` and `score` templates emitted `printError(...)`, a
|
||||
helper that exists only inside the `LyrebirdCLI` target, so **every
|
||||
scaffolded `nrt`/`score` project failed to compile** — a regression from the
|
||||
earlier stderr port on this branch. They now emit a self-contained
|
||||
`FileHandle`-based helper. All five CLI templates are verified by scaffolding
|
||||
and **building** them in the Linux container, not by string inspection.
|
||||
|
||||
### Item 2 — Golden-value DSP tests that run on Linux — HIGH — ✅ DONE
|
||||
**What:** Tests asserting concrete numeric output of the portable FFT/biquad
|
||||
**through the real generators**, runnable off Apple.
|
||||
**Why:** `Tests/LyrebirdDSPTests/ScalarDSPParityTests.swift` compares to *real
|
||||
vDSP* and is therefore `#if canImport(Accelerate)` — **Apple-only**. Nothing
|
||||
verified that the portable DSP produces correct *audio* on Linux; a packing or
|
||||
scaling bug in the portable FFT would have shipped silently.
|
||||
**Delivered:** a new platform-neutral test target `LyrebirdPortableTests`
|
||||
(`Tests/LyrebirdPortableTests/`, in the main `targets:` array so a Linux host
|
||||
sees it) holding **6 golden-value tests**, no `#if` guards anywhere:
|
||||
|
||||
| Test | Portable code it pins |
|
||||
|---|---|
|
||||
| `butterworthLowPassOrder4ImpulseResponse` | `vDSP_biquadD` opaque-setup cascade (`PortableBiquad.swift`) |
|
||||
| `butterworthHighPassOrder2ImpulseResponse` | same, different coefficient path |
|
||||
| `klankImpulseResponse` | vector kernel — `vsmulD` / `vmulD` / **`vsubD`** / `sveD` |
|
||||
| `resonatorBankImpulseResponse` | same kernel, `(freq, decay, amp)` spec order |
|
||||
| `analysisMagnitudeSpectrumOfBinCentredSine` | forward `vDSP_fft_zrip` + `ctoz` packing and real-FFT scaling |
|
||||
| `resynthesisReconstructsInputSine` | inverse FFT + windowed overlap-add round trip |
|
||||
|
||||
Goldens were captured on macOS (arm64, vDSP-backed) and are compared with a
|
||||
`absolute + relative × |golden|` tolerance — `1e-9` for the double-precision
|
||||
filter responses, `1e-5` for the `Float`-internal spectral paths.
|
||||
`Tests/LyrebirdPortableTests/PortableTestSupport.swift` holds the local
|
||||
engine/collect helpers (test targets cannot share sources) and deliberately uses
|
||||
only the public + `@_spi(LyrebirdExtensions)` surface.
|
||||
|
||||
**Both directions of the check were verified** (a golden test that cannot fail is
|
||||
worse than none):
|
||||
- swapping `vDSP_vsubD`'s operands in `AccelerateShim.swift` → Klank and
|
||||
ResonatorBank fail on Linux with diffs of `1e7`+ (the classic vDSP
|
||||
reversed-operand bug, caught).
|
||||
- swapping real/imag in `vDSP_ctoz` (`PortableFFT.swift`) → both spectral tests
|
||||
fail with diffs of ~0.29 on a unit-amplitude sine.
|
||||
Each sabotage was reverted immediately after the run.
|
||||
|
||||
**Verified green:** macOS (`swift test --no-parallel`, vDSP path — see the
|
||||
serial-run note above) and Linux in-container on
|
||||
both architectures — `docker run --rm [--platform linux/amd64] -v "$PWD":/pkg
|
||||
-w /pkg swift:6.3.3 swift test` — so the CI lane (Item 3, x86_64 runners) runs
|
||||
them on every push with no config change; only the explanatory comment in
|
||||
`bitbucket-pipelines.yml` was updated.
|
||||
|
||||
**Regenerating a golden** (only after establishing the change was intended —
|
||||
unexplained drift is the bug this target exists to catch): run the same graph on
|
||||
macOS and print each sample with `String(format: "%+.15e")`.
|
||||
|
||||
**Not done here (deliberate):** the ~165 files of `LyrebirdTests` are still
|
||||
macOS-host-only. Most are platform-neutral and could migrate to
|
||||
`LyrebirdPortableTests` over time, which would widen Linux coverage well beyond
|
||||
DSP; that is bulk mechanical work, independent of this item, and best done in
|
||||
slices rather than as one move.
|
||||
|
||||
### Item 3 — Linux CI lane — HIGH — ✅ DONE
|
||||
**What:** CI building + testing on Linux.
|
||||
**Why:** Locks in the port so a main-merge can't silently regress it (see the
|
||||
standing-maintenance hazard). CI is also the only place tests actually *run* on
|
||||
Linux without a local Linux box.
|
||||
**Delivered:** `bitbucket-pipelines.yml` (the repo remote is BitBucket, not
|
||||
GitHub) using the official `swift:6.3.3` image. `size: 2x` (8 GB). Builds
|
||||
`LyrebirdSynth` / `LyrebirdGraphDSL` / `LyrebirdCLI`, then `swift test` runs
|
||||
every target the Linux manifest exposes: **LyrebirdDSPTests, LyrebirdGraphDSLTests,
|
||||
LyrebirdCLITests — 239 tests, all green** natively in-container.
|
||||
**Verified locally** in the same image via Docker Desktop (arm64):
|
||||
`docker run --rm -v "$PWD":/pkg -w /pkg swift:6.3.3 swift test`.
|
||||
|
||||
Supporting changes made to get here:
|
||||
- **Manifest split** (`Package.swift`): the Apple-only targets — `LyrebirdUI`,
|
||||
`LyrebirdUITests`, `LyrebirdTests` (imports `AudioToolbox` directly in some
|
||||
files), and `LyrebirdBenchmark` (micro-benchmarks vDSP) — are appended under
|
||||
`#if os(macOS)` *after* the `Package(...)` initializer (an `#if` cannot be an
|
||||
array element in a manifest). On a Linux/Windows host they are simply absent,
|
||||
so `swift test` compiles only the portable surface. macOS/iOS builds see every
|
||||
target unchanged; the two remaining test targets' `AudioToolbox`/`Accelerate`
|
||||
links are now `.when(platforms: [.macOS, .iOS])`.
|
||||
- **Core `stderr` fix**: a `git merge main` had landed
|
||||
`fputs(..., stderr)` in `Score/ScoreElementDSL.swift`, which fails Swift 6
|
||||
concurrency checking on Linux — the exact standing-maintenance hazard. Added
|
||||
`Utilities/StandardError.swift` (`lyrebirdPrintError(_:)`, `FileHandle`-based)
|
||||
and routed the call through it. Grep guard added to the maintenance list above.
|
||||
|
||||
**Registry compile-memory (resolved):** the generated
|
||||
`Sources/LyrebirdGraphDSL/Generated/GeneratedDSLRegistry.swift` used to be one
|
||||
~300-element array literal; the type-checker checked it as a single expression and
|
||||
needed several GB, so two concurrent heavy compiles OOM-killed the compiler on an
|
||||
8 GB runner. Fixed in `Tools/DSLRegistryGen`: `emitRegistry` now emits the entries
|
||||
as fixed-size (`registryChunkSize = 32`) `private static let _chunkN` arrays
|
||||
concatenated into `generated`, so each chunk type-checks independently. Verified
|
||||
building at full parallelism on Linux from a clean scratch — no OOM — so CI runs
|
||||
default `-j` (no cap). Regenerate with `bash scripts/generate-dsl-registry.sh`
|
||||
after changing a public generator init; the `--check` drift guard stays green.
|
||||
|
||||
**Acceptance:** green CI on push to the branch — Pipelines is enabled on the
|
||||
BitBucket repo.
|
||||
|
||||
### Item 4 — MIDI on Linux — MEDIUM — ⚠️ BUILT, NOT YET RECEIVED FROM HARDWARE
|
||||
**What:** `Sources/Lyrebird/MIDI/` was `#if canImport(CoreMIDI)`-guarded out, so
|
||||
there was no MIDI in/out on Linux.
|
||||
**Delivered:** an ALSA-sequencer backend behind the same `MIDI` public API as the
|
||||
CoreMIDI one.
|
||||
- **Shared, tested mapping.** `MIDI/ALSASeqMIDIEvent.swift` — a pure enum +
|
||||
`midiMessage(for:)` that turns a decoded seq event into a `MIDIMessage`,
|
||||
routing channel-voice events through the existing
|
||||
`MIDIMessage.from(status:data1:data2:)` so Linux applies the identical parsing
|
||||
(note-on velocity 0 → note-off, the pitch-bend offset) the CoreMIDI path does.
|
||||
Pure Swift, no ALSA import, so it is unit-tested on **both** platforms
|
||||
(`ALSASeqMIDIEventTests`, 8 tests).
|
||||
- **The backend.** `MIDI/ALSAMIDI.swift`, guarded
|
||||
`#if !canImport(CoreMIDI) && canImport(CALSA)`, defines `MIDI` for native
|
||||
Linux: `snd_seq_open`, in/out simple ports, source enumeration
|
||||
(`snd_seq_query_next_client/port`), auto-subscribe to readable sources, a
|
||||
`poll()`-based input thread (200 ms cadence so `stop()` is responsive) that
|
||||
decodes events via the shared mapping and dispatches on the `lyrebird.midi`
|
||||
queue, and `send` / `sendVirtual` building seq events from `MIDIMessage`.
|
||||
The handler registry, dispatch contract, and lifecycle discipline mirror the
|
||||
CoreMIDI class; the two definitions are mutually exclusive so exactly one
|
||||
`MIDI` compiles per platform.
|
||||
- `MIDISource` / `MIDIDestination` are now cross-platform: `endpointRef` on
|
||||
Apple, ALSA `client:port` off Apple. `MIDIError` gained `Equatable` and its
|
||||
`OSStatus`-carrying cases double as ALSA return-code carriers (`OSStatus` is
|
||||
`Int32` off Apple). `MIDIMessage` / `+UMP` / `MIDIHandlerToken` were already
|
||||
neutral.
|
||||
|
||||
**Availability:** like `ALSAAudioDriver`, `MIDI` exists on Linux only where
|
||||
CALSA is linked — absent under `LYREBIRD_DISABLE_ALSA=1` or a cross-compile from
|
||||
macOS. Consumers that need MIDI everywhere must guard accordingly.
|
||||
|
||||
**Verified (headless):** `ALSAMIDITests` (Linux-only) — handler registry, the
|
||||
not-started send/create guards, safe repeated stop, empty pre-start
|
||||
enumeration, and a tolerant start/stop that accepts either a real open or a
|
||||
clean `clientCreateFailed` when `/dev/snd/seq` is absent (the container case),
|
||||
checking a failed start does not latch `isStarted`. macOS
|
||||
`swift test --no-parallel` 5714/5714; Linux arm64 302 / x86_64 302;
|
||||
`LYREBIRD_DISABLE_ALSA=1` 289.
|
||||
|
||||
**Acceptance NOT met — no controller has been received from.** The container has
|
||||
no sequencer device, so the poll loop, event decode from a live controller,
|
||||
subscription, and `send` to real hardware have never run. Outstanding on a Linux
|
||||
box with ALSA + a connected controller:
|
||||
1. receive note-on / note-off / CC / pitch-bend / program-change from a
|
||||
controller and confirm the decoded `MIDIMessage`;
|
||||
2. `send` to a hardware synth and hear it;
|
||||
3. `createVirtualInput` / `createVirtualOutput` visible to other clients
|
||||
(`aconnect -l`) and round-trip;
|
||||
4. hot-plug: a controller connected after `start()` appears (the poll loop does
|
||||
not currently re-enumerate — see below).
|
||||
|
||||
**Known limitations / follow-ups:**
|
||||
- **No hot-plug re-enumeration.** CoreMIDI's `MIDIClientCreateWithBlock`
|
||||
notification re-runs `_refreshEndpoints` / `_connectAllSources`; the ALSA
|
||||
backend enumerates and subscribes once at `start()`. A device connected later
|
||||
is not auto-subscribed. ALSA exposes this via the System announce port
|
||||
(subscribe to client 0 port 1 and handle `SND_SEQ_EVENT_PORT_START`); left as
|
||||
a follow-up.
|
||||
- **UMP / MIDI 2.0.** The CoreMIDI path sends MIDI 1.0 over the UMP API; the
|
||||
ALSA path is MIDI 1.0 via legacy seq events. Functionally equivalent for the
|
||||
`MIDIMessage` set; a native UMP seq path is not implemented.
|
||||
|
||||
### Item 5 — OSC on Linux — MEDIUM — ✅ DONE
|
||||
**What:** `OSCClient` / `OSCServer` used Apple's `Network.framework`
|
||||
(`NWConnection` / `NWListener`), guarded out on Linux.
|
||||
**Delivered:** POSIX BSD-socket transports under `#else`, no dependencies. The
|
||||
OSC 1.0 codec (`OSCArgument` / `OSCCodec` / `OSCMessage`) was already portable;
|
||||
only the transport was swapped, and the handler registry / decode+dispatch is
|
||||
now shared code rather than living inside the `Network` guard.
|
||||
- `OSCClient`: a connected UDP socket (`getaddrinfo` → `socket` → `connect`),
|
||||
opened lazily on the first send on the serial `sendQueue`, reused after. A
|
||||
resolution/connect failure is latched so a bad host does not re-resolve every
|
||||
send. `sendto` with a nil destination avoids the name clash with the class's
|
||||
own `send`.
|
||||
- `OSCServer`: `socket` + `SO_REUSEADDR` + `bind` to `INADDR_ANY:port`, then a
|
||||
dedicated receive thread running a `poll()` loop (200 ms cadence) that
|
||||
`recv`s datagrams and hands them to the shared decode+dispatch. `stop()`
|
||||
shuts the socket down (unblocking any wait), clears the run flag, joins, and
|
||||
closes — the same discipline as the ALSA backends. New `OSCServerError`
|
||||
(`socketFailed` / `bindFailed`, carrying `errno`) is thrown off Apple; on
|
||||
Apple `NWListener` throws its own error. `OSCHandlerToken` moved out of the
|
||||
`Network` guard so it exists on both platforms.
|
||||
|
||||
**Acceptance MET — verified over real loopback, on both platforms.** Unlike the
|
||||
ALSA MIDI and audio backends, OSC needs no hardware: `OSCLoopbackTests`
|
||||
(`Tests/LyrebirdPortableTests`) binds an `OSCServer` on 127.0.0.1 and sends to it
|
||||
with `OSCClient`, asserting a full argument round trip, glob-pattern address
|
||||
matching, that a removed handler stops receiving, and safe idempotent stop. It
|
||||
exercises `Network.framework` on macOS and the POSIX transport on Linux, and
|
||||
passes on both — including **Linux without ALSA** (OSC is pure POSIX, so it does
|
||||
not depend on CALSA and runs under `LYREBIRD_DISABLE_ALSA=1`). macOS
|
||||
`swift test --no-parallel` 5718/5718; Linux arm64 306 / x86_64 306;
|
||||
`LYREBIRD_DISABLE_ALSA=1` 293.
|
||||
|
||||
### Item 6 — DiskIn + LyrebirdBuffer file I/O on Linux — MEDIUM — ✅ DONE
|
||||
**What:** `Generators/BufferIO/DiskIn.swift` and `Buffers/LyrebirdBufferFileIO.swift`
|
||||
were fully `#if canImport(AudioToolbox)`-guarded (no portable fallback), so
|
||||
soundfile-into-buffer loads and disk streaming did not exist off Apple.
|
||||
**Delivered:** portable `#else` branches on the `WavFileReader` /
|
||||
`WavFileWriter` backend, mirroring `DiskOut` / `NRTDriver`:
|
||||
- `LyrebirdBuffer.load` / `loadAllChannels` / `fill` read WAV via
|
||||
`WavFileReader`; the chunked read + channel-extract + optional peak
|
||||
normalisation is replicated in two portable helpers
|
||||
(`portableReadMono` / `portableReadAllChannels`). `channelOutOfRange` /
|
||||
`invalidChannelCount` stay cross-platform; open/read failures surface as
|
||||
`WavFileError` (matching the documented `NRTDriver` decision, rather than
|
||||
wrapping).
|
||||
- `LyrebirdBuffer.write` gains a `WavFileWriter` branch (RF64 already went
|
||||
through the portable `RF64Writer` on both platforms); the Apple-only
|
||||
containers throw a new `LyrebirdBufferIOError.unsupportedFormatOnPlatform`.
|
||||
- `DiskIn.Audio` streams via `WavFileReader`, reopening the file to loop (the
|
||||
reader is forward-only). **Sample-rate handling:** `ExtAudioFile` resamples
|
||||
to the engine rate transparently; the portable reader hands back the file's
|
||||
native frames, so `DiskIn` folds `fileSampleRate / engineSampleRate` into the
|
||||
read-position advance (`_readRateScale`, `1.0` on Apple) — a 44.1 kHz file on
|
||||
a 48 kHz engine plays at the right speed and pitch via the existing linear
|
||||
interpolation. The buffer-load paths do **not** resample on either platform
|
||||
(they keep the file's own rate), so no scale is needed there.
|
||||
- `LyrebirdBufferIOError` split: the `OSStatus` cases are Apple-only; the
|
||||
semantic cases (`channelOutOfRange`, `invalidChannelCount`,
|
||||
`fileTooLargeForContainer`) are cross-platform; `unsupportedFormatOnPlatform`
|
||||
is added off Apple. `DiskInError` stays Apple-only — the portable `DiskIn`
|
||||
throws `WavFileError`.
|
||||
|
||||
**Verified:** new `Tests/LyrebirdPortableTests/PortableFileIOTests.swift` —
|
||||
mono/stereo load round trips, channel select, `channelOutOfRange`, fill
|
||||
truncate + zero-pad, peak normalisation, int16 write→load round trip, DiskIn
|
||||
sample-accurate streaming at matching rate, and (off-Apple only) DiskIn
|
||||
sample-rate-ratio folding + `write` to a CAF throwing
|
||||
`unsupportedFormatOnPlatform`. Fixtures are written with `WavFileWriter`, so the
|
||||
suite runs on both platforms; on Apple the same paths exercise `ExtAudioFile`
|
||||
and a round trip that agrees on both is the guarantee. macOS
|
||||
`swift test --no-parallel` 5706/5706; Linux arm64 + x86_64 289/289;
|
||||
`LYREBIRD_DISABLE_ALSA=1` 281/281.
|
||||
|
||||
**One test is portable-only by nature:** the SR-ratio DiskIn test is
|
||||
`#if !canImport(AudioToolbox)`, because on Apple `ExtAudioFile` does the
|
||||
conversion inside `DiskIn` (advancing at rate 1) and the exact file-frame
|
||||
mapping the test asserts only holds for the portable read-position scaling.
|
||||
|
||||
### Item 7 — CLI on musl (LineNoise) — LOW / decision
|
||||
**What:** `LyrebirdCLI` builds on glibc but not musl — the `LineNoise`
|
||||
dependency does `import Glibc` with no `Musl` support.
|
||||
**Why / decision:** glibc is the standard Linux target, so this is optional.
|
||||
Options: (a) accept CLI = glibc-only (recommended); (b) fork/patch LineNoise for
|
||||
`Musl`; (c) swap the line-editing dependency. Document the choice; don't spend
|
||||
effort unless a static-musl CLI binary is specifically wanted.
|
||||
|
||||
### Item 8 — GUI spike: **SwiftOpenUI** for `LyrebirdUI` on Linux — EXPLORATION
|
||||
**What:** Evaluate `codelynx/SwiftOpenUI` (MIT) as the path to run `LyrebirdUI`
|
||||
on Linux. It is a SwiftUI-API reimplementation: **on macOS it imports real
|
||||
SwiftUI**; on Linux it renders via **GTK4** (needs `libgtk-4-dev`) — the same
|
||||
"real API on Apple / portable backend elsewhere" pattern Lyrebird already uses
|
||||
for `LyrebirdDSP`.
|
||||
**Why it looks reasonable:** its coverage matches what `LyrebirdUI` actually
|
||||
needs — `Canvas`/`Path`/`Circle`/`Rectangle` (the knobs, scope, and envelope
|
||||
views are custom-drawn), drag/tap gestures (the XY pad), and the
|
||||
`@State`/`@Binding` wrappers that `@UIParam` builds on. MIT-licensed.
|
||||
**Risks / unknowns (why it's a spike, not a commitment):**
|
||||
- Maturity is modest (~31 stars, effectively one author) — bus-factor risk; the
|
||||
"Stable" self-label is optimistic. SwiftUI reimplementations always have edge
|
||||
gaps.
|
||||
- Lyrebird's AppKit `NSEvent` mouse monitor (`MouseInputBridge`, installed via
|
||||
`MouseInput.install(_:)`) is Apple-only — a GTK input path is needed for the
|
||||
mouse-driven generators.
|
||||
- `@UIParam` (`Sources/LyrebirdUI/`) + `ParameterKnob`/`Slider`/`XY`/scope/
|
||||
envelope views must actually compile + render against SwiftOpenUI's surface.
|
||||
**Compile-probe done (container, no display) — the hard 20% answered.**
|
||||
`codelynx/SwiftOpenUI` (`develop` @ 8100d9c, MIT). Modules `SwiftOpenUI` +
|
||||
`BackendGTK4` (a `.systemLibrary` on `libgtk-4-dev`). Built the framework **and a
|
||||
LyrebirdUI-style Canvas knob** in a GTK4 container (`swift:6.3.3` + `libgtk-4-dev`):
|
||||
SwiftOpenUI + BackendGTK4 compile on Linux, and the knob (custom drawing +
|
||||
`@Observable` model + drag) compiles. What the probe found:
|
||||
|
||||
- **`GraphicsContext` is NOT provided — this is the shim.** SwiftOpenUI's
|
||||
`Canvas(renderer: { ctx, size in … })` hands back a **Cairo-backed
|
||||
`DrawingContext`** (`setColor` / `moveTo` / `lineTo` / `arc` / `stroke()` /
|
||||
`fill()`), not SwiftUI's `GraphicsContext`. So every LyrebirdUI custom-drawn
|
||||
view — `ParameterKnob`, `LyrebirdScopeView`, `LyrebirdEnvelopeView`,
|
||||
`LyrebirdSpectrumView`, `LyrebirdScatterView` (the 9 `Canvas` + 6
|
||||
`GraphicsContext` call sites) — needs its drawing body **rewritten** from
|
||||
`GraphicsContext.fill/stroke/draw` to `DrawingContext`. The rewrite is
|
||||
mechanical (both are imperative 2-D drawing) and was proven to compile, but it
|
||||
is per-view work, not a drop-in.
|
||||
- **`@Observable` works on Linux (stdlib `Observation`), but SwiftOpenUI does not
|
||||
re-export it** — a consumer must add `import Observation` explicitly (real
|
||||
SwiftUI re-exports it). SwiftOpenUI's `DependencyTracking` claims
|
||||
`@Observable`-driven rebuilds, so `@UIParam`'s backing model should drive
|
||||
re-renders — but that is runtime behavior still to confirm on a display.
|
||||
- **Gestures fit.** `.onDrag { (d: DragGestureValue) in … }` carries
|
||||
`translation`, which is what the knob/XY drags need; the closure shape differs
|
||||
from SwiftUI's `DragGesture().onChanged`, so a light rewrite.
|
||||
- Declarative controls (`Slider`, `Button`, `Text`, `VStack`/`HStack`) and the
|
||||
`@State`/`@Observable` binding port with light friction.
|
||||
|
||||
**Update 10 — RESUME with fork patches (2026-09-05).** Re-verified upstream
|
||||
`develop @ 8100d9c` still has the observation→full-rebuild→gesture-teardown
|
||||
(`GTKViewHost.rebuild()` still gates the narrow path on `!fromObservation`); no
|
||||
`@GestureState`, no gesture-identity reconciliation. Confirmed the blocker lives
|
||||
in the GTK4 render/gesture layer, **below** the state wrappers — so no
|
||||
`@State`/`@Binding`/`@Observable` choice routes around it (the single-control
|
||||
`@State` "success" is an artifact of Problem 1's idle-starvation masking Problem
|
||||
2). Decision: **keep the SwiftUI path for the Linux pre-release** and fix it in
|
||||
the fork. Two patches planned (B: live redraw via high-priority `queue_draw`
|
||||
during drag; C: reuse the existing `beginInteractiveUpdate`/`endInteractiveUpdate`
|
||||
deferral so no rebuild recreates the gesture mid-drag). Full plan, fork-commit
|
||||
strategy, and validation: **`spikes/SwiftOpenUIKnob/FORK_PATCH_PLAN.md`**.
|
||||
Patches are the next work session.
|
||||
|
||||
**Update 9 — INTERACTIVE-UI BLOCKER (hardware, 2026-08-22). All 8 views build
|
||||
and the timer-driven ones work; live drag interaction does NOT.** On-hardware
|
||||
testing of the full demo found two distinct SwiftOpenUI GTK4-backend problems,
|
||||
both root-caused from the pinned fork source. Both are BEYOND the drag-observable
|
||||
patch already submitted upstream (that patch fixed single-control gesture
|
||||
*streaming*, which does work — see below).
|
||||
|
||||
What works on hardware: the scope animates, the CPU meters update, audio tracks
|
||||
live (dragging a knob changes the sound continuously). What fails: the *visual*
|
||||
of interactive controls.
|
||||
|
||||
Bisected with `LYREBIRD_DEMO={knob,controls,full}` (diagnostic scaffolding in
|
||||
`Sources/LyrebirdUILinuxDemo/`, commit 22dd5b6a — kept until this is resolved):
|
||||
- `knob` (one knob): gesture STREAMS (sound tracks continuously), but the knob
|
||||
Canvas only redraws on mouse-UP.
|
||||
- `controls` (all controls, no animated views): knob/XY drop back to one tick per
|
||||
gesture; native slider moves but its sound update only lands on mouse-up.
|
||||
- `full`: scope animates; every interactive control is one-tick.
|
||||
|
||||
Root causes (in `.build-*/checkouts/SwiftOpenUI/Sources/Backend/GTK4/Rendering/`):
|
||||
1. **Idle-starved redraw (Problem 1).** `GTKViewHost.scheduleRebuild` schedules
|
||||
the redraw with plain `g_idle_add` (default idle priority). During a continuous
|
||||
drag, higher-priority pointer-motion events saturate the GLib loop and starve
|
||||
the idle rebuild, so the Canvas only redraws when motion stops (release). Audio
|
||||
is unaffected because `node.update(_:)` runs directly in the `onChanged`
|
||||
closure, not via a rebuild. Fix direction: high-priority `gtk_widget_queue_draw`
|
||||
on the Canvas during drag, not an idle-scheduled full-tree rebuild.
|
||||
2. **Drag-gesture teardown under sibling rebuilds (Problem 2).** With several
|
||||
controls bound to one node, a drag triggers a mid-drag rebuild that recreates
|
||||
the dragged Canvas widget → the `GtkGestureDrag` detaches → one tick. The
|
||||
single-control case only survives because its rebuild is idle-starved (so the
|
||||
widget is never recreated during the drag). Fix direction: reconcile the drag-
|
||||
gesture widget by IDENTITY so it survives rebuilds — exactly the preferred fix
|
||||
in `spikes/SwiftOpenUIKnob/UPSTREAM_ISSUE.md`, and the drop-target code
|
||||
(`GTKDropState` widget-pinning) is the in-repo precedent.
|
||||
|
||||
Decision (2026-08-22): PAUSE the interactive-UI push and gauge the SwiftOpenUI
|
||||
maintainer's responsiveness on the submitted PR first. If it is accepted → dig
|
||||
into Problems 1 & 2 (extend the issue/PR). If rejected with rationale → iterate.
|
||||
If it goes stale → reconsider the Linux UI approach (swift-cross-ui, or a thinner
|
||||
GTK layer). Not blocking anything else on the branch — the headless core, audio,
|
||||
scope/CPU readouts, and static views are all fine; only live *dragging* is
|
||||
affected. Investigation cost is already paid and captured here, so resuming does
|
||||
not require re-bisecting.
|
||||
|
||||
**Update 8 — control + visualization set ported.** All eight `LyrebirdUI`
|
||||
controls/views now have `Linux*` counterparts in `LyrebirdUILinux`:
|
||||
`LinuxParameterKnob` / `Slider` / `Label` / `Button` / `XY` (controls) and
|
||||
`LinuxScopeView` / `LinuxEnvelopeView` / `LinuxStatusView` (visualization). The
|
||||
animated views (scope, CPU status) use an `@Observable` model polled by a
|
||||
Foundation `Timer` on `RunLoop.main` (pumped by the GTK4 backend), NOT
|
||||
SwiftOpenUI's off-main `.task`. See Update 9 for the interaction blocker found
|
||||
when these were tested together on hardware.
|
||||
|
||||
**Update 7 — symmetric import shape + runnable demo.** Two ergonomics changes
|
||||
so friends can clone and run:
|
||||
- **Re-export shims** give both platforms one import shape. `LyrebirdUILinux`
|
||||
gets `LinuxUIExports.swift` (`@_exported import SwiftOpenUI` +
|
||||
`@_exported import BackendGTK4`); the macOS `LyrebirdUI` gets
|
||||
`LyrebirdUIExports.swift` (`@_exported import SwiftUI`). Downstream code is
|
||||
then `import LyrebirdSynth` + one `#if canImport(LyrebirdUI)` selecting
|
||||
`LyrebirdUI` (Apple) vs `LyrebirdUILinux` (Linux); body code beneath is
|
||||
identical because both bind the same core `@UIParam`/`UIParamNode`. In-repo
|
||||
precedent for `@_exported`: `Sources/LyrebirdDSP/AccelerateShim.swift`.
|
||||
- **Runnable demo** — new `LyrebirdUILinuxDemo` executable target (opt-in, same
|
||||
`LYREBIRD_ENABLE_LINUX_UI=1` gate): `KnobDemoSynth` (`@UIParam`
|
||||
frequency/amplitude sine → `Pan2`), `KnobDemoView` (two `LinuxParameterKnob`s),
|
||||
and a `main.swift` that starts the engine on `makeDefaultAudioDriver()` (ALSA
|
||||
if present, else silent Offline) then runs the GTK4 loop. Run with
|
||||
`LYREBIRD_ENABLE_LINUX_UI=1 swift run LyrebirdUILinuxDemo`. Turn the freq knob,
|
||||
hear the pitch track (needs a live ALSA device; GUI works regardless).
|
||||
|
||||
**Next steps (full cross-platform `LyrebirdUI` merge — deferred).** The symmetric
|
||||
shape above still keeps two module names. A *true* single unconditional
|
||||
`import LyrebirdUI` on both platforms needs the modules merged:
|
||||
1. Make the `LyrebirdUI` target cross-platform: build on Linux too, with internal
|
||||
`#if canImport(SwiftUI)` (Apple) / `#else` SwiftOpenUI (Linux) branches per
|
||||
control, and depend on SwiftOpenUI + BackendGTK4 on Linux only.
|
||||
2. Port the *remaining* controls. Done so far: `ParameterKnob`, `ParameterSlider`,
|
||||
`ParameterButton`, `ParameterLabel`, `ParameterXY`, `LyrebirdScopeView`,
|
||||
`LyrebirdEnvelopeView`, and `LyrebirdStatusView` (CPU meters) — all as `Linux*`
|
||||
in `LyrebirdUILinux`. The core control + visualization set is now ported.
|
||||
Deferred by choice: the large `LyrebirdEngineStatusView` (601 lines — a
|
||||
composite of start/stop + counts + a gain slider + a mute toggle + CPU, mostly
|
||||
duplicating already-ported controls) and the node-tree / message-banner /
|
||||
running-processes diagnostic views; port those only if the friends round wants
|
||||
them. NOTES: (a) the scope introduced the periodic-redraw
|
||||
pattern for animated viz views — an `@Observable` model polled by a Foundation
|
||||
`Timer` on `RunLoop.main` (which the GTK4 backend pumps ~every 5 ms), NOT
|
||||
SwiftOpenUI's `.task` (whose closure runs off-main and would race the
|
||||
observation registrar); its 30 Hz redraw is compile-verified but still needs
|
||||
on-hardware confirmation. (b) The envelope is static (draws once, no timer).
|
||||
`DrawingContext` has no text drawing, so the envelope's "L"/"R" marker letters
|
||||
are omitted (dashed green/orange lines still mark loop/release) — the status
|
||||
views likely need text, so plan on real `Text` views over/around a `Canvas`
|
||||
rather than text inside it.
|
||||
3. Fold `LyrebirdUILinux` + `LyrebirdUILinuxDemo` back into `LyrebirdUI` /
|
||||
a shared demo; retire the separate module.
|
||||
4. Gate the whole thing on the SwiftOpenUI dep being available (fork now,
|
||||
upstream + tag later). Larger review surface — its own branch.
|
||||
Do this only after the fork→upstream switch settles, so the merged module isn't
|
||||
pinned to a personal fork.
|
||||
|
||||
**Update 6 — shared parameter model moved to core.** The SwiftUI-free
|
||||
`@UIParam` property wrapper and its `@Observable` `UIParamNode` backing object
|
||||
moved from the macOS-only `LyrebirdUI` module into core `LyrebirdSynth`
|
||||
(`Sources/Lyrebird/Parameters/`). Neither imports SwiftUI — only `Observation`
|
||||
(stdlib, Linux-OK) — so nothing platform-gates them. `LinuxParameterKnob` now
|
||||
binds a real `UIParamNode` (via a synthesizer's `@UIParam` projected value
|
||||
`synth.$paramName`) with a value `range`, exactly as the macOS `ParameterKnob`
|
||||
does — one parameter model drives both platforms. Because `UIParamNode` is
|
||||
`@Observable`, `node.update(_:)` from a drag takes the GTK4 backend's narrow
|
||||
redraw path (the fork fix), so the gesture survives. The `UIParamTests` suite
|
||||
moved to `LyrebirdPortableTests` so Linux exercises it too. The placeholder
|
||||
`LinuxKnobModel` is gone. No macOS API broke: every real `@UIParam` consumer
|
||||
already imports `LyrebirdSynth`. Remaining: switch the SwiftOpenUI dep to
|
||||
upstream `codelynx/SwiftOpenUI` + a tagged release once the PR lands.
|
||||
|
||||
**Update 5 — `LyrebirdUILinux` target scaffolded (depends on the fork).** An
|
||||
opt-in Linux UI target now lives in the main package: build with
|
||||
`LYREBIRD_ENABLE_LINUX_UI=1` on a Linux host with `libgtk-4-dev`. It depends on
|
||||
the personal fork `github.com/joshpar/SwiftOpenUI` pinned to commit `1ac66079`
|
||||
(the drag fix), plus `BackendGTK4`, and holds the first ported control —
|
||||
`LinuxParameterKnob` (Canvas/`DrawingContext` + `.onDrag`, `@Observable`-backed).
|
||||
Gated so the **default** Linux build/CI stays lean and fork-free (verified: a
|
||||
flag-off resolve fetches no fork). macOS/iOS builds never see the target.
|
||||
Caveats: (1) SwiftPM writes `Package.resolved` at the package root regardless of
|
||||
`--scratch-path`, so a flagged build adds the fork pin locally — **do not commit
|
||||
a fork-polluted `Package.resolved`** (the committed one stays fork-free). (2) The
|
||||
control binds to a local `@Observable`; the shared-model step — moving the
|
||||
SwiftUI-free `@UIParam` / `UIParamNode` from the macOS-only `LyrebirdUI` module
|
||||
into core `LyrebirdSynth` so macOS and Linux UIs share one parameter model — is
|
||||
the next reviewed change. Switch the dep to upstream `codelynx/SwiftOpenUI` + a
|
||||
tagged release once the PR lands.
|
||||
|
||||
**Update 4 — `@Observable` PATCH CONFIRMED on hardware (2026-08-21).** With
|
||||
`swiftopenui-drag-observable.patch` applied to a fork, the `@Observable` knob
|
||||
(`spikes/SwiftOpenUIKnobObservable/`) tracks the drag continuously — so
|
||||
`@UIParam` (which is `@Observable`-backed) can drive a `Canvas` control on Linux
|
||||
**directly, no `@State` shim**. The patch is display-validated and PR-ready
|
||||
(`spikes/SwiftOpenUIKnob/PR_DESCRIPTION.md`, `UPSTREAM_ISSUE.md`). **Verdict:
|
||||
GO** — SwiftOpenUI is a viable single-codebase UI path for Linux, pending (a)
|
||||
the patch landing upstream or being vendored, and (b) the per-view
|
||||
`GraphicsContext → DrawingContext` drawing rewrite (mechanical, already shown to
|
||||
compile). The remaining LyrebirdUI port work is now ordinary, not blocked.
|
||||
|
||||
**Update 3 — `@State` drag CONFIRMED on hardware (2026-08-21).** On the Ubuntu
|
||||
24.04 arm64 VM the `@State` knob tracks the drag continuously — the narrow
|
||||
mutation path preserves the `GtkGestureDrag`, so the core question ("can a
|
||||
Canvas control take live drag input on GTK4?") is answered **yes**. The no-fork
|
||||
`@State` usage pattern is a viable single-codebase path today; LyrebirdUI's
|
||||
`@UIParam` (which is `@Observable`-backed) would draw from a local `@State` and
|
||||
sync to the param. The `@Observable` framework patch
|
||||
(`swiftopenui-drag-observable.patch`) — which would let `@UIParam` drive the
|
||||
Canvas directly, no `@State` shim — remains **compile-only**; validate it against
|
||||
a fork (`PATCH_TESTING.md`) before filing the PR.
|
||||
|
||||
**Update 2 — drag fix identified (compile-verified), pending display
|
||||
validation.** Root cause is narrow: SwiftOpenUI's GTK4 backend has a narrow
|
||||
mutation path that redraws a `Canvas` in place and preserves the drag gesture,
|
||||
but it is skipped for `@Observable`-driven changes (it falls through to a full
|
||||
rebuild to re-register observation, and the rebuild destroys the gesture). Two
|
||||
fixes, both in `spikes/SwiftOpenUIKnob/` (`PATCH_TESTING.md`): a **no-fork
|
||||
`@State` usage pattern** (the narrow path already covers `@State` Canvas
|
||||
redraws), and a **framework patch** (`swiftopenui-drag-observable.patch`) that
|
||||
runs the describe pass under `withObservationTracking` so `@Observable` takes
|
||||
the narrow path too. Both need the user's GTK4 display to confirm; if they hold,
|
||||
SwiftOpenUI remains the single-codebase path.
|
||||
|
||||
**Update 1 (hardware run, Ubuntu 24.04 arm64): renders + `@Observable`
|
||||
re-renders, but continuous drag is broken.** A drag handler that writes the
|
||||
bound value triggers a body rebuild that replaces the GTK drag-gesture widget
|
||||
(SwiftOpenUI defers that only for *drop*, not drag), so a knob moves one step
|
||||
per press instead of tracking the drag — the exact interaction every LyrebirdUI
|
||||
knob/slider/XY needs. See `spikes/SwiftOpenUIKnob/README.md` for the confirmed
|
||||
root cause and diagnostic. This is now the gating unknown, ahead of the
|
||||
GraphicsContext rewrite. Resolving it needs an upstream fix (defer the rebuild
|
||||
for drag gestures, or reuse the gesture widget) or a UI structure that keeps the
|
||||
gesture widget stable across value redraws.
|
||||
|
||||
**Verdict: conditional GO.** The framework builds on Linux and the hard 20%
|
||||
(custom drawing) is portable via a mechanical per-view `GraphicsContext →
|
||||
DrawingContext` rewrite that compiles — not a drop-in, but not a wall either.
|
||||
Still gated on a **display run** (Parallels) to confirm the knob actually
|
||||
renders, `@Observable` drives re-render, and drag behaves — the container has no
|
||||
X/Wayland. Risks unchanged: 32 stars / one author, "Stable" self-label
|
||||
optimistic. Alternative if the display run disappoints: `swift-cross-ui`
|
||||
(stackotter — own API, bigger rewrite) or stay headless on Linux.
|
||||
|
||||
**Reproduce the display run on Parallels:** `apt install libgtk-4-dev`; a
|
||||
minimal SwiftPM app depending on `SwiftOpenUI` + `BackendGTK4` (Linux) with an
|
||||
`App`/`WindowGroup`, `import Observation`, a `Canvas(renderer:)` knob drawn via
|
||||
`DrawingContext`, and `.onDrag`; entry `GTK4Backend().run(App.self)`; then
|
||||
`swift run`. The exact ~60-line spike is available on request.
|
||||
|
||||
---
|
||||
|
||||
Windows is planned separatelyWindows is planned separately and on hold (`docs/windows-support-plan.md`).
|
||||
Reference in New Issue
Block a user