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:
2026-09-10 21:09:11 -07:00
parent 77580ee98e
commit b6fdee8bfc
293 changed files with 16800 additions and 775 deletions
+111 -1
View File
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT
#if os(macOS)
#if canImport(SwiftUI)
import AppKit
import Synchronization
import LyrebirdSynth
@@ -160,4 +161,113 @@ private let mouseButtonReleased: Double = 0.0
private let normalizedMin: Double = 0.0
private let normalizedMax: Double = 1.0
#endif // os(macOS)
#endif // canImport(SwiftUI)
#elseif os(Linux)
import Synchronization
import LyrebirdSynth
import BackendGTK4
/// Linux `MouseInputBridge` conformer driven by a window-local GTK pointer
/// source (`GtkEventControllerMotion` + `GtkGestureClick`), the GTK4 counterpart
/// to the macOS `NSEvent`-monitor `MouseTracker`.
///
/// Position is normalised to the window the pointer is over:
/// - `x` = 0 (left edge) … 1 (right edge)
/// - `y` = 0 (bottom edge) … 1 (top edge) — flipped from GTK's top-left origin
/// - `button` = 0.0 (released) or 1.0 (primary button held)
///
/// Values are exposed via lock-free `Synchronization.Atomic<Double>` reads,
/// safe for the audio render thread, exactly like the macOS tracker.
///
/// Install once at app startup so `Mouse.X.Control()` / `Mouse.Y.Control()` /
/// `Mouse.Click.Control()` read live values:
///
/// ```swift
/// import LyrebirdSynth
/// import LyrebirdUI
///
/// MouseTracker.installShared()
/// ```
///
/// Unlike macOS this is window-local: it reports while the pointer is over one
/// of the app's windows (SwiftOpenUI attaches the controllers to every window
/// it opens). `x` / `y` are fully covered; `button` is best-effort — a
/// window-level click gesture sees presses not consumed by an interactive child.
///
/// ## Threading
///
/// `installShared()` and the forwarded pointer callbacks run on the GTK main
/// thread. No `@MainActor` — the Linux UI is GTK-main-loop-confined, not on the
/// Swift main actor (see `LyrebirdWindow`).
public final class MouseTracker: MouseInputBridge, @unchecked Sendable {
// Sendable invariant: `_x`/`_y`/`_button`/`_installed` are immutable `Atomic`s —
// all reads/writes lock-free. The pointer-sink closures are set once (gated by
// the `_installed` CAS) and only store into those atomics.
/// Process-wide `MouseTracker` instance.
public static let shared: MouseTracker = MouseTracker()
private let _x: Atomic<Double>
private let _y: Atomic<Double>
private let _button: Atomic<Double>
private let _installed: Atomic<Bool> = Atomic<Bool>(false)
/// Allocates the atomic state slots. Does not install the pointer sink —
/// `installShared()` does that.
public override init() {
_x = Atomic(mouseTrackerInitialPosition)
_y = Atomic(mouseTrackerInitialPosition)
_button = Atomic(mouseButtonReleased)
super.init()
}
// MARK: - MouseInputBridge overrides
public override var x: Double { _x.load(ordering: .relaxed) }
public override var y: Double { _y.load(ordering: .relaxed) }
public override var button: Double { _button.load(ordering: .relaxed) }
// MARK: - Install
/// Installs `MouseTracker.shared` as the active `MouseInput` bridge AND
/// registers the GTK pointer sink. Idempotent via the `_installed` atomic CAS.
///
/// Install timing is not sensitive: SwiftOpenUI attaches the pointer
/// controllers to every window it opens and reads the installed sink at event
/// time, so calling this before or after `GTK4Backend().run(_:)` both work.
public static func installShared() {
shared._installIfNeeded()
}
private func _installIfNeeded() {
let (exchanged, _) = _installed.compareExchange(
expected: false, desired: true, ordering: .acquiringAndReleasing)
guard exchanged else { return }
MouseInput.install(self)
GTK4PointerTracking.install(
onMove: { [weak self] (nx: Double, ny: Double) in
// Clamp to [0, 1] to honour the normalized-range contract even if
// an edge/drag-out event reports slightly out of bounds — parity
// with the macOS tracker's clamp.
self?._x.store(min(max(nx, 0.0), 1.0), ordering: .relaxed)
self?._y.store(min(max(ny, 0.0), 1.0), ordering: .relaxed)
},
onButton: { [weak self] (pressed: Bool) in
self?._button.store(
pressed ? mouseButtonPressed : mouseButtonReleased,
ordering: .relaxed
)
}
)
}
}
// MARK: - MouseTracker constants
private let mouseTrackerInitialPosition: Double = 0.5
private let mouseButtonPressed: Double = 1.0
private let mouseButtonReleased: Double = 0.0
#endif // os(macOS) / os(Linux)