560724d116
- Fixed: SynthesizerBase subclasses' release/free now dispatch correctly (gated synths were hard-freed instead of released). - New: quickstart project template + LyrebirdQuickstartDemo. - Docs: every example typechecked or provably illustrative (426->542); ~20 wrong-API examples fixed; root docs brought under the compile guard. - Fixed: NRT/Score demo Package.swift build from terminal again. See RELEASES.md for details.
370 lines
10 KiB
Markdown
370 lines
10 KiB
Markdown
# Lyrebird CLI Guide
|
|
|
|
`lyrebird` is the command-line tool for creating, running, and exporting Lyrebird synthesis projects. This guide walks through a complete workflow from first install to a running audio patch.
|
|
|
|
---
|
|
|
|
## Installation
|
|
|
|
The `lyrebird` binary is built from the Lyrebird package itself. From the root of the Lyrebird repository:
|
|
|
|
```sh
|
|
swift build -c release --product LyrebirdCLI
|
|
```
|
|
|
|
Then copy the binary somewhere on your `PATH`, renaming to `lyrebird`:
|
|
|
|
```sh
|
|
cp .build/release/LyrebirdCLI /usr/local/bin/lyrebird
|
|
```
|
|
|
|
Verify:
|
|
|
|
```sh
|
|
lyrebird version
|
|
# lyrebird 0.1.0
|
|
```
|
|
|
|
**Requirement:** macOS 15+, Xcode or a Swift toolchain with `swift` on your `PATH`.
|
|
|
|
---
|
|
|
|
## Quick Start
|
|
|
|
Three commands to go from nothing to audio:
|
|
|
|
```sh
|
|
lyrebird new MyPiece # 1. scaffold a project
|
|
cd MyPiece
|
|
# edit Sources/MyPiece/main.swift
|
|
lyrebird run # 2. build and run
|
|
```
|
|
|
|
That's the complete loop. The rest of this guide explains each step in depth.
|
|
|
|
---
|
|
|
|
## Commands
|
|
|
|
### `lyrebird new <name>`
|
|
|
|
Scaffolds a new Lyrebird Swift Package in a subdirectory named `<name>`.
|
|
|
|
```sh
|
|
lyrebird new MyPiece
|
|
# Created MyPiece/
|
|
```
|
|
|
|
Generated layout:
|
|
|
|
```
|
|
MyPiece/
|
|
├── Package.swift
|
|
├── MyPiece.xcworkspace/
|
|
│ └── contents.xcworkspacedata ← open in Xcode (references Package.swift)
|
|
├── Sources/
|
|
│ └── MyPiece/
|
|
│ └── main.swift ← engine setup + entry point
|
|
└── Tests/
|
|
└── MyPieceTests/
|
|
└── MyPieceTests.swift
|
|
```
|
|
|
|
Open `MyPiece.xcworkspace` in Xcode for SwiftUI previews and debugging; or stay on the terminal with `lyrebird run`.
|
|
|
|
`main.swift` is pre-wired: engine is created, `engine.start()` is called, and `RunLoop.main.run()` keeps the process alive until Ctrl+C. Add your `Synthesizer` subclasses to the same `Sources/MyPiece/` directory — they share the module namespace so no imports are needed between files.
|
|
|
|
**Name rules:** valid Swift module identifiers only — ASCII letters, digits, underscores; no leading digit; no spaces or hyphens.
|
|
|
|
```sh
|
|
lyrebird new DrumMachine # OK
|
|
lyrebird new "my piece" # error: not a valid Swift module name
|
|
lyrebird new 1stPiece # error: not a valid Swift module name
|
|
```
|
|
|
|
**Templates** — `--template <name>`:
|
|
|
|
- SPM-only (open `Package.swift` in Xcode): `quickstart` (fastest sound), `basic` (default), `demo`, `ui-demo`, `nrt`, `score`
|
|
- Xcode-project (ships `.xcodeproj` + `.xcworkspace`, builds to `.app` or `.appex`): `macos-ui-xcode`, `ios-ui`, `auv3`
|
|
|
|
```sh
|
|
lyrebird new MyApp --template macos-ui-xcode # macOS .app
|
|
lyrebird new MyApp --template ios-ui # iOS .app
|
|
lyrebird new MyPlugin --template auv3 # AUv3 host + .appex
|
|
```
|
|
|
|
**Local Lyrebird checkout** — `--lyrebird-path <abs-path>` makes the generated project depend on a local Lyrebird checkout (via `.package(name: "Lyrebird", path: ...)` in `Package.swift`, `XCLocalSwiftPackageReference` in `<name>.xcodeproj`). Use while the published repo URL isn't yet accessible:
|
|
|
|
```sh
|
|
lyrebird new MyApp --template macos-ui-xcode \
|
|
--lyrebird-path /Users/me/Documents/LyrebirdII
|
|
```
|
|
|
|
See `docs/tooling/project-system.md` for the layout each template emits. Guitar-pedalboard app scaffolding lives in the standalone ShoeGaze repo, which depends on Lyrebird.
|
|
|
|
If the directory already exists, the command fails cleanly and leaves the filesystem unchanged.
|
|
|
|
---
|
|
|
|
### `lyrebird run [--release]`
|
|
|
|
Builds and runs the current project. Must be called from the project's root directory (where `Package.swift` lives).
|
|
|
|
```sh
|
|
lyrebird run # debug build — fast compile, slower audio
|
|
lyrebird run --release # release build — full optimisation, use for performance
|
|
```
|
|
|
|
Under the hood this is `swift run` / `swift run -c release`. Exit code from `swift run` passes through, so CI can detect failures normally.
|
|
|
|
**Use `--release` for real audio work.** Debug builds run without optimisations; vDSP and tight DSP loops can be noticeably slower, and the RT thread may miss its deadline under heavy load.
|
|
|
|
```sh
|
|
cd MyPiece
|
|
lyrebird run --release
|
|
# Build complete!
|
|
# MyPiece running — press Ctrl+C to stop
|
|
```
|
|
|
|
---
|
|
|
|
### `lyrebird export <name> [--to <path>] [--overwrite]`
|
|
|
|
Generates a `SynthesizerBase` subclass template and writes it to a `.swift` file. Use this to stub out a new synth inside an existing project.
|
|
|
|
```sh
|
|
# Write BassDrum.swift to the current directory
|
|
lyrebird export BassDrum
|
|
|
|
# Write to a specific path
|
|
lyrebird export BassDrum --to Sources/MyPiece/BassDrum.swift
|
|
|
|
# Replace an existing file
|
|
lyrebird export BassDrum --to Sources/MyPiece/BassDrum.swift --overwrite
|
|
```
|
|
|
|
Generated file (`BassDrum.swift`):
|
|
|
|
```swift
|
|
import LyrebirdSynth
|
|
|
|
// MARK: - BassDrum
|
|
|
|
/// A Lyrebird synthesizer — generated by `lyrebird export BassDrum` (your subclass).
|
|
final class BassDrum: SynthesizerBase {
|
|
|
|
// MARK: - Parameters
|
|
|
|
// Declare parameters here. Example:
|
|
// let freq: Double = 440.0
|
|
|
|
// MARK: - Build
|
|
|
|
override func build() {
|
|
// Wire your signal graph here. Example:
|
|
// let osc = OscSin.Audio(freq: freq)
|
|
// addOutputGenerator(osc * env)
|
|
}
|
|
}
|
|
```
|
|
|
|
Without `--overwrite`, the command fails if the destination already exists — safe to run repeatedly without clobbering work in progress.
|
|
|
|
---
|
|
|
|
### `lyrebird install-templates [--force]`
|
|
|
|
Installs Lyrebird's Xcode file templates (Generator, Synthesizer, Task, …) into
|
|
`~/Library/Developer/Xcode/Templates/File Templates/Lyrebird/`. After install,
|
|
Xcode's New File dialog (`⌘N`) shows a "Lyrebird" section listing every shipped
|
|
template.
|
|
|
|
```sh
|
|
lyrebird install-templates
|
|
# Installed 12 Lyrebird Xcode templates →
|
|
# /Users/you/Library/Developer/Xcode/Templates/File Templates/Lyrebird
|
|
```
|
|
|
|
Templates are bundled with the `lyrebird` binary as SPM resources — no repo
|
|
checkout needed once `lyrebird` is on your `PATH`.
|
|
|
|
Fails with `--force`-prompt error if the destination already exists. Pass
|
|
`--force` to replace it. See [xcode-templates.md](xcode-templates.md) for the
|
|
full template catalog and per-template usage notes.
|
|
|
|
### `lyrebird uninstall-templates`
|
|
|
|
Removes the entire `~/Library/Developer/Xcode/Templates/File Templates/Lyrebird/`
|
|
directory. Will not touch any other Xcode template you have installed.
|
|
|
|
```sh
|
|
lyrebird uninstall-templates
|
|
# Removed Lyrebird templates from
|
|
# /Users/you/Library/Developer/Xcode/Templates/File Templates/Lyrebird
|
|
```
|
|
|
|
---
|
|
|
|
### `lyrebird repl`
|
|
|
|
Runs `swift build` in the current directory, then launches `swift repl` with `-I` /
|
|
`-L` / `-l` flags pointing at the package's `.build/debug` artifacts so `import LyrebirdSynth`
|
|
works immediately. (`swift package repl` was removed from the toolchain; this is the
|
|
canonical replacement — see [repl.md](repl.md) for the raw command.)
|
|
|
|
```sh
|
|
cd MyPiece
|
|
lyrebird repl
|
|
# Lyrebird 0.1.0 — starting Swift REPL
|
|
# Run `import LyrebirdSynth` to access the framework.
|
|
```
|
|
|
|
Inside the REPL:
|
|
|
|
```swift
|
|
import LyrebirdSynth
|
|
|
|
let engine = SynthesisEngine(
|
|
blockSize: 512, sampleRate: 44100,
|
|
numOutputChannels: 2, numInputChannels: 0,
|
|
driver: CoreAudioDriver()
|
|
)
|
|
try engine.start()
|
|
|
|
// Example — your synthesizer, defined by subclassing SynthesizerBase
|
|
final class SineTone: SynthesizerBase {
|
|
@LiveParam var freq: Double = 440.0
|
|
|
|
override func build() {
|
|
let osc = OscSin.Audio(freq: $freq)
|
|
output(bus: 0, source: Pan2(input: osc * 0.2))
|
|
}
|
|
}
|
|
|
|
let tone = SineTone()
|
|
try engine.add(tone)
|
|
|
|
// While audio plays — parameter writes need no try (atomic store), RT-safe
|
|
tone.freq = 880.0
|
|
engine.remove(tone)
|
|
engine.stop()
|
|
```
|
|
|
|
`@LiveParam` assignments are atomic stores — safe to do from the REPL main thread while the audio thread runs. `engine.add` / `engine.remove` are lock-free and take effect at the next block boundary.
|
|
|
|
Exit the REPL with Ctrl+D.
|
|
|
|
See [repl.md](repl.md) for full REPL reference.
|
|
|
|
---
|
|
|
|
### `lyrebird help`
|
|
|
|
Prints the command summary.
|
|
|
|
```sh
|
|
lyrebird help
|
|
lyrebird --help
|
|
lyrebird -h
|
|
```
|
|
|
|
---
|
|
|
|
### `lyrebird version`
|
|
|
|
Prints the version string.
|
|
|
|
```sh
|
|
lyrebird version
|
|
lyrebird --version
|
|
# lyrebird 0.1.0
|
|
```
|
|
|
|
---
|
|
|
|
## Interactive Shell
|
|
|
|
Running `lyrebird` with no arguments enters the `lyrebird>` shell — a LineNoise-powered command loop with history and tab completion.
|
|
|
|
```sh
|
|
lyrebird
|
|
# Lyrebird 0.1.0 — Swift audio synthesis
|
|
# Type 'help' for available commands, or 'repl' to start a Swift REPL session.
|
|
#
|
|
# lyrebird>
|
|
```
|
|
|
|
All the same commands work inside the shell:
|
|
|
|
```
|
|
lyrebird> new FMSynth
|
|
Created FMSynth/
|
|
|
|
lyrebird> export Drone --to Sources/FMSynth/Drone.swift
|
|
Exported /Users/josh/FMSynth/Sources/FMSynth/Drone.swift
|
|
|
|
lyrebird> run --release
|
|
Build complete!
|
|
...
|
|
|
|
lyrebird> quit
|
|
```
|
|
|
|
**Shell features:**
|
|
|
|
| Feature | Details |
|
|
|---|---|
|
|
| Line editing | Arrow keys, Home/End, Ctrl+A/E (linenoise) |
|
|
| Tab completion | Prefix-match on all subcommand names |
|
|
| History | Up/down arrows; persisted to `~/.lyrebird_history` on exit |
|
|
| Case-insensitive verbs | `NEW`, `Run`, `EXPORT` all work |
|
|
| Preserved casing on names | `export MySynth` → file named `MySynth.swift`, not `mysynth.swift` |
|
|
| Exit | `quit`, `exit`, `:quit`, or Ctrl+D |
|
|
|
|
---
|
|
|
|
## A Complete Workflow
|
|
|
|
```sh
|
|
# 1. Scaffold
|
|
lyrebird new PadSynth
|
|
cd PadSynth
|
|
|
|
# 2. Stub out a synth
|
|
lyrebird export Pad --to Sources/PadSynth/Pad.swift
|
|
|
|
# 3. Edit Pad.swift — fill in build()
|
|
# (your editor here)
|
|
|
|
# 4. Add to main.swift:
|
|
# try engine.add(Pad())
|
|
|
|
# 5. Test with a debug build first
|
|
lyrebird run
|
|
|
|
# 6. Once stable, run optimised
|
|
lyrebird run --release
|
|
```
|
|
|
|
---
|
|
|
|
## Error Reference
|
|
|
|
| Error message | Cause | Fix |
|
|
|---|---|---|
|
|
| `error: directory 'X' already exists.` | `new` target dir present | Remove it or choose a different name |
|
|
| `error: 'X' is not a valid Swift module name.` | Name fails identifier rules | Use ASCII letters/digits/underscores only |
|
|
| `error: 'X' already exists. Pass --overwrite to replace it.` | `export` destination exists | Add `--overwrite` flag |
|
|
| `error: swift not found.` | No Swift toolchain on PATH | Install Xcode or a Swift toolchain |
|
|
| `Build failed (exit code N).` | `swift run` failed | Check compiler output above the error |
|
|
|
|
---
|
|
|
|
## Reference Docs
|
|
|
|
| Doc | Contents |
|
|
|---|---|
|
|
| [project-system.md](project-system.md) | Generated file contents, scaffolder/runner/exporter internals |
|
|
| [repl.md](repl.md) | Full REPL reference, threading model, live coding patterns |
|
|
| [targets.md](targets.md) | All package targets and when to use each |
|