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>
12 KiB
Linux parity plan — the two must-dos + the scratch window
Where Lyrebird's Linux GUI stands and what closes the gap to a defensible
"parity with macOS" claim. The interactive widget layer is done and validated:
every control/view is ported to a GTK4 #else body, and the SwiftOpenUI fork's
narrow-mutation path (Patches A–F) makes them behave like real SwiftUI, not a
degraded port. What remains are two functional gaps and one follow-on.
Prereq context: docs/ui/linux-view-port-plan.md (the view ports),
spikes/SwiftOpenUIKnob/FORK_PATCH_PLAN.md + NARROW_PATH_GENERALIZATION_PLAN.md
(the fork), and the linux-gui-swiftopenui memory. The fork is pinned by
revision in Package.swift; this Mac cannot build the GTK4 backend, so every
change is prepare-diff → push fork → bump pin → validate on the Linux VM.
Ordering: (1) LyrebirdWindow → (2) MouseTracker → (3) scratch window. The scratch window depends on (1). (1) and (2) are independent of each other.
Must-do 1 — LyrebirdWindow (host-window abstraction) — ✅ DONE
Status (branch parity/linux-window-mousetracker). Shipped. A #elseif os(Linux) body backs LyrebirdWindow with a runtime-opened
GtkApplicationWindow via a new fork API GTK4Backend.openStandaloneWindow
(+ gtk_swift_get_default_gtk_application); presentInWindow is ported on all
six views and the EngineStatus "Open Window" buttons are re-enabled. VM-runtime
confirmed. Design note that DIVERGES from the original plan below: the Linux
LyrebirdWindow / presentInWindow are nonisolated, NOT @MainActor — the
whole Linux/GTK4 UI is confined to the GTK main loop (not the Swift main actor),
and keeping @MainActor forced an assumeIsolated hop that captured
task-isolated self → a "sending self risks data races" error. Only the
@MainActor LyrebirdMessageCenter.shared access needs a self-less
assumeIsolated. The original recommendation below to "Keep it @MainActor" is
therefore superseded — do not follow it.
Why it was a must-do. There was no first-class way to open/manage a window on
Linux. LyrebirdWindow was Apple-only (NSWindow + NSHostingController);
every view's presentInWindow(...) convenience, and the EngineStatus "Open
Window" buttons, were therefore macOS-only. The demo hand-rolls a single GTK
window via SwiftOpenUI's App/Scene/WindowGroup scene model — there's no
imperative "open another window hosting this view" equivalent.
Current Apple surface (Sources/LyrebirdUI/LyrebirdWindow.swift):
@MainActor final class LyrebirdWindow — init(title:width:height:),
open<Content: View>(@ViewBuilder content:) (wraps NSHostingController),
close(), nsWindow, and an NSWindowDelegate that nils the reference on user
close. Consumed by presentInWindow on EngineStatus / NodeTree / Message /
EventList / Process / RunningProcesses views.
Linux approach. Add a GTK4 #else body with the same public API, backed by a
GtkWindow:
open(content:)→ create aGtkApplicationWindow(orGtkWindow), set title + default size,gtkRenderView(content())(BackendGTK4) as the child,present.close()→ destroy the window; wire theclose-request/ destroy signal to nil the reference (parity with theNSWindowDelegate).- Keep it
@MainActor.
Key unknown to resolve first (spike). GTK needs a running GtkApplication +
main loop before a window can present. Two questions:
- Does SwiftOpenUI already expose a way to open a standalone window at runtime
outside the
App/WindowGroupscene (an imperativeGTK4Backendwindow API)? If yes, build on it. If not,LyrebirdWindowmust own thegtk_init+ application + main-loop lifecycle itself. - App entry point. On macOS
LyrebirdWindowworks standalone (implicitNSApp). On Linux, opening a window from a CLI/REPL with no scene needs an owned GTK app + loop. Decide: doesLyrebirdWindowbootstrap GTK if none is running (sopresentInWindowworks headless-of-a-scene), or is it only valid inside aGTK4Backend().run(App)context? Recommendation: make it work in an existing loop first (covers the in-app "Open Window" buttons), then add a bootstrap path for standalone use.
Effort: moderate–substantial. The view hosting is straightforward
(gtkRenderView); the GTK app/main-loop lifecycle + multi-window management is
the real work, sized by what SwiftOpenUI already gives us (the spike answers it).
Validation: presentInWindow on EngineStatus/NodeTree/Message from the demo
opens a second GTK window that renders + tracks; closing it (button + WM close)
nils cleanly; no leak/crash on repeated open/close.
Fork implication: if SwiftOpenUI lacks a standalone-window API, that's a fork
addition (a GTK4Backend.openWindow(title:size:content:)), upstreamable.
Must-do 2 — MouseTracker / MouseInput (Linux pointer source) — ✅ DONE
Status (branch parity/linux-window-mousetracker). Shipped the window-local
baseline. A #elseif os(Linux) MouseTracker (MouseInputBridge subclass,
Atomic<Double> x/y/button, nonisolated) is fed by a new fork API
GTK4PointerTracking — a GtkEventControllerMotion + window-level
GtkGestureClick attached to every window the backend opens, forwarding
normalized (y-flipped) coordinates to a process-wide sink. installShared()
registers both MouseInput.install(self) and the sink; install timing is not
sensitive (controllers read the sink at event time). x/y fully covered, button
best-effort. Validated by LYREBIRD_DEMO=mouse. The X11-global enhancement below
remains an optional future add.
Why it was a must-do. The Mouse.X / Mouse.Y / Mouse.Click generators
(core, Sources/Lyrebird/Generators/UI/) read from MouseInput, which is fed by
a MouseInputBridge. The only bridge is MouseTracker (AppKit NSEvent global
monitors) — Apple-only. On Linux the generators silently read the default
0.5/0.5/0 — any patch using mouse control does nothing.
Current seam (already platform-neutral — this is the good news):
open class MouseInputBridge(x/y/button, default 0.5/0.5/0) — core.enum MouseInputwithinstall(_ bridge:)/currentX/Y/Button— core seam.MouseTracker: MouseInputBridge(AppKit) installsNSEventglobal monitors and overridesx/y/buttonfrom atomics — Apple-only, inLyrebirdUI.
So the port is a new MouseInputBridge conformer for Linux + installing it at
startup via MouseInput.install. No core changes.
Linux approach — pick the pointer source (design decision):
- Window-local (recommended baseline, portable): a
GtkEventControllerMotionon the app window updates x/y (normalized to the window), plus a click gesture forbutton. Works on both X11 and Wayland. Limitation: only tracks while the pointer is over a Lyrebird window (not truly global) — acceptable for a synth control surface, and matches how you'd actually perform with it. - Global (X11-only enhancement): poll
XQueryPointer(or XInput2) on a timer/thread for screen-global position. True parity with the macOS global monitor, but X11 only — Wayland forbids global pointer access (needs a portal). Gate behind an availability check; fall back to window-local.
Recommendation: ship window-local first (covers the real use case, no display- server dependency), add X11-global as an optional path if global is wanted.
Effort: moderate. The bridge + install is small; the pointer plumbing (GTK motion controller, or X11 polling) is the work. Live values are read on the RT-adjacent path via atomics exactly as the AppKit tracker does — mirror that.
Validation: a patch with Mouse.X.Control() driving a parameter responds to
pointer motion over the window on the VM; MouseInput.currentX/Y/Button update.
Placement: the Linux bridge lives in LyrebirdUI (like MouseTracker),
conforms to the core MouseInputBridge, installed via MouseInput.install at app
startup — same contract as macOS.
Follow-on — the LiveCompile scratch window (after 1 & 2)
The live-coding scratchpad (LiveCompile/ sub-package) is macOS-only. It has two
layers with very different portability; full detail lives with the engine spike,
summarized here for sequencing.
-
Engine (
LyrebirdLiveCompile, ~3.3k LOC) — moderate, independent of 1 & 2.LiveCompilershellsswiftc -emit-library→ dylib,dlopen/dlsym;SourceKitLSPClientdrivessourcekit-lsp. All portable (Linux toolchain shipsswiftc,dlopen,sourcekit-lsp). Adapt:.dylib→.so, dropxcrun(PATH), Linux-target/SDK + module paths, dynamic-link the snippet against onelibLyrebird.so(Linux analog of thelibLyrebirdDynamic.dylibdesign), and a LinuxSwiftToolchainStatus.- Spike first (½ day, do before committing): prove a
swiftc → .so → dlopensnippet resolves Lyrebird's symbols on the VM against the sharedlibLyrebird.so. Swift-on-Linux cross-.sosymbol/metadata resolution is the one real unknown; go/no-go for the whole path.
- Spike first (½ day, do before committing): prove a
-
Editor UI (
LyrebirdLiveCompileUI, ~3.1k LOC) — depends on Must-do 1. Built onNSTextView(ScratchTextView,NSViewRepresentable, AppKit menus) + hand-rolled highlighter/gutter/LSP-completion/position-mapping. Two landings:- Minimal (modest): a
LyrebirdWindowhosting SwiftOpenUITextEditor+ Run/Stop + console + the portedLyrebirdScopeView. No highlighting/completion. - Full parity (large, fork work): wrap GtkSourceView (GTK's code editor —
syntax highlighting, gutter, completion, UTF-8) as a new SwiftOpenUI widget,
rewire
ScratchModel, feed it the LSP completions. GtkSourceView gives the highlighting/gutter/completion for less custom code than the AppKit version, but wrapping it in SwiftOpenUI is a genuine new-backend-widget project.
- Minimal (modest): a
Scratch-window sequencing: engine spike → engine port (anytime) → Must-do 1 → minimal scratch window → (optional) full GtkSourceView editor.
Cross-cutting (applies to all three)
- Fork discipline. Any SwiftOpenUI gap (standalone window API, GtkSourceView
widget) is a fork commit: push
joshpar/SwiftOpenUIdevelop, bump thePackage.swiftrevision, validate on the VM. Keep each a clean upstreamable delta (seeFORK_PATCH_PLAN.md). - No Linux UI CI. Core CI skips the UI (needs GTK). Before calling any of this
"done", add at least a Linux build job for the UI + demo so regressions
surface (a compile-only GTK4 job via the
swift:6.x+libgtk-4-devcontainer noted inlinux-ci-x86-verification). - Validate on display, not just compile. The Process/EventList/Message-family
views compile but aren't exercised on the VM yet; fold them into the demo while
doing Must-do 1 (they're what
presentInWindowopens).
Definition of "Linux at parity" (the checklist this plan satisfies)
- ✅
LyrebirdWindowopens/manages GTK windows;presentInWindowworks for every view; the EngineStatus "Open Window" buttons return. - ✅
Mouse.X/Y/Clickgenerators respond to the pointer on Linux (window-local baseline). - ◐ Fork on a tagged release + UI has a Linux build job. The Linux CI job is in
(
bitbucket-pipelines.yml— one GTK-enabled build+test step compiles the UI graph). The fork is pinned to its first tagged release,joshpar/SwiftOpenUI0.1.0, instead of a bare commit. Still open: upstreaming the GTK4 patches tocodelynx/SwiftOpenUI(externally gated — one maintainer, a prior PR went stale), after which the pin can move to an upstream version. - ✅ Ported views exercised on display (VM-confirmed): EngineStatus (+ node-tree
/ messages detached windows), the mouse demo, and — via
LYREBIRD_DEMO=events— the Process/EventList family (LyrebirdEventListPerformanceViewinline, hostingLyrebirdEventListView+ per-processLyrebirdProcessViewstrips, pluspresentInWindowfor EventListPerformance / EventList / RunningProcesses). - (Stretch) live-coding scratchpad usable on Linux — not started.