06bdcbbe92
- 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>
56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
// main.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
|
|
// 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
|
|
let blockSize: Int = 512
|
|
|
|
// Build the score first — totalDuration must be known before NRTDriver is created.
|
|
let demo: ScoreDemo = ScoreDemo()
|
|
let totalDuration: Double = demo.totalDuration
|
|
|
|
// MusicXML export and round-trip before audio engine creation.
|
|
demo.runDemo()
|
|
|
|
// Create NRTDriver and engine.
|
|
let driver: NRTDriver = NRTDriver(outputURL: audioURL, duration: totalDuration, format: outputFormat)
|
|
let engine: SynthesisEngine = SynthesisEngine(
|
|
blockSize: blockSize,
|
|
sampleRate: sampleRate,
|
|
numOutputChannels: 2,
|
|
numInputChannels: 0,
|
|
driver: driver
|
|
)
|
|
|
|
// Schedule all score voices. SynthesizerBase (and thus scheduleVoices) is
|
|
// @MainActor-isolated; SwiftPM's top-level entry point is itself main-actor
|
|
// isolated, so this is a plain direct call — no MainActor hop needed.
|
|
demo.scheduleVoices(engine: engine)
|
|
|
|
print(String(format: "Rendering %.2f s → %@", totalDuration, audioURL.path))
|
|
|
|
do {
|
|
try engine.start()
|
|
print("Done.")
|
|
} catch {
|
|
FileHandle.standardError.write(Data("Render failed: \(error)\n".utf8))
|
|
exit(1)
|
|
}
|