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
+5 -5
View File
@@ -172,7 +172,7 @@ public enum InteractiveShell {
// Ctrl+C or Ctrl+D — clean exit.
break shellLoop
} catch {
fputs("lyrebird: input error: \(error)\n", stderr)
printError("lyrebird: input error: \(error)\n")
break shellLoop
}
@@ -183,11 +183,11 @@ public enum InteractiveShell {
do {
try REPLLauncher.launch()
} catch CLIError.swiftNotFound {
fputs("error: swift not found. Install Xcode or a Swift toolchain.\n", stderr)
printError("error: swift not found. Install Xcode or a Swift toolchain.\n")
} catch CLIError.buildFailed(let code) {
fputs("error: swift build failed (exit code \(code)). REPL not started.\n", stderr)
printError("error: swift build failed (exit code \(code)). REPL not started.\n")
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
}
case .new(let name, let template, let lyrebirdPath):
@@ -215,7 +215,7 @@ public enum InteractiveShell {
do {
try ProjectRunner.run(release: release)
} catch ProjectRunner.Error.swiftNotFound {
fputs("error: swift not found. Install Xcode or a Swift toolchain.\n", stderr)
printError("error: swift not found. Install Xcode or a Swift toolchain.\n")
} catch ProjectRunner.Error.buildFailed(let code) {
print("Build failed (exit code \(code)).")
} catch {
+23 -23
View File
@@ -47,18 +47,18 @@ struct LyrebirdCLIMain {
print("Open Xcode → File → New → File from Template…")
print("→ scroll to the 'Lyrebird' section.")
} catch TemplateInstaller.Error.destinationExists(let path) {
fputs("error: '\(path)' already exists. Pass --force to replace it.\n", stderr)
printError("error: '\(path)' already exists. Pass --force to replace it.\n")
exit(1)
} catch TemplateInstaller.Error.bundleMissingTemplates(let path) {
fputs("error: bundled templates not found at \(path).\n", stderr)
fputs(" This usually means the lyrebird binary was built without\n", stderr)
fputs(" its resource bundle. Rebuild with `swift build`.\n", stderr)
printError("error: bundled templates not found at \(path).\n")
printError(" This usually means the lyrebird binary was built without\n")
printError(" its resource bundle. Rebuild with `swift build`.\n")
exit(1)
} catch TemplateInstaller.Error.fileSystemError(let path, let reason) {
fputs("error: could not write '\(path)': \(reason)\n", stderr)
printError("error: could not write '\(path)': \(reason)\n")
exit(1)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
@@ -74,10 +74,10 @@ struct LyrebirdCLIMain {
print(" \(TemplateInstaller.destinationURL.path)")
}
} catch TemplateInstaller.Error.fileSystemError(let path, let reason) {
fputs("error: could not remove '\(path)': \(reason)\n", stderr)
printError("error: could not remove '\(path)': \(reason)\n")
exit(1)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
@@ -92,13 +92,13 @@ struct LyrebirdCLIMain {
do {
try REPLLauncher.launch()
} catch CLIError.swiftNotFound {
fputs("error: swift not found. Install Xcode or a Swift toolchain.\n", stderr)
printError("error: swift not found. Install Xcode or a Swift toolchain.\n")
exit(1)
} catch CLIError.buildFailed(let code) {
fputs("error: swift build failed (exit code \(code)). REPL not started.\n", stderr)
printError("error: swift build failed (exit code \(code)). REPL not started.\n")
exit(code)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
@@ -121,13 +121,13 @@ struct LyrebirdCLIMain {
if let path: String = effectivePath {
print("Lyrebird dependency: local checkout at \(path)")
} else {
fputs("""
printError("""
warning: no local Lyrebird checkout found; pinning published \
\(ProjectScaffolder.lyrebirdPackageURL)@\(ProjectScaffolder.lyrebirdMinimumVersion). \
The generated template may use API newer than that release — if it \
fails to build, re-run with --lyrebird-path <checkout>.
""", stderr)
""")
}
do {
@@ -138,16 +138,16 @@ struct LyrebirdCLIMain {
)
print("Created \(name)/")
} catch ProjectScaffolder.Error.projectExists(let n) {
fputs("error: directory '\(n)' already exists.\n", stderr)
printError("error: directory '\(n)' already exists.\n")
exit(1)
} catch ProjectScaffolder.Error.invalidName(let n) {
fputs("error: '\(n)' is not a valid Swift module name.\n", stderr)
printError("error: '\(n)' is not a valid Swift module name.\n")
exit(1)
} catch ProjectScaffolder.Error.fileSystemError(let path, let reason) {
fputs("error: could not create '\(path)': \(reason)\n", stderr)
printError("error: could not create '\(path)': \(reason)\n")
exit(1)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
@@ -156,12 +156,12 @@ struct LyrebirdCLIMain {
do {
try ProjectRunner.run(release: release)
} catch ProjectRunner.Error.swiftNotFound {
fputs("error: swift not found. Install Xcode or a Swift toolchain.\n", stderr)
printError("error: swift not found. Install Xcode or a Swift toolchain.\n")
exit(1)
} catch ProjectRunner.Error.buildFailed(let code) {
exit(code)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
@@ -176,16 +176,16 @@ struct LyrebirdCLIMain {
let dest: String = path ?? SynthExporter.defaultOutputPath(for: name)
print("Exported \(dest)")
} catch SynthExporter.Error.invalidName(let n) {
fputs("error: '\(n)' is not a valid Swift identifier.\n", stderr)
printError("error: '\(n)' is not a valid Swift identifier.\n")
exit(1)
} catch SynthExporter.Error.fileExists(let p) {
fputs("error: '\(p)' already exists. Pass --overwrite to replace it.\n", stderr)
printError("error: '\(p)' already exists. Pass --overwrite to replace it.\n")
exit(1)
} catch SynthExporter.Error.fileSystemError(let p, let reason) {
fputs("error: could not write '\(p)': \(reason)\n", stderr)
printError("error: could not write '\(p)': \(reason)\n")
exit(1)
} catch {
fputs("error: \(error)\n", stderr)
printError("error: \(error)\n")
exit(1)
}
}
+6 -12
View File
@@ -82,19 +82,13 @@ public enum ProjectRunner {
// MARK: - Helpers
/// Returns the path to the `swift` binary.
/// Returns the path to the `swift` binary, located via ``lyrebirdLocateSwift()``
/// (searches `PATH` — honouring swiftly / Homebrew / custom toolchains — then
/// the well-known absolute locations).
///
/// Checks, in order:
/// - `/usr/bin/swift` — Xcode Command Line Tools / Xcode toolchain
/// - `/usr/local/bin/swift` — standalone toolchain (Intel Mac default)
/// - `/opt/homebrew/bin/swift` — Homebrew toolchain on Apple Silicon
///
/// Throws `ProjectRunner.Error.swiftNotFound` if none of the candidates exist.
/// Throws `ProjectRunner.Error.swiftNotFound` if no `swift` is found.
static func findSwift() throws -> String {
let candidates: [String] = ["/usr/bin/swift", "/usr/local/bin/swift", "/opt/homebrew/bin/swift"]
for path: String in candidates where FileManager.default.isExecutableFile(atPath: path) {
return path
}
throw Error.swiftNotFound
guard let path: String = lyrebirdLocateSwift() else { throw Error.swiftNotFound }
return path
}
}
+53 -15
View File
@@ -14,7 +14,9 @@ public enum ProjectTemplate: String, CaseIterable, Equatable {
/// `main` that plays a 440 Hz tone for ten seconds and exits. The fastest way
/// to hear Lyrebird after installing the CLI.
case quickstart = "quickstart"
/// Minimal engine setup with `CoreAudioDriver` and `RunLoop.main.run()`.
/// Minimal engine setup with the platform's live-audio driver
/// (`CoreAudioDriver` on Apple, `ALSAAudioDriver` on Linux) and
/// `RunLoop.main.run()`.
case basic = "basic"
/// Real-time demo: `SineTone` synthesizer with `@LiveParam` frequency and amplitude.
case demo = "demo"
@@ -474,14 +476,20 @@ public enum ProjectScaffolder {
}
}
// Lyrebird picks the platform's live-audio driver: Core Audio on Apple,
// ALSA on a Linux build with libasound. Where no live backend exists it
// returns an OfflineDriver, which runs the graph but makes no sound —
// `isLiveAudioAvailable` says which you got.
let driver: any AudioDriver = makeDefaultAudioDriver()
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.
let engine = SynthesisEngine(
blockSize: \(scaffoldDefaultBlockSize),
sampleRate: \(scaffoldDefaultSampleRate),
numOutputChannels: \(scaffoldDefaultOutputChannels),
numInputChannels: 0,
driver: CoreAudioDriver()
driver: driver
)
try engine.start() // opens the output device
@@ -506,13 +514,19 @@ public enum ProjectScaffolder {
import Foundation
import LyrebirdSynth
// Lyrebird picks the platform's live-audio driver: Core Audio on Apple,
// ALSA on a Linux build with libasound. Where no live backend exists it
// returns an OfflineDriver, which runs the graph but makes no sound —
// `isLiveAudioAvailable` says which you got.
let driver: any AudioDriver = makeDefaultAudioDriver()
// Configure the synthesis engine.
let engine = SynthesisEngine(
blockSize: \(scaffoldDefaultBlockSize),
sampleRate: \(scaffoldDefaultSampleRate),
numOutputChannels: \(scaffoldDefaultOutputChannels),
numInputChannels: \(scaffoldDefaultInputChannels),
driver: CoreAudioDriver()
driver: driver
)
// Add your Synthesizers here.
@@ -551,12 +565,18 @@ public enum ProjectScaffolder {
// MARK: - Main
// Lyrebird picks the platform's live-audio driver: Core Audio on Apple,
// ALSA on a Linux build with libasound. Where no live backend exists it
// returns an OfflineDriver, which runs the graph but makes no sound —
// `isLiveAudioAvailable` says which you got.
let driver: any AudioDriver = makeDefaultAudioDriver()
let engine = SynthesisEngine(
blockSize: \(scaffoldDefaultBlockSize),
sampleRate: \(scaffoldDefaultSampleRate),
numOutputChannels: \(scaffoldDefaultOutputChannels),
numInputChannels: \(scaffoldDefaultInputChannels),
driver: CoreAudioDriver()
driver: driver
)
do {
@@ -625,9 +645,19 @@ public enum ProjectScaffolder {
}
}
// Diagnostics go to stderr. Written through FileHandle rather than
// `fputs(_:stderr)` because Swift 6 rejects the imported C `stderr`
// global as not concurrency-safe on Linux.
func printError(_ message: String) {
FileHandle.standardError.write(Data(message.utf8))
}
// MARK: - Render
let outputURL = URL(fileURLWithPath: "output.caf")
// WAV, not CAF: CAF is an Apple container, and NRTDriver throws
// `unsupportedFormatOnPlatform` for it off Apple. A scaffolded project
// should run everywhere it compiles.
let outputURL = URL(fileURLWithPath: "output.wav")
let renderDuration = \(scaffoldDefaultNRTDuration)
let engine = SynthesisEngine(
@@ -635,14 +665,14 @@ public enum ProjectScaffolder {
sampleRate: \(scaffoldDefaultSampleRate),
numOutputChannels: \(scaffoldDefaultOutputChannels),
numInputChannels: 0,
driver: NRTDriver(outputURL: outputURL, duration: renderDuration)
driver: NRTDriver(outputURL: outputURL, duration: renderDuration, format: .wavFloat32)
)
// Add synthesizers BEFORE start() — NRTDriver renders synchronously inside start().
do {
try engine.add(\(name)Synth())
} catch {
fputs("engine.add failed: \\(error)\\n", stderr)
printError("engine.add failed: \\(error)\\n")
exit(1)
}
@@ -650,7 +680,7 @@ public enum ProjectScaffolder {
try engine.start()
print("Rendered \\(renderDuration)s → \\(outputURL.path)")
} catch {
fputs("Render failed: \\(error)\\n", stderr)
printError("Render failed: \\(error)\\n")
exit(1)
}
"""
@@ -744,6 +774,13 @@ public enum ProjectScaffolder {
}
}
// Diagnostics go to stderr. Written through FileHandle rather than
// `fputs(_:stderr)` because Swift 6 rejects the imported C `stderr`
// global as not concurrency-safe on Linux.
func printError(_ message: String) {
FileHandle.standardError.write(Data(message.utf8))
}
// MARK: - Output location
// Write next to this project's source rather than the launch directory.
@@ -762,7 +799,7 @@ public enum ProjectScaffolder {
try xml.write(to: xmlURL, atomically: true, encoding: .utf8)
print("MusicXML written → \\(xmlURL.path)")
} catch {
fputs("MusicXML export failed: \\(error)\\n", stderr)
printError("MusicXML export failed: \\(error)\\n")
exit(1)
}
@@ -771,21 +808,22 @@ public enum ProjectScaffolder {
let restored = try Score.fromMusicXML(data: score.toMusicXMLData())
print("Round-trip events: \\(score.allEvents.count) → \\(restored.allEvents.count)")
} catch {
fputs("MusicXML round-trip failed: \\(error)\\n", stderr)
printError("MusicXML round-trip failed: \\(error)\\n")
}
// MARK: - Render the score offline
let tailSeconds = 1.5
let renderDuration = score.totalBeats * secondsPerBeat + tailSeconds
let outputURL = outputDir.appendingPathComponent("score.caf")
// WAV, not CAF — see the nrt template: CAF is Apple-only.
let outputURL = outputDir.appendingPathComponent("score.wav")
let engine = SynthesisEngine(
blockSize: \(scaffoldDefaultBlockSize),
sampleRate: \(scaffoldDefaultSampleRate),
numOutputChannels: \(scaffoldDefaultOutputChannels),
numInputChannels: 0,
driver: NRTDriver(outputURL: outputURL, duration: renderDuration)
driver: NRTDriver(outputURL: outputURL, duration: renderDuration, format: .wavFloat32)
)
// Schedule one voice per sounding event BEFORE start() — NRTDriver
@@ -805,7 +843,7 @@ public enum ProjectScaffolder {
try engine.schedule(voice, after: event.beat * secondsPerBeat)
scheduled += 1
} catch {
fputs("engine.schedule failed: \\(error)\\n", stderr)
printError("engine.schedule failed: \\(error)\\n")
}
}
print("Scheduled \\(scheduled) voices.")
@@ -814,7 +852,7 @@ public enum ProjectScaffolder {
try engine.start()
print("Rendered \\(renderDuration)s → \\(outputURL.path)")
} catch {
fputs("Render failed: \\(error)\\n", stderr)
printError("Render failed: \\(error)\\n")
exit(1)
}
"""
+6 -9
View File
@@ -51,16 +51,13 @@ public enum REPLLauncher {
.appendingPathComponent(".lyrebird_history").path
}
/// Returns the path to the `swift` binary.
///
/// Checks `/usr/bin/swift` (Xcode toolchain on macOS) and `/usr/local/bin/swift`
/// (standalone toolchain). Throws `CLIError.swiftNotFound` if neither exists.
/// Returns the path to the `swift` binary, located via ``lyrebirdLocateSwift()``
/// (searches `PATH` — honouring swiftly / Homebrew / custom toolchains — then
/// the well-known absolute locations). Throws `CLIError.swiftNotFound` if none
/// is found.
public static func findSwift() throws -> String {
let candidates: [String] = ["/usr/bin/swift", "/usr/local/bin/swift"]
for path: String in candidates where FileManager.default.isExecutableFile(atPath: path) {
return path
}
throw CLIError.swiftNotFound
guard let path: String = lyrebirdLocateSwift() else { throw CLIError.swiftNotFound }
return path
}
/// Builds a `Process` that runs `swift` with the given arguments in `directory`.
+18
View File
@@ -0,0 +1,18 @@
// StandardError.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
/// Writes `message` to standard error.
///
/// Uses `FileHandle.standardError` rather than the C `stderr` global: on Linux,
/// Swift 6 flags a direct reference to the imported `stderr` (a mutable global
/// `var`) as `reference to var 'stderr' is not concurrency-safe`. `FileHandle`
/// carries no such hazard and is identical across platforms.
@inline(__always)
func printError(_ message: String) {
try? FileHandle.standardError.write(contentsOf: Data(message.utf8))
}
+44
View File
@@ -0,0 +1,44 @@
// SwiftToolchain.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
/// Locates the `swift` executable for `lyrebird run` / `lyrebird repl`.
///
/// Searches `PATH` first, so whatever toolchain the user's shell resolves
/// `swift` to is honoured — a swiftly shim (`~/.local/share/swiftly/bin/swift`),
/// Homebrew, or a custom prefix — then falls back to the well-known absolute
/// locations for a bare environment with an empty `PATH`. Returns `nil` if no
/// `swift` executable is found anywhere.
///
/// The hardcoded fallbacks alone were macOS-only (`/usr/bin/swift` etc.) and
/// missed every non-default Linux install, most notably swiftly.
func lyrebirdLocateSwift() -> String? {
let fileManager: FileManager = FileManager.default
let executableName: String = "swift"
// PATH, in order — the active toolchain wins over the fallbacks below.
if let pathEnv: String = ProcessInfo.processInfo.environment["PATH"] {
let directories: [String] = pathEnv
.split(separator: ":", omittingEmptySubsequences: true)
.map(String.init)
for directory: String in directories {
let candidate: String = directory.hasSuffix("/")
? directory + executableName
: directory + "/" + executableName
if fileManager.isExecutableFile(atPath: candidate) {
return candidate
}
}
}
// Well-known absolute locations, for an environment with no usable PATH.
let fallbacks: [String] = ["/usr/bin/swift", "/usr/local/bin/swift", "/opt/homebrew/bin/swift"]
for path: String in fallbacks where fileManager.isExecutableFile(atPath: path) {
return path
}
return nil
}
+1 -1
View File
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: MIT
/// The current Lyrebird framework and CLI version.
public let lyrebirdVersion: String = "1.0.0"
public let lyrebirdVersion: String = "2.0.0"
/// The banner printed when the interactive shell or REPL session starts.
public let welcomeBanner: String = """