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
+3 -1
View File
@@ -7,12 +7,14 @@
import Foundation
import LyrebirdSynth
// `makeDefaultAudioDriver()` selects the platform backend — Core Audio on Apple,
// ALSA on Linux (needs libasound) — so the demo builds and runs on both.
let engine = SynthesisEngine(
blockSize: 512,
sampleRate: 44100,
numOutputChannels: 2,
numInputChannels: 2,
driver: CoreAudioDriver()
driver: makeDefaultAudioDriver()
)
do {
+24
View File
@@ -0,0 +1,24 @@
{
"originHash" : "c2996d6577ec0139a89be2f2d57d304047b7d5bf7f7eba2577fde9dc2fdc0b91",
"pins" : [
{
"identity" : "linenoise-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/andybest/linenoise-swift",
"state" : {
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
"version" : "0.0.3"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
"version" : "7.3.4"
}
}
],
"version" : 3
}
+48
View File
@@ -0,0 +1,48 @@
// Package.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// swift-tools-version: 6.0
import PackageDescription
// A single cross-platform GUI demo: one shared library of synths + views, and a
// thin executable entry point that bootstraps the native toolkit per platform —
// AppKit/SwiftUI on macOS, GTK4/SwiftOpenUI on Linux. The view bodies are written
// to the subset of the View DSL that both backends share, so the UI is one source.
//
// macOS: swift run LyrebirdGUIDemo (or open the thin Xcode project)
// Linux: swift run LyrebirdGUIDemo (needs libgtk-4-dev + libasound2-dev)
//
// Select the synth with LYREBIRD_DEMO=vector (default) or LYREBIRD_DEMO=sine.
let package = Package(
name: "LyrebirdGUIDemo",
platforms: [.macOS(.v15)],
products: [
.library(name: "LyrebirdGUIDemoKit", targets: ["LyrebirdGUIDemoKit"]),
.executable(name: "LyrebirdGUIDemo", targets: ["LyrebirdGUIDemo"]),
],
dependencies: [
.package(path: "../.."),
],
targets: [
.target(
name: "LyrebirdGUIDemoKit",
dependencies: [
.product(name: "Lyrebird", package: "Lyrebird"),
.product(name: "LyrebirdUI", package: "Lyrebird"),
],
path: "Sources/LyrebirdGUIDemoKit"
),
.executableTarget(
name: "LyrebirdGUIDemo",
dependencies: [
"LyrebirdGUIDemoKit",
.product(name: "Lyrebird", package: "Lyrebird"),
.product(name: "LyrebirdUI", package: "Lyrebird"),
],
path: "Sources/LyrebirdGUIDemo"
),
]
)
+58
View File
@@ -0,0 +1,58 @@
<!--
README.md
Lyrebird
Copyright (c) 2026 Joshua Parmenter / realizedsound
SPDX-License-Identifier: MIT
-->
# LyrebirdGUIDemo — one GUI demo, two platforms
A live-controllable synth GUI that builds and runs from a single source tree on
**macOS** (AppKit + SwiftUI) and **Linux** (GTK4 + SwiftOpenUI). It is the
cross-platform counterpart to the richer, macOS-only `LyrebirdMacOSDemo` Xcode
project.
The split follows the "mostly in a package, thin entry points" shape:
| Piece | Where | Platform |
|---|---|---|
| Synths + views | `Sources/LyrebirdGUIDemoKit/` | shared — one source |
| App bootstrap | `Sources/LyrebirdGUIDemo/main.swift` | one `#if` (AppKit vs GTK4) |
The view bodies are written to the subset of the View DSL that SwiftUI and
SwiftOpenUI share, so there is **one** body per view — not a macOS copy and a
Linux copy. Both back ends bind the same core `@UIParam` / `UIParamNode` model,
so the controls, the oscilloscope, and the CPU meters are identical.
## Run it
```bash
swift run LyrebirdGUIDemo # vector oscillator (default)
LYREBIRD_DEMO=sine swift run LyrebirdGUIDemo # stereo sine tone
```
- **macOS** — no extra setup; a native window opens with live audio via Core Audio.
- **Linux** — needs `libgtk-4-dev` (GUI) and `libasound2-dev` + a sound device
(audio). Without a sound backend the window still opens and the controls work;
there is just no sound (`isLiveAudioAvailable` reports it, and the console says so).
## Open in an IDE
- **Xcode (macOS)** — open the folder (or `Package.swift`); Xcode treats it as a
SwiftPM package. Pick the `LyrebirdGUIDemo` scheme and Run. No `.xcodeproj` to
maintain — the package *is* the project.
- **VS Code (Linux)** — open the folder with the Swift extension
(`swiftlang.swift-vscode`); it picks up `Package.swift`. Run `LyrebirdGUIDemo`
from the test/run explorer or a terminal.
## What each demo shows
- **vector** — `VectorOscillatorUI`: an XY pad crossfades four corner wavetables
(sine / saw-ish / triangle / Hanning); frequency and amplitude knobs; a live
oscilloscope and CPU-load strip.
- **sine** — `SineToneUI`: a frequency slider, amplitude and pan knobs, a level
readout, the scope and CPU strip, and a static envelope plot.
Add a synth by dropping a `SynthesizerBase` subclass and a node-based view into
`LyrebirdGUIDemoKit`, then extend `DemoSelection` and the `demoContent()` switch
in `main.swift`.
@@ -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))
}
}
@@ -7,9 +7,21 @@
import Foundation
import LyrebirdSynth
// Output to the Desktop — triggers the NSDesktopFolderUsageDescription TCC prompt on first run.
let outputURL = FileManager.default.homeDirectoryForCurrentUser
// Offline render has no audio device, so this demo runs the same on macOS and Linux.
// Only the output container differs: CAF is Apple-only (it goes through `ExtAudioFile`),
// so off Apple we write the portable WAV codec instead.
#if canImport(AudioToolbox)
// Apple: CAF on the Desktop — triggers the NSDesktopFolderUsageDescription TCC prompt on first run.
let outputURL: URL = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Desktop/nrt_output.caf")
let outputFormat: AudioFileFormat = .cafFloat32
#else
// Linux (and any non-Apple): WAV in the current working directory — no special-folder
// permission needed, and `WavFileWriter` is the portable encoder off Apple.
let outputURL: URL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
.appendingPathComponent("nrt_output.wav")
let outputFormat: AudioFileFormat = .wavFloat32
#endif
// Render parameters.
let sampleRate: Double = 48000
@@ -43,7 +55,7 @@ let tailDuration: Double = 0.1
let lastStart = voices.map(\.start).max() ?? 0.0
let totalDur = lastStart + interSetDelay + voiceLength + tailDuration
let driver = NRTDriver(outputURL: outputURL, duration: totalDur)
let driver = NRTDriver(outputURL: outputURL, duration: totalDur, format: outputFormat)
let engine = SynthesisEngine(
blockSize: blockSize,
sampleRate: sampleRate,
@@ -77,7 +89,7 @@ do {
)
}
} catch {
fputs("engine.schedule failed: \(error)\n", stderr)
FileHandle.standardError.write(Data("engine.schedule failed: \(error)\n".utf8))
exit(1)
}
@@ -87,7 +99,7 @@ do {
try engine.start()
print("Done.")
} catch {
fputs("Render failed: \(error)\n", stderr)
FileHandle.standardError.write(Data("Render failed: \(error)\n".utf8))
exit(1)
}
@@ -17,13 +17,15 @@ import LyrebirdSynth
let quickstartDuration: Double = 5.0
do {
// The engine owns Core Audio and runs the graph on the RT thread.
// The engine owns the audio device and runs the graph on the RT thread.
// `makeDefaultAudioDriver()` picks the platform backend — Core Audio on Apple,
// ALSA on Linux (needs libasound) — so this demo builds and runs on both.
let engine = SynthesisEngine(
blockSize: 512,
sampleRate: 48000,
numOutputChannels: 2,
numInputChannels: 0,
driver: CoreAudioDriver()
driver: makeDefaultAudioDriver()
)
try engine.start()
@@ -39,6 +41,6 @@ do {
engine.stop() // closes the device
print("Done.")
} catch {
fputs("Lyrebird quickstart failed to start: \(error)\n", stderr)
FileHandle.standardError.write(Data("Lyrebird quickstart failed to start: \(error)\n".utf8))
exit(1)
}
@@ -7,6 +7,17 @@
import Foundation
import LyrebirdSynth
/// Directory this demo writes its output files to: the Desktop on Apple (matching the
/// Xcode scheme), the current working directory elsewhere (Linux has no Desktop folder
/// to grant, and `swift run` starts from a known location).
func demoOutputDirectory() -> URL {
#if canImport(AudioToolbox)
return FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Desktop")
#else
return URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
#endif
}
/// Builds a multi-part Score using every DSL node type, exports MusicXML, round-trips
/// the document, and reports render statistics.
///
@@ -58,15 +69,15 @@ final class ScoreDemo: DemoProtocol {
/// Export MusicXML and print the round-trip event count. Does not interact with
/// the engine or schedule any voices.
func runDemo() {
// Step 1 — write MusicXML to Desktop.
let xmlURL: URL = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Desktop/LyrebirdScoreDemo.musicxml")
// Step 1 — write MusicXML to the demo output directory.
let xmlURL: URL = demoOutputDirectory()
.appendingPathComponent("LyrebirdScoreDemo.musicxml")
let xmlString: String = score.toMusicXMLString()
do {
try xmlString.write(to: xmlURL, atomically: true, encoding: .utf8)
print("MusicXML written → \(xmlURL.path)")
} catch {
fputs("Failed to write MusicXML: \(error)\n", stderr)
FileHandle.standardError.write(Data("Failed to write MusicXML: \(error)\n".utf8))
}
// Step 2 — round-trip sanity check.
@@ -105,7 +116,7 @@ final class ScoreDemo: DemoProtocol {
print("Score key (G major): \(rt.keySignature == .gMajor ? "OK" : "MISMATCH(\(rt.keySignature))")")
}
} catch {
fputs("MusicXML round-trip failed: \(error)\n", stderr)
FileHandle.standardError.write(Data("MusicXML round-trip failed: \(error)\n".utf8))
}
// Step 2b — sectioned showcase: multiple Sections assembled into one
@@ -119,8 +130,8 @@ final class ScoreDemo: DemoProtocol {
// `rehearsalMarksAsStaffText: true` option emits boxed <words> staff text
// instead, but that attaches to a staff and can collide with notation.
let showcase: Score = ScoreDemo.makeSectionedShowcase()
let showcaseURL: URL = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Desktop/LyrebirdScoreSections.musicxml")
let showcaseURL: URL = demoOutputDirectory()
.appendingPathComponent("LyrebirdScoreSections.musicxml")
do {
try showcase.toMusicXMLString().write(to: showcaseURL, atomically: true, encoding: .utf8)
print("Sectioned showcase written → \(showcaseURL.path)")
@@ -132,7 +143,7 @@ final class ScoreDemo: DemoProtocol {
print("Sections → rehearsal marks: \(markList)")
print("Sectioned showcase parts: \(showcase.parts.map { $0.name }.joined(separator: ", "))")
} catch {
fputs("Failed to write sectioned showcase: \(error)\n", stderr)
FileHandle.standardError.write(Data("Failed to write sectioned showcase: \(error)\n".utf8))
}
// Step 3 — report render parameters.
@@ -185,7 +196,7 @@ final class ScoreDemo: DemoProtocol {
try engine.schedule(voice, after: startSeconds)
scheduledCount += 1
} catch {
fputs("engine.schedule failed for beat \(event.beat): \(error)\n", stderr)
FileHandle.standardError.write(Data("engine.schedule failed for beat \(event.beat): \(error)\n".utf8))
failedCount += 1
}
}
@@ -7,9 +7,16 @@
import Foundation
import LyrebirdSynth
// Output paths — both land on the Desktop.
let cafURL: URL = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Desktop/LyrebirdScoreDemo.caf")
// Audio output. CAF is Apple-only (ExtAudioFile), so off Apple we render the
// portable WAV codec; `demoOutputDirectory()` is the Desktop on Apple and the
// current working directory elsewhere (see ScoreDemo.swift).
#if canImport(AudioToolbox)
let outputFormat: AudioFileFormat = .cafFloat32
let audioURL: URL = demoOutputDirectory().appendingPathComponent("LyrebirdScoreDemo.caf")
#else
let outputFormat: AudioFileFormat = .wavFloat32
let audioURL: URL = demoOutputDirectory().appendingPathComponent("LyrebirdScoreDemo.wav")
#endif
// Render parameters.
let sampleRate: Double = 48000
@@ -23,7 +30,7 @@ let totalDuration: Double = demo.totalDuration
demo.runDemo()
// Create NRTDriver and engine.
let driver: NRTDriver = NRTDriver(outputURL: cafURL, duration: totalDuration)
let driver: NRTDriver = NRTDriver(outputURL: audioURL, duration: totalDuration, format: outputFormat)
let engine: SynthesisEngine = SynthesisEngine(
blockSize: blockSize,
sampleRate: sampleRate,
@@ -37,12 +44,12 @@ let engine: SynthesisEngine = SynthesisEngine(
// isolated, so this is a plain direct call — no MainActor hop needed.
demo.scheduleVoices(engine: engine)
print(String(format: "Rendering %.2f s → %@", totalDuration, cafURL.path))
print(String(format: "Rendering %.2f s → %@", totalDuration, audioURL.path))
do {
try engine.start()
print("Done.")
} catch {
fputs("Render failed: \(error)\n", stderr)
FileHandle.standardError.write(Data("Render failed: \(error)\n".utf8))
exit(1)
}
+44 -17
View File
@@ -6,6 +6,25 @@ Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a s
---
## Try it — run a demo
The fastest way in is a demo project, not a snippet to copy. Each demo under [`Demos/`](Demos/) is a standalone SwiftPM package that depends on this checkout, so `swift run` from its folder builds and runs it — on **macOS** (Xcode optional) and **Linux** (VS Code optional), no project file to open:
```bash
git clone https://git.lyrebirdsynth.net/josh/Lyrebird.git
cd Lyrebird
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine — the shortest path to sound
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → an audio file, no sound device needed
(cd Demos/LyrebirdDemo && swift run) # a fuller reverb smoke-test through your default output
```
These three run the same on macOS and Linux. Each has a `Synthesizers/` folder — drop a `SynthesizerBase` subclass in, re-run, and you are building your own voice. The GUI demos (SwiftUI on macOS/iOS; the GTK4 UI on Linux) and the full list are under [Demo projects](#demo-projects).
On Linux the live-audio demos need `libasound2-dev`; the offline NRT demo needs nothing. Full Linux setup is in the [On Linux](#on-linux--vs-code-or-any-editor-no-xcode) notes and [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
---
## A quick taste
Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives the platform audio backend (Core Audio on Apple, ALSA on Linux) and schedules voices sample-accurately.
@@ -192,13 +211,13 @@ Workspace scheme selector exposes ten entries:
| Scheme | Purpose | Platform |
|---|---|---|
| `Lyrebird-Package` | Umbrella — builds Lyrebird + LyrebirdUI + LyrebirdLiveCompile + LyrebirdC + LyrebirdBenchmark + LyrebirdCLI, runs the test suites, launches/profiles `LyrebirdCLI` | macOS |
| `LyrebirdQuickstartDemo` | CLI — fastest sound: a one-oscillator `SineTone` that plays 440 Hz for 10 s and exits | macOS |
| `LyrebirdQuickstartDemo` | CLI — fastest sound: a one-oscillator `SineTone` that plays 440 Hz for 10 s and exits | macOS · Linux |
| `LyrebirdUI` | Builds the `LyrebirdUI` module only (SwiftUI parameter controls + visualisations) | macOS |
| `LyrebirdDemo` | CLI — plays through default output via `CoreAudioDriver` | macOS |
| `LyrebirdDemo` | CLI — plays through default output via `makeDefaultAudioDriver()` | macOS · Linux |
| `LyrebirdMacOSDemo` | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
| `LyrebirdiOSDemo` | SwiftUI app — same UI via `iOSAudioDriver` (RemoteIO) | iOS |
| `LyrebirdNRTDemo` | CLI — offline render to CAF via `NRTDriver` | macOS |
| `LyrebirdScoreDemo` | CLI — builds notated `Score`s (result-builder DSL), exports MusicXML, renders to CAF via `NRTDriver` | macOS |
| `LyrebirdNRTDemo` | CLI — offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
| `LyrebirdScoreDemo` | CLI — builds notated `Score`s (result-builder DSL), exports MusicXML, renders via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
| `LyrebirdAUv3Demo` | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro, etc. Run the host app once to register the extension. | macOS |
| `LyrebirdScratch` | Live-coding scratchpad — type Swift snippets, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
@@ -231,7 +250,17 @@ swift run LyrebirdCLI repl # the CLI (also `new`
LYREBIRD_ENABLE_LINUX_UI=1 swift run LyrebirdUILinuxDemo # the GTK4 UI demo
```
The SwiftUI / AUv3 / iOS demos in the scheme table do not build on Linux. Full walk-through — toolchain, VS Code, building, running a sample: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
The CLI demo projects build and run on Linux too — each is its own package, so run it from its folder (`swift run` picks up the single executable):
```bash
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → ./nrt_output.wav (no audio device needed)
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine (needs libasound + a sound device)
(cd Demos/LyrebirdDemo && swift run) # reverb smoke-test through default output
(cd Demos/LyrebirdScoreDemo && swift run) # notated Score → MusicXML + a rendered WAV (no device)
(cd Demos/LyrebirdGUIDemo && swift run) # cross-platform GUI via GTK4 (needs libgtk-4-dev); LYREBIRD_DEMO=vector|sine
```
The four CLI demos plus `LyrebirdGUIDemo` (a GTK4 window here, SwiftUI on macOS) run on Linux; the AUv3 / iOS / `LyrebirdMacOSDemo` GUI demos are Apple-only. Full walk-through — toolchain, VS Code, building, running a sample: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
---
@@ -243,23 +272,24 @@ swift test # run all 5481 tests
swift test --filter LyrebirdTests # run one suite
swift run lyrebird # run the CLI
swift run lyrebird repl # Swift REPL with Lyrebird available
swift run LyrebirdDemo # run the hardware smoke-test demo
(cd Demos/LyrebirdDemo && swift run) # run a demo project (each Demos/* is its own package)
```
---
## Demo projects
All eight live in [`Demos/`](Demos/). Open via `Lyrebird.xcworkspace`.
All nine live in [`Demos/`](Demos/). Each is its own SwiftPM package depending on the local checkout, so a demo runs with `swift run` from its folder on **any** platform it supports — no Xcode needed. On macOS you can also open them together via `Lyrebird.xcworkspace`. The demos marked **Linux** build and run on Linux as well (see the Linux VS Code section above); `LyrebirdGUIDemo` is the cross-platform GUI — SwiftUI on macOS, GTK4 on Linux, one source.
| Demo | What it does | Platform |
|---|---|---|
| [`LyrebirdQuickstartDemo`](Demos/LyrebirdQuickstartDemo/) | CLI — fastest sound: a one-oscillator `SineTone` plays 440 Hz for 10 s, then exits (mirrors the `quickstart` template) | macOS |
| [`LyrebirdDemo`](Demos/LyrebirdDemo/) | CLI — plays through default output via `CoreAudioDriver` | macOS |
| [`LyrebirdMacOSDemo`](Demos/LyrebirdMacOSDemo/) | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
| [`LyrebirdQuickstartDemo`](Demos/LyrebirdQuickstartDemo/) | CLI — fastest sound: a one-oscillator `SineTone` plays 440 Hz for 10 s, then exits (mirrors the `quickstart` template) | macOS · Linux |
| [`LyrebirdDemo`](Demos/LyrebirdDemo/) | CLI — plays through default output via `makeDefaultAudioDriver()` (Core Audio on macOS, ALSA on Linux) | macOS · Linux |
| [`LyrebirdGUIDemo`](Demos/LyrebirdGUIDemo/) | GUI — live `@UIParam` controls, XY pad, oscilloscope, CPU meters, from one shared source; AppKit/SwiftUI on macOS, GTK4/SwiftOpenUI on Linux (`LYREBIRD_DEMO=vector`/`sine`) | macOS · Linux |
| [`LyrebirdMacOSDemo`](Demos/LyrebirdMacOSDemo/) | SwiftUI app — live oscilloscope, `@UIParam` knobs, vector / sine / spectral-bin-delay patches | macOS |
| [`LyrebirdiOSDemo`](Demos/LyrebirdiOSDemo/) | SwiftUI app — same UI system via `iOSAudioDriver` (RemoteIO) | iOS |
| [`LyrebirdNRTDemo`](Demos/LyrebirdNRTDemo/) | CLI — offline render to CAF file via `NRTDriver` | macOS |
| [`LyrebirdScoreDemo`](Demos/LyrebirdScoreDemo/) | CLI — notated `Score` → MusicXML export + offline render to CAF via `NRTDriver` | macOS |
| [`LyrebirdNRTDemo`](Demos/LyrebirdNRTDemo/) | CLI — offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
| [`LyrebirdScoreDemo`](Demos/LyrebirdScoreDemo/) | CLI — notated `Score` → MusicXML export + offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
| [`LyrebirdAUv3Demo`](Demos/LyrebirdAUv3Demo/) | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro | macOS |
| [`LyrebirdScratch`](Demos/LyrebirdScratch/) | Live-coding scratchpad — type Swift, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
@@ -297,14 +327,10 @@ Arrow-key editing, tab completion, persistent history (`~/.lyrebird_history`). `
Lyrebird supports out-of-tree Swift packages that add `Generator` or `Synthesizer` implementations. Extension packages depend on Lyrebird via SwiftPM, host their own source, and ship their own version releases — core users pin the version range they want.
| Package | Description |
|---|---|
| [`LyrebirdATK`](#) | First-order Ambisonics toolkit (37 `Foa*` UGens, MIT KEMAR HRIR set, binaural decoder). Worked example for the Extension SDK. |
Building your own extension package:
- **API contract**: [`docs/protocols/extension-sdk.md`](docs/protocols/extension-sdk.md) — tier-1 stable public surface + tier-2 `@_spi(LyrebirdExtensions)` symbols and versioning policy.
- **Walk-through**: [`docs/extension-authors-guide.md`](docs/extension-authors-guide.md) — end-to-end build a new extension package using LyrebirdATK as the reference.
- **Walk-through**: [`docs/extension-authors-guide.md`](docs/extension-authors-guide.md) — end-to-end build a new extension package.
---
@@ -322,6 +348,7 @@ LyrebirdII/
├── Demos/
│ ├── LyrebirdQuickstartDemo/ # fastest sound — SineTone plays 10 s then exits
│ ├── LyrebirdDemo/ # (same as Sources/LyrebirdDemo — workspace target)
│ ├── LyrebirdGUIDemo/ # cross-platform GUI — SwiftUI (macOS) + GTK4 (Linux), one source
│ ├── LyrebirdMacOSDemo/ # macOS SwiftUI app
│ ├── LyrebirdiOSDemo/ # iOS SwiftUI app
│ ├── LyrebirdNRTDemo/ # offline renderer
@@ -41,9 +41,11 @@ EXCLUSIONS=(
)
# Regex the release repo's origin URL must match — a guard so --apply can never
# nuke the wrong directory. Requires the mooo host AND the `Lyrebird` repo path
# (so a sibling mooo repo like ShoeGaze can't be mistaken for the release repo).
RELEASE_REMOTE_REGEX='realizedsound\.mooo\.com.*/Lyrebird(\.git)?/?$'
# nuke the wrong directory. Requires the gitea host AND the `Lyrebird` repo path
# (so a sibling repo like ShoeGaze can't be mistaken for the release repo).
# Accepts both the canonical host (git.lyrebirdsynth.net) and its legacy alias
# (realizedsound.mooo.com) — a DNS CNAME to the same gitea server.
RELEASE_REMOTE_REGEX='(git\.lyrebirdsynth\.net|realizedsound\.mooo\.com).*/Lyrebird(\.git)?/?$'
while [ $# -gt 0 ]; do
case "$1" in
@@ -66,7 +68,7 @@ fail() { echo "ERROR: $*" >&2; exit 1; }
RELEASE_URL="$(git -C "$RELEASE" remote get-url origin 2>/dev/null || echo "")"
if [[ ! "$RELEASE_URL" =~ $RELEASE_REMOTE_REGEX ]]; then
fail "release origin ('$RELEASE_URL') is not the Lyrebird mooo release repo (must match /$RELEASE_REMOTE_REGEX/) — refusing to sync. Wrong --release path?"
fail "release origin ('$RELEASE_URL') is not the Lyrebird gitea release repo (must match /$RELEASE_REMOTE_REGEX/) — refusing to sync. Wrong --release path?"
fi
# --- Guard: dev working tree should be committed (we archive HEAD) -----------
+29
View File
@@ -124,6 +124,35 @@ swift run # a 440 Hz sine for a few seconds
built with `LYREBIRD_DISABLE_ALSA=1`), in which case `makeDefaultAudioDriver()`
returns a silent `OfflineDriver`.
### The bundled CLI demos
The scaffold templates above make a *new* project. To run the demos that ship in
this repo instead, each lives in its own package under `Demos/` and runs with
`swift run` from its folder — the same source as the macOS Xcode schemes:
```bash
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → ./nrt_output.wav (no audio device)
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine (needs libasound + a device)
(cd Demos/LyrebirdDemo && swift run) # reverb smoke-test through the default output
(cd Demos/LyrebirdScoreDemo && swift run) # notated Score → MusicXML + a rendered WAV (no device)
```
`LyrebirdNRTDemo` and `LyrebirdScoreDemo` write a WAV off Apple (CAF is Apple-only)
into the current directory; the live demos use `makeDefaultAudioDriver()` →
`ALSAAudioDriver`.
There is also a cross-platform **GUI** demo — `Demos/LyrebirdGUIDemo` — whose synths
and views are one shared source that bootstraps SwiftUI on macOS and GTK4 on Linux.
It needs `libgtk-4-dev` + `libgtksourceview-5-dev` (and `libasound2-dev` + a device
for sound):
```bash
(cd Demos/LyrebirdGUIDemo && swift run) # vector oscillator (default)
(cd Demos/LyrebirdGUIDemo && LYREBIRD_DEMO=sine swift run) # stereo sine tone
```
The AUv3 / iOS / `LyrebirdMacOSDemo` GUI demos are Apple-only.
### REPL and live coding
```bash