Files
Lyrebird/docs/tooling/targets.md
T
2026-06-01 18:27:40 -07:00

133 lines
4.3 KiB
Markdown

# Package Targets
Lyrebird is structured as a multi-target Swift package. This document describes each target, its role, and when to use it.
---
## Core Targets
### `LyrebirdC`
Thin C shim. Exposes `fesetenv(FE_DFL_DISABLE_DENORMS_ENV)` to Swift — a C-only macro sentinel that Swift cannot reference directly. Linked into `Lyrebird` automatically; you never import this directly.
### `Lyrebird`
The core framework. Import this in any synthesis code.
```swift
import LyrebirdSynth
```
Provides: `SynthesisEngine`, `Generator`/`Synthesizer` protocols, all built-in generators, `LyrebirdBuffer`, `ParameterNode`, bus system, scheduling, and `CoreAudioDriver`. Links `CoreAudio`, `AudioToolbox`, and `Accelerate`.
Built as a `.dynamic` library — required by the Xcode 26 SPM regression (see `Package.swift` note). Reverts to `.static` when that regression is fixed.
### `LyrebirdUI`
Optional GUI module. Import alongside `Lyrebird` when you need parameter controls.
```swift
import LyrebirdUI
```
Provides: `LyrebirdWindow` (AppKit/SwiftUI host), `@SynthParam` property wrapper, and pre-built slider/knob views. Uses Swift 5 language mode to avoid actor-isolation diagnostics in SwiftUI/AppKit interop.
**Rule:** never import `LyrebirdUI` in `Lyrebird` — GUI code must stay in this module only.
---
## Executable Targets
### `LyrebirdCLI` — `lyrebird` command
Project scaffolding, running, and export from the command line.
```
lyrebird new MyProject # scaffold a new project
lyrebird run # compile and run
lyrebird export MySynth # generate a SynthesizerBase template
lyrebird repl # start Swift REPL with Lyrebird importable
```
Provides an interactive `lyrebird>` shell (via LineNoise) with history and tab completion. Uses Swift 5 language mode — LineNoise predates Swift 6 concurrency annotations.
See [cli-guide.md](cli-guide.md) for a full walkthrough.
### `LyrebirdDemo` — headless audio starting point
Command-line synthesis without a GUI. Best starting point for a new synthesis program.
```
swift run LyrebirdDemo
```
Demonstrates: `SynthesizerBase`, `@LiveParam`, `OscSin`, `DelayLine`, `engine.add`/`remove`, and RT-safe parameter updates from the main thread. Runs real-time audio via `CoreAudioDriver`, plays for a few seconds, then stops.
**Copy this target** when you want a headless synthesis starting point. Swap `CoreAudioDriver()` for `NRTDriver(outputURL:duration:)` to render offline to a file — see [nrt-guide.md](nrt-guide.md).
### `LyrebirdUIDemo` — GUI starting point
AppKit application with SwiftUI parameter controls. Best starting point for a windowed synthesis app.
```
swift run LyrebirdUIDemo
```
Demonstrates: `LyrebirdWindow`, `@SynthParam`-bound slider views, `AppDelegate` lifecycle (start/stop engine), and `NoteController` pattern for driving a `Synthesizer` from UI state.
**Copy this target** when you want a windowed synthesis app.
### `LyrebirdBenchmark`
Micro-benchmarks for DSP hot paths. Not a user starting point — run when profiling filter, vDSP, or block-processing performance.
```
swift run -c release LyrebirdBenchmark
```
Reports ns/block and ns/sample for scalar vs. vDSP biquad implementations at `blockSize = 512`. Always run with `-c release`; debug builds give meaningless numbers.
---
## Test Targets
| Target | What it covers |
|---|---|
| `LyrebirdTests` | Core engine: generators, bus system, scheduling, file I/O, all built-in DSP |
| `LyrebirdUITests` | `LyrebirdUI` module: parameter binding, `@SynthParam`, window lifecycle |
| `LyrebirdCLITests` | `LyrebirdCLI`: scaffolder, runner, exporter, REPL commands |
Run all tests:
```
swift test
```
---
## Dependency Map
```
LyrebirdC
└── Lyrebird (links CoreAudio, AudioToolbox, Accelerate)
├── LyrebirdUI (SwiftUI + AppKit, Swift 5 mode)
├── LyrebirdDemo
├── LyrebirdBenchmark
└── LyrebirdUIDemo (also links LyrebirdUI)
LyrebirdCLI (links LineNoise, Swift 5 mode)
```
---
## Choosing a Starting Point
| Goal | Use |
|---|---|
| Headless audio synthesis | `LyrebirdDemo` |
| Windowed app with GUI controls | `LyrebirdUIDemo` |
| CLI tooling / REPL | `lyrebird` (`LyrebirdCLI`) |
| Measure DSP performance | `LyrebirdBenchmark` (release build) |
| Framework import only | `import LyrebirdSynth` |
| GUI parameter controls | `import LyrebirdUI` |