49 lines
1.4 KiB
Swift
49 lines
1.4 KiB
Swift
// main.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
|
|
// Output paths — both land on the Desktop.
|
|
let cafURL: URL = FileManager.default.homeDirectoryForCurrentUser
|
|
.appendingPathComponent("Desktop/LyrebirdScoreDemo.caf")
|
|
|
|
// 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: cafURL, duration: totalDuration)
|
|
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, cafURL.path))
|
|
|
|
do {
|
|
try engine.start()
|
|
print("Done.")
|
|
} catch {
|
|
fputs("Render failed: \(error)\n", stderr)
|
|
exit(1)
|
|
}
|