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
@@ -4,6 +4,7 @@
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
#if canImport(SwiftUI)
import SwiftUI
import LyrebirdSynth
@@ -220,3 +221,250 @@ extension LyrebirdProcessView {
}
}
#endif
#else
// Linux/GTK4 counterpart to `LyrebirdUI.LyrebirdProcessView`: a control panel for
// one `LyrebirdProcess` (state dot + id, dB amp slider, Start/Release). The 10 Hz
// lifecycle poll moves off SwiftOpenUI's off-main `.task` onto a `Timer` on
// `RunLoop.main` inside an `@Observable` model — the amp/running/releasing state
// lives there so the `@Bindable` body tracks it. dB↔amp maths reuse the
// cross-platform `DbSliderConversion`.
//
// The amp control uses SwiftOpenUI's native `Slider` (GtkScale). Unlike the
// Canvas-drawn `ParameterSlider`, a native scale does not live-track other
// controls mid-drag — acceptable here (a single transport slider, not a linked
// modulation source).
//
// SwiftOpenUI is always present in this target (see Package.swift).
import SwiftOpenUI
import LyrebirdSynth
import Observation
import Foundation
/// 10 Hz process lifecycle poll interval.
private let linuxProcessPollIntervalSeconds: TimeInterval = 0.1
/// Polls one `LyrebirdProcess`'s lifecycle + amp on a main-thread timer and
/// publishes them for ``LyrebirdProcessView``. Internal — only the view is public.
///
/// `@unchecked Sendable`: main-thread-confined; the `Timer` block is `@Sendable`,
/// same rationale as `LyrebirdScopeModel`.
@Observable
final class LinuxProcessModel: @unchecked Sendable {
var isRunning: Bool = false
var isReleasing: Bool = false
var amp: Double = 1.0
@ObservationIgnored let process: LyrebirdProcess
@ObservationIgnored private var timer: Timer?
init(process: LyrebirdProcess) {
self.process = process
// `amp` is @MainActor; construction happens on the GTK main thread.
self.amp = MainActor.assumeIsolated { process.amp }
}
deinit {
timer?.invalidate()
}
func start() {
guard timer == nil else { return }
refresh()
let t: Timer = Timer.scheduledTimer(
withTimeInterval: linuxProcessPollIntervalSeconds,
repeats: true
) { [weak self] _ in
self?.refresh()
}
timer = t
}
func stop() {
timer?.invalidate()
timer = nil
}
// SwiftOpenUI view/timer callbacks are nonisolated but always run on the GTK
// main thread, so `assumeIsolated` reaches `LyrebirdProcess`'s @MainActor
// `amp` safely. `isRunning` / `isReleasing` are nonisolated already.
func refresh() {
isRunning = process.isRunning
isReleasing = process.isReleasing
amp = MainActor.assumeIsolated { process.amp }
}
}
/// A control panel for a single `LyrebirdProcess` on the Linux/GTK4 UI. Mirrors
/// `LyrebirdUI.LyrebirdProcessView`; same public API/init as the Apple side.
public struct LyrebirdProcessView: View {
public let process: LyrebirdProcess
public let engine: SynthesisEngine
@State private var model: LinuxProcessModel
// Layout constants (points).
private let dotSize: Double = 10
private let ampLabelWidth: Double = 36
private let dbReadoutWidth: Double = 56
private let disabledDotOpacity: Double = 0.4
/// Creates a process control view bound to the given process.
///
/// - Parameters:
/// - process: The `LyrebirdProcess` to control.
/// - engine: The `SynthesisEngine` used by the **Start** button.
public init(
process: LyrebirdProcess,
engine: SynthesisEngine
) {
self.process = process
self.engine = engine
_model = State(wrappedValue: LinuxProcessModel(process: process))
}
public var body: some View {
VStack(alignment: .leading, spacing: 12) {
header
Divider()
ampRow
Divider()
transportRow
}
.padding(12)
.background(Color.lyrebirdControlBackground)
.frame(minWidth: 280)
.onAppear { model.start() }
.onDisappear { model.stop() }
}
// MARK: - Sub-rows
private var header: some View {
HStack(spacing: 8) {
Circle()
.fill(stateColor)
.frame(width: dotSize, height: dotSize)
Text(process.id)
.font(.headline)
Spacer()
Text(stateLabel)
.font(.caption)
.monospacedDigit()
.foregroundStyle(.secondary)
}
}
private var ampRow: some View {
HStack(spacing: 8) {
Text("Amp")
.font(.caption)
.monospacedDigit()
.foregroundStyle(.secondary)
.frame(width: ampLabelWidth, alignment: .leading)
Slider(value: Binding(
get: { dbFromAmp(model.amp) },
set: { newDb in
let newAmp: Double = ampFromDb(newDb)
model.amp = newAmp
// Bind `process` (Sendable) to a local so the @MainActor
// closure captures it, not `self` (the non-Sendable View).
let p: LyrebirdProcess = process
MainActor.assumeIsolated { p.amp = newAmp }
}
), in: LyrebirdProcessView.minDb ... maxDb)
Text(dbDisplay(dbFromAmp(model.amp)))
.font(.caption)
.monospacedDigit()
.foregroundStyle(.primary)
.frame(width: dbReadoutWidth, alignment: .trailing)
}
}
// MARK: - dB <-> linear amplitude (shared via `DbSliderConversion`)
private static let minDb: Double = DbSliderConversion.minDb
/// Per-process slider ceiling, sourced from ``LyrebirdProcess/maxUIAmpDb``.
private var maxDb: Double { process.maxUIAmpDb }
private func ampFromDb(_ db: Double) -> Double { DbSliderConversion.ampFromDb(db) }
private func dbFromAmp(_ amp: Double) -> Double { DbSliderConversion.dbFromAmp(amp, maxDb: maxDb) }
private func dbDisplay(_ db: Double) -> String { DbSliderConversion.dbDisplay(db) }
private var transportRow: some View {
HStack(spacing: 8) {
Button("Start") {
// `process` is Sendable; `engine` is not, so bind it via
// `nonisolated(unsafe)` (safe — all runs on the GTK main thread).
// Capturing these locals keeps `self` (the View) out of the
// @MainActor closure.
let p: LyrebirdProcess = process
nonisolated(unsafe) let e: SynthesisEngine = engine
MainActor.assumeIsolated { p.play(engine: e) }
model.refresh()
}
.disabled(model.isRunning)
Button("Release") {
let p: LyrebirdProcess = process
MainActor.assumeIsolated { p.release() }
model.refresh()
}
.disabled(!model.isRunning || model.isReleasing)
Spacer()
}
}
// MARK: - Helpers
private var stateColor: Color {
if model.isReleasing { return .yellow }
if model.isRunning { return .green }
return Color.secondary.opacity(disabledDotOpacity)
}
private var stateLabel: String {
if model.isReleasing { return "Releasing" }
if model.isRunning { return "Running" }
return "Idle"
}
}
// MARK: - Standalone window (Linux)
extension LyrebirdProcessView {
/// Opens a `LyrebirdWindow` hosting a process control view. Requires a
/// running `GtkApplication` loop.
///
/// - Parameters:
/// - process: The `LyrebirdProcess` to control.
/// - engine: The `SynthesisEngine` used by the **Start** button.
/// - title: Window title-bar text. Defaults to the process ID.
/// - width: Initial window width in points. Defaults to `300`.
/// - height: Initial window height in points. Defaults to `180`.
/// - Returns: The `LyrebirdWindow` hosting the view.
@discardableResult
public static func presentInWindow(
process: LyrebirdProcess,
engine: SynthesisEngine,
title: String? = nil,
width: Double = 300,
height: Double = 180
) -> LyrebirdWindow {
let win: LyrebirdWindow = LyrebirdWindow(
title: title ?? process.id,
width: width,
height: height
)
win.open {
LyrebirdProcessView(process: process, engine: engine)
}
return win
}
}
#endif