v2.3.1 release: cross-platform LyrebirdGUIDemo + Linux demo ports + doc refresh

- New Demos/LyrebirdGUIDemo: one shared source (synths + node-based views) that
  bootstraps SwiftUI on macOS and GTK4/SwiftOpenUI on Linux; LYREBIRD_DEMO=vector|sine.
- The four CLI demos (Quickstart/Demo/NRT/Score) now build and run on Linux.
- README + Linux getting-started refreshed; LyrebirdATK row removed from the
  Extensions section pending collaborator sign-off.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 11:34:24 -08:00
parent 162da89319
commit 06bdcbbe92
17 changed files with 717 additions and 45 deletions
@@ -0,0 +1,181 @@
// main.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// Thin cross-platform entry point. The shared synths + views live in
// `LyrebirdGUIDemoKit`; this file only bootstraps the native toolkit and opens a
// window hosting the selected demo view:
//
// • macOS — AppKit `NSApplication` + `LyrebirdWindow` (SwiftUI content).
// • Linux — a GTK4 `App`/`WindowGroup` scene run by `GTK4Backend`.
//
// Run either with `swift run LyrebirdGUIDemo`. Pick the synth with
// `LYREBIRD_DEMO=vector` (default) or `LYREBIRD_DEMO=sine`.
//
// `@ViewBuilder` and the window hosts come from SwiftUI on macOS and from
// SwiftOpenUI (re-exported through `LyrebirdUI`) on Linux — hence the single
// `#if canImport(SwiftUI)` import guard.
#if canImport(SwiftUI)
import SwiftUI
#endif
import Foundation
import LyrebirdSynth
import LyrebirdUI
import LyrebirdGUIDemoKit
// MARK: - Shared setup (runs on both platforms)
let selection: DemoSelection = DemoSelection.fromEnvironment()
private let demoBlockSize: Int = 512
private let demoSampleRate: Double = 44_100.0
private let demoScopeBufferSize: Int = 2048
// Oscilloscope tap on the stereo output buses. Must be set before `start()`.
let demoScope: ScopeCapture = ScopeCapture(buses: [0, 1], bufferSize: demoScopeBufferSize)
// Core Audio on Apple, ALSA on a Linux build with libasound, else a silent
// OfflineDriver. The GUI runs either way; `isLiveAudioAvailable` reports which.
let demoDriver: any AudioDriver = makeDefaultAudioDriver()
let demoEngine: SynthesisEngine = SynthesisEngine(
blockSize: demoBlockSize,
sampleRate: demoSampleRate,
numOutputChannels: 2,
numInputChannels: 0,
driver: demoDriver
)
demoEngine.scopeTap = demoScope
// Both synths are cheap to build; only the selected one is added to the engine.
// Building both keeps the node extraction below branch-free (no force-unwrap).
let vectorSynth: VectorOscillatorUI = VectorOscillatorUI()
let sineSynth: SineToneUI = SineToneUI()
let activeSynth: SynthesizerBase = (selection == .vector) ? vectorSynth : sineSynth
// Extract the projected parameter nodes here, in main.swift's top-level
// `@MainActor` context: `SynthesizerBase` is `@MainActor`, so `synth.$…` is only
// reachable on the main actor. The nodes are not actor-isolated, so the
// (nonisolated, on Linux) view body can read them freely.
let vectorX: UIParamNode = vectorSynth.$x
let vectorY: UIParamNode = vectorSynth.$y
let vectorFreq: UIParamNode = vectorSynth.$frequency
let vectorAmp: UIParamNode = vectorSynth.$amplitude
let sineFreq: UIParamNode = sineSynth.$frequency
let sineAmp: UIParamNode = sineSynth.$amplitude
let sinePan: UIParamNode = sineSynth.$pan
// A static example envelope for the sine demo's envelope plot.
let demoEnvelope: Envelope = Envelope(
levels: [0.0001, 1.0, 0.6, 0.4, 0.0001],
durations: [0.05, 0.15, 0.4, 0.3],
curves: [.exponential, .exponential, .lin, .exponential],
loopNode: 2,
releaseNode: 4
)
// `SynthesisEngine` is not Sendable; the status view only reads plain CPU-load
// doubles off it, and this demo runs entirely on the UI thread, so a nonisolated
// handle is safe (mirrors the Linux UI demo).
nonisolated(unsafe) let statusEngine: SynthesisEngine = demoEngine
/// Builds the view for the active selection. `if`/`else` maps to the DSL's
/// `buildEither`, which both backends provide.
///
/// Isolation differs by backend: SwiftUI's `View` is `@MainActor`, so on macOS
/// this must be `@MainActor` to construct the view (and it is called from
/// AppKit's main-actor launch). SwiftOpenUI's `View` is nonisolated, so on Linux
/// this stays nonisolated and is callable from the nonisolated scene closure.
#if canImport(SwiftUI)
@MainActor
#endif
@ViewBuilder
func demoContent() -> some View {
if selection == .vector {
VectorOscillatorDemoView(
xNode: vectorX,
yNode: vectorY,
frequencyNode: vectorFreq,
amplitudeNode: vectorAmp,
scope: demoScope,
engine: statusEngine
)
} else {
SineToneDemoView(
frequencyNode: sineFreq,
amplitudeNode: sineAmp,
panNode: sinePan,
scope: demoScope,
engine: statusEngine,
envelope: demoEnvelope
)
}
}
// Start the engine and add the selected synth. `engine.start()` / `add` are
// @MainActor; main.swift's top level is main-actor isolated, so these are direct
// calls. On a build with no live backend the GUI still runs (silently).
do {
try demoEngine.start()
try demoEngine.add(activeSynth)
} catch {
print("[Lyrebird] demo engine setup failed: \(error)")
}
if !isLiveAudioAvailable {
print("[Lyrebird] no live audio backend — the controls still work, but there is no sound.")
}
// MARK: - macOS front end (AppKit + SwiftUI)
#if os(macOS)
import AppKit
final class DemoAppDelegate: NSObject, NSApplicationDelegate {
var window: LyrebirdWindow?
func applicationDidFinishLaunching(_ notification: Notification) {
let w: LyrebirdWindow = LyrebirdWindow(
title: selection.windowTitle,
width: 380,
height: 620
)
w.open { demoContent() }
window = w
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
true
}
func applicationWillTerminate(_ notification: Notification) {
demoEngine.stop()
}
}
MainActor.assumeIsolated {
let app: NSApplication = NSApplication.shared
app.setActivationPolicy(.regular)
let delegate: DemoAppDelegate = DemoAppDelegate()
app.delegate = delegate
app.run()
}
// MARK: - Linux front end (GTK4 + SwiftOpenUI)
#else
struct DemoApp: App {
var body: some Scene {
WindowGroup(selection.windowTitle) {
demoContent()
}
}
}
GTK4Backend().run(DemoApp.self)
#endif
@@ -0,0 +1,33 @@
// DemoSelection.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
/// Which synthesizer the demo runs, chosen by the `LYREBIRD_DEMO` environment
/// variable. Both front ends (AppKit on macOS, GTK4 on Linux) read the same
/// selection so one binary covers every patch.
public enum DemoSelection: String, Sendable {
/// Vector oscillator with an XY blend pad (the default).
case vector
/// Stereo sine tone with frequency / amplitude / pan controls.
case sine
/// Resolve the selection from `LYREBIRD_DEMO` (defaults to `.vector`).
public static func fromEnvironment() -> DemoSelection {
let raw: String = ProcessInfo.processInfo.environment["LYREBIRD_DEMO"]?.lowercased() ?? "vector"
return DemoSelection(rawValue: raw) ?? .vector
}
/// Title-bar text for the window hosting this demo.
public var windowTitle: String {
switch self {
case .vector: return "Lyrebird — Vector Oscillator"
case .sine: return "Lyrebird — Sine Tone"
}
}
}
@@ -0,0 +1,60 @@
// SineToneDemoView.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
#if canImport(SwiftUI)
import SwiftUI
#endif
import LyrebirdSynth
import LyrebirdUI
/// Live controls for ``SineToneUI``: a frequency slider, amplitude and pan knobs,
/// a level readout, a CPU-load strip, an oscilloscope, and a static envelope plot.
///
/// Node-based for the same reason as ``VectorOscillatorDemoView`` — the body must
/// compile under both SwiftUI's `@MainActor` body and SwiftOpenUI's nonisolated one.
public struct SineToneDemoView: View {
let frequencyNode: UIParamNode
let amplitudeNode: UIParamNode
let panNode: UIParamNode
let scope: ScopeCapture
let engine: SynthesisEngine
let envelope: Envelope
public init(
frequencyNode: UIParamNode,
amplitudeNode: UIParamNode,
panNode: UIParamNode,
scope: ScopeCapture,
engine: SynthesisEngine,
envelope: Envelope
) {
self.frequencyNode = frequencyNode
self.amplitudeNode = amplitudeNode
self.panNode = panNode
self.scope = scope
self.engine = engine
self.envelope = envelope
}
public var body: some View {
VStack {
Text("Lyrebird — Sine Tone")
.font(.headline)
ParameterSlider("Frequency", node: frequencyNode, range: 440.0...880.0)
HStack {
ParameterKnob("Amplitude", node: amplitudeNode, range: 0.0...1.0)
ParameterKnob("Pan", node: panNode, range: -1.0...1.0)
ParameterLabel("Level", node: amplitudeNode, decimalPlaces: 2)
}
LyrebirdStatusView(engine: engine)
LyrebirdScopeView(capture: scope)
.frame(height: 120)
LyrebirdEnvelopeView(envelope)
}
.padding()
}
}
@@ -0,0 +1,31 @@
// SineToneUI.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
/// A stereo sine tone whose frequency, amplitude, and pan are live-controllable
/// from the UI. The `@UIParam` slots are the same model both the SwiftUI (macOS)
/// and SwiftOpenUI (Linux) controls bind to — one synthesizer, two front ends.
public final class SineToneUI: SynthesizerBase {
/// Frequency in Hz. Slider range: 440–880 Hz.
@UIParam public var frequency: Double = 440.0
/// Output amplitude (linear gain). Knob range: 0–1.
@UIParam public var amplitude: Double = 0.25
/// Stereo pan position. Knob range: -1 (hard left) … 0 (center) … +1 (hard right).
@UIParam public var pan: Double = 0.0
public override init() {
super.init()
}
public override func build() {
let osc: OscSin.Audio = OscSin.Audio(freq: $frequency)
output(bus: 0, source: Pan2(input: osc * $amplitude, pan: $pan))
}
}
@@ -0,0 +1,70 @@
// VectorOscillatorDemoView.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// One platform `#if` at the import site; identical body beneath. On macOS SwiftUI
// supplies the View DSL; on Linux `LyrebirdUI` re-exports the SwiftOpenUI DSL, so
// `VStack` / `Text` / `.padding()` resolve on both. The Lyrebird controls
// (`ParameterXY`, `ParameterKnob`, …) and views live in `LyrebirdUI` on every
// platform and bind the same core `UIParamNode`s this view is handed.
#if canImport(SwiftUI)
import SwiftUI
#endif
import LyrebirdSynth
import LyrebirdUI
/// Live controls for ``VectorOscillatorUI``: an XY blend pad, frequency and
/// amplitude knobs, a CPU-load strip, and an oscilloscope of the stereo output.
///
/// The view holds the projected `UIParamNode`s rather than the `@MainActor`
/// synthesizer, because SwiftOpenUI's `body` is nonisolated (unlike SwiftUI's).
/// The caller extracts the nodes on the main actor and hands them in; the nodes
/// themselves are not actor-isolated, so a nonisolated body reads them freely.
public struct VectorOscillatorDemoView: View {
let xNode: UIParamNode
let yNode: UIParamNode
let frequencyNode: UIParamNode
let amplitudeNode: UIParamNode
let scope: ScopeCapture
let engine: SynthesisEngine
public init(
xNode: UIParamNode,
yNode: UIParamNode,
frequencyNode: UIParamNode,
amplitudeNode: UIParamNode,
scope: ScopeCapture,
engine: SynthesisEngine
) {
self.xNode = xNode
self.yNode = yNode
self.frequencyNode = frequencyNode
self.amplitudeNode = amplitudeNode
self.scope = scope
self.engine = engine
}
public var body: some View {
VStack {
Text("Lyrebird — Vector Oscillator")
.font(.headline)
ParameterXY(
xLabel: "X (A↔B)", xNode: xNode, xRange: 0.0...1.0,
yLabel: "Y (AB↔CD)", yNode: yNode, yRange: 0.0...1.0
)
.frame(width: 240, height: 240)
HStack {
ParameterKnob("Frequency", node: frequencyNode, range: 40.0...2000.0)
ParameterKnob("Amplitude", node: amplitudeNode, range: 0.0...1.0)
ParameterLabel("Freq (Hz)", node: frequencyNode, decimalPlaces: 1)
}
LyrebirdStatusView(engine: engine)
LyrebirdScopeView(capture: scope)
.frame(height: 120)
}
.padding()
}
}
@@ -0,0 +1,75 @@
// VectorOscillatorUI.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
/// A stereo vector oscillator whose XY position, frequency, and amplitude are
/// live-controllable from the UI.
///
/// Four corner wavetables are crossfaded on a 2D XY plane:
///
/// C (triangle) ── D (Hanning) (y = 1)
/// │ │
/// A (sine) ──── B (saw-ish) (y = 0)
/// x=0 x=1
///
/// Moving X blends A↔B (and C↔D); moving Y blends the AB mix into the CD mix.
public final class VectorOscillatorUI: SynthesizerBase {
/// X-axis blend position. 0 = corner A/C, 1 = corner B/D. Normalized [0, 1].
@UIParam public var x: Double = 0.5
/// Y-axis blend position. 0 = bottom (A, B), 1 = top (C, D). Normalized [0, 1].
@UIParam public var y: Double = 0.5
/// Oscillator frequency in Hz. Slider range: 40–2000 Hz.
@UIParam public var frequency: Double = 220.0
/// Output amplitude (linear gain). Knob range: 0–1.
@UIParam public var amplitude: Double = 0.25
private let bufferA: LyrebirdBuffer // corner A: sine
private let bufferB: LyrebirdBuffer // corner B: 16-partial saw-ish
private let bufferC: LyrebirdBuffer // corner C: triangle
private let bufferD: LyrebirdBuffer // corner D: Hanning window shape
public override init() {
let tableSize: Int = lyrebirdDefaultTableSize
let a: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
a.fillSine()
let b: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
b.fill(partials: 16)
let c: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
c.fillTriangle()
let d: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
d.fillHanning()
self.bufferA = a
self.bufferB = b
self.bufferC = c
self.bufferD = d
super.init()
}
public override func build() {
let osc: VectorOscillator.Audio = VectorOscillator.Audio(
bufferA: bufferA,
bufferB: bufferB,
bufferC: bufferC,
bufferD: bufferD,
freq: $frequency,
x: $x,
y: $y,
mul: $amplitude
)
output(bus: 0, source: Pan2(input: osc, pan: 0.0))
}
}