Files
Lyrebird/INSTALLATION_AND_USAGE.md
T
2026-06-01 20:38:04 -07:00

10 KiB

Lyrebird — Installation & Usage

How to add Lyrebird to a project and scaffold the five kinds of app it supports: real-time, real-time + UI, non-real-time (offline) render, AUv3 plugin, and iOS.

The package is hosted at https://realizedsound.mooo.com/josh/Lyrebird.


Requirements

Platform OS Xcode Swift
macOS 15+ 16+ 6.0
iOS 18+ 16+ 6.0

The macOS 15 / iOS 18 floor is hard: Lyrebird's lock-free queues use Synchronization.Atomic, which is unavailable earlier.


Adding the package

Swift Package Manager (Package.swift)

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "MyPiece",
    platforms: [.macOS(.v15), .iOS(.v18)],
    dependencies: [
        .package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
    ],
    targets: [
        .executableTarget(
            name: "MyPiece",
            dependencies: [
                .product(name: "Lyrebird",   package: "Lyrebird"),
                .product(name: "LyrebirdUI", package: "Lyrebird"),  // only if you need the GUI module
            ]),
    ]
)

The package vends three products:

Product Kind Use
Lyrebird library (static) Core framework — Generators, Synthesizers, engine, drivers.
LyrebirdUI library SwiftUI parameter controls (ParameterKnob, scope/envelope views, LyrebirdWindow).
LyrebirdCLI executable The lyrebird command-line tool (scaffolding, REPL).

In Xcode

File ▸ Add Package Dependencies…, paste the repository URL, choose Up to Next Major Version from 1.0.0, and add the Lyrebird (and optionally LyrebirdUI) products to your target.

Local checkout (development)

To build against a local clone instead of the remote, use a path dependency:

.package(name: "Lyrebird", path: "/Users/me/Documents/LyrebirdII")

The scaffolder (below) does this automatically with --lyrebird-path.

Linkage note

The consumer-facing Lyrebird product uses automatic linkage — SwiftPM/Xcode link it statically into your target. No dynamic framework is produced, so adding Lyrebird needs no special build settings: no disable-library-validation entitlement, no SWIFT_USE_INTEGRATED_DRIVER override. It just links.

Internally the package also vends a second product, LyrebirdDynamic (type: .dynamic), used only by the bundled LiveCompile/ live-coding sub-package — it needs a shared dylib so live-compiled snippets and the host resolve to one copy of every class. You never reference LyrebirdDynamic as an external consumer; ignore it.


The lyrebird CLI

Project scaffolding goes through the lyrebird CLI. Install it once onto your $PATH:

swift build -c release --product LyrebirdCLI
cp .build/release/LyrebirdCLI /usr/local/bin/lyrebird
lyrebird --version    # verify

(From a checkout you can also use swift run lyrebird … without installing.)

Command Purpose
lyrebird new <name> [--template <t>] [--lyrebird-path <p>] Scaffold a new project.
lyrebird run [--release] Build and run the project in the current directory.
lyrebird export <name> [--to <p>] [--overwrite] Emit a standalone SynthesizerBase template file.
lyrebird install-templates [--force] Install the Xcode file templates (New File… ▸ Lyrebird).
lyrebird uninstall-templates Remove them.
lyrebird repl Swift REPL with import LyrebirdSynth available.
lyrebird (no args) Interactive lyrebird> shell.

Full reference: docs/tooling/cli-guide.md.


Generating projects

lyrebird new <name> --template <template> is the single entry point. The templates fall into two groups: SPM-only (a Package.swift + an .xcworkspace that references it — open and run with swift/Xcode, no .xcodeproj) and Xcode-project (ship a real .xcodeproj, needed for .app/.appex bundles, code signing, and iOS).

Template Group What you get Driver
basic (default) SPM-only Minimal engine + RunLoop.main.run(). CoreAudioDriver
demo SPM-only A SineTone synth with @LiveParam frequency/amplitude. CoreAudioDriver
ui-demo SPM-only AppKit window with @UIParam knobs + LyrebirdWindow. CoreAudioDriver
nrt SPM-only Renders to output.caf, no hardware needed. NRTDriver
macos-ui-xcode Xcode-project macOS .app bundle (AppKit + SwiftUI), hardened runtime. CoreAudioDriver
ios-ui Xcode-project iOS .app (SwiftUI), with AVAudioSession activation. iOSAudioDriver (RemoteIO)
auv3 Xcode-project AUv3 host .app + aumu .appex subclassing LyrebirdAudioUnit. AUv3Driver

After scaffolding:

open <name>/<name>.xcworkspace     # SPM-only & Xcode-project templates both ship a workspace
# or, for the SPM-only ones:
cd <name> && lyrebird run

To develop against a local Lyrebird checkout instead of the remote URL (path dependency + an XCLocalSwiftPackageReference in the generated project):

lyrebird new <name> --template <t> --lyrebird-path /Users/me/Documents/LyrebirdII

1. Real-time

lyrebird new MyPiece --template demo
cd MyPiece && lyrebird run

main.swift boots a CoreAudioDriver, starts the engine, and adds a synth. The shape is:

import LyrebirdSynth

let engine = SynthesisEngine(
    blockSize:         512,
    sampleRate:        48_000,
    numOutputChannels: 2,
    numInputChannels:  0,
    driver:            CoreAudioDriver())

try engine.start()
try engine.add(SineTone())
RunLoop.main.run()        // keep the process alive while audio runs

2. Real-time with UI

# SPM-only AppKit window:
lyrebird new MyApp --template ui-demo
# or a full macOS .app bundle:
lyrebird new MyApp --template macos-ui-xcode

UI templates depend on LyrebirdUI and drive parameters with @UIParam (SwiftUI-bindable) instead of @LiveParam. A knob binds straight to the projected parameter:

import SwiftUI
import LyrebirdSynth
import LyrebirdUI

struct ContentView: View {
    @StateObject var synth = ToneSynth()       // ToneSynth: SynthesizerBase with @UIParam
    var body: some View {
        ParameterKnob(value: synth.$frequency, in: 50...2000, label: "Freq")
    }
}

3. Non-real-time (offline render)

lyrebird new MyRender --template nrt
cd MyRender && lyrebird run     # writes output.caf

Identical graph code as real-time — only the driver changes. NRTDriver runs processBlock in a tight loop (faster than real time) and writes a CAF file:

let driver = NRTDriver(outputURL: outputURL, duration: totalDuration)
let engine = SynthesisEngine(
    blockSize:         512,
    sampleRate:        48_000,
    numOutputChannels: 2,
    numInputChannels:  0,
    driver:            driver)

try engine.schedule(FMTone(carrierFreq: 440), after: 0.0)
try engine.schedule(FMTone(carrierFreq: 660), after: 2.5)   // sample-accurate
try engine.start()      // blocks until `duration` is rendered, then closes the file

For batch offline rendering across cores, see EngineHost.renderConcurrent(jobs:maxConcurrent:) in docs/tooling/nrt-guide.md.

4. AU plugin (AUv3)

lyrebird new MyPlugin --template auv3
open MyPlugin/MyPlugin.xcworkspace

This generates a host .app plus an aumu .appex extension. Run the host app once to register the extension with the system; it then loads in Logic, GarageBand, AUM, Loopy Pro, etc.

Your DSP is an ordinary SynthesizerBase; you expose it by subclassing LyrebirdAudioUnit and declaring parameter metadata:

import LyrebirdSynth

final class MyFMSynth: SynthesizerBase {
    @LiveParam var carrierFreq: Double = 440
    @LiveParam var modIndex:    Double = 0.5

    override func build() {
        let mod = OscSin.Audio(freq: $carrierFreq * 2, mul: $modIndex * $carrierFreq)
        let car = OscSin.Audio(freq: $carrierFreq + mod)
        output(bus: 0, source: car * 0.3)
    }
}

public final class MyFMSynthAudioUnit: LyrebirdAudioUnit {
    public override class func makeSynthesizer() -> SynthesizerBase { MyFMSynth() }
    public override class func parameterMetadata() -> [String: LyrebirdAUParameterInfo] {
        [
            "carrierFreq": .init(min: 20, max: 8000, unit: .hertz),
            "modIndex":    .init(min: 0,  max: 4),
        ]
    }
}

LyrebirdAudioUnit provides the parameter tree, bus topology, the host-driven internalRenderBlock (via the passive AUv3Driver + AUv3RingBuffer fixed-block→variable-frame adapter), fullState preset save/restore, MIDI dispatch, and an optional LyrebirdSynthView SwiftUI parameter grid. Full guide: Sources/Lyrebird/Lyrebird.docc/AUv3.md. The reference plugin is Demos/LyrebirdAUv3Demo.

5. iOS

lyrebird new MyApp --template ios-ui
open MyApp/MyApp.xcworkspace      # set your signing team, then run on device/simulator

The iOS template uses iOSAudioDriver (RemoteIO) and activates an AVAudioSession at launch; the synth/UI code is otherwise identical to the macOS UI template. The reference app is Demos/LyrebirdiOSDemo.


Xcode file templates

Beyond whole projects, the CLI installs New File… templates so you can add a Generator, Synthesizer, Task, Oscillator, Filter, Spectral Processor, AUv3 source-slot synth, test suite, and more without boilerplate:

lyrebird install-templates          # New File… ▸ Lyrebird section appears in Xcode
lyrebird uninstall-templates

From a repo checkout you can equivalently run bash scripts/install-xcode-templates.sh (--dry-run to preview). Catalog: docs/tooling/xcode-templates.md.


Reference projects

The repo ships six runnable demos in Demos/, opened via Lyrebird.xcworkspace, covering every template above — start there to see complete, working code:

Demo Mirrors template
LyrebirdDemo real-time CLI
LyrebirdMacOSDemo macos-ui-xcode
LyrebirdiOSDemo ios-ui
LyrebirdNRTDemo nrt
LyrebirdAUv3Demo auv3
LyrebirdScratchDemo live-coding scratchpad

See LYREBIRD_START_HERE.md for per-demo notes and gotchas.