v1.4.1 release: Learning Swift for Lyrebird intro guide

Documentation-only release. Adds docs/learning-swift/ — a four-part
introduction to Swift for Lyrebird users coming from SuperCollider,
Max/MSP, Csound, etc. (Hello World, Swift basics & best practices,
types & functional programming, Xcode/packages/debugging). Linked from
README.md and LYREBIRD_START_HERE.md. See RELEASES.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 12:04:33 -07:00
parent 38d2107f64
commit c665c99b5a
8 changed files with 1071 additions and 0 deletions
+1
View File
@@ -202,6 +202,7 @@ final class MySynth: SynthesizerBase {
| Topic | Doc |
|-------|-----|
| New to Swift? Intro for Lyrebird users | `docs/learning-swift/README.md` |
| Engine setup and Core Audio | `docs/engine/synthesis-engine.md` |
| Bus system, In/Out generators | `docs/engine/bus-system.md` |
| Sample-accurate scheduling | `docs/engine/scheduling.md` |
+3
View File
@@ -122,6 +122,8 @@ The REPL is text-only and works from any project that depends on Lyrebird; the s
**Read [`LYREBIRD_START_HERE.md`](LYREBIRD_START_HERE.md)** — it covers the eight demo projects, how to open the workspace, where to add synthesizers, and the gotchas that will bite you.
**New to Swift itself?** [`docs/learning-swift/`](docs/learning-swift/README.md) is a four-part intro to Swift written for Lyrebird users (not iOS developers): a Hello-World tone, Swift basics and best practices, the type system and functional style applied to synthesis graphs, and Xcode / packages / Debug-vs-Release / debugging.
---
## Requirements
@@ -337,6 +339,7 @@ swift package --disable-sandbox preview-documentation --target Lyrebird
| Topic | Doc |
|---|---|
| **Start here / demo projects** | [`LYREBIRD_START_HERE.md`](LYREBIRD_START_HERE.md) |
| **New to Swift? Intro for Lyrebird users** | [`docs/learning-swift/README.md`](docs/learning-swift/README.md) |
| **What's new / release notes** | [`RELEASES.md`](RELEASES.md) |
| Engine setup and Core Audio | `docs/engine/synthesis-engine.md` |
| Bus memory / In / Out | `docs/engine/bus-system.md` |
+35
View File
@@ -7,6 +7,41 @@ functionality in a backward-compatible way.
---
## 1.4.1 — "Learning Swift for Lyrebird" intro guide
A documentation-only release, continuing the doc improvements begun in 1.3. No
source or public-API changes. Adds a four-part introduction to Swift written
specifically for Lyrebird users coming from SuperCollider, Max/MSP, Csound, and
similar tools — people who want just enough Swift to be productive without
wading through iOS-development tutorials.
### New — `docs/learning-swift/`
Four short guides, meant to be read in order, each grounded in audio examples
rather than app-building:
1. **Hello, World** — from a one-line `print` to a working 440 Hz tone, every
line of a Lyrebird program explained (engine → synthesizer → generator graph
→ output bus).
2. **Swift Basics & Best Practices** — `let`/`var`, the scalar types, optionals
(and why Lyrebird forbids force-unwrap `!`), control flow, functions, error
handling, and `struct` vs `class`.
3. **Types & Functional Programming** — enums, protocols, operator overloading,
closures, and `map`/`filter`/`reduce` applied to building synthesis graphs;
`expand` as `map` for multichannel generators.
4. **Xcode, Packages & Debugging** — Xcode vs. SwiftPM, adding Lyrebird as a
package, **Debug vs. Release** build configurations (and why Debug audio can
glitch), and breakpoints — including the rule to never break or `print` on
the real-time render thread, using `debugTap`/`debugTag` instead.
Throughout, examples use explicit **type annotations** on every binding — the
same practice the Lyrebird codebase enforces — for readability and faster
compilation on large, generic audio-graph expressions.
Linked from `README.md` and `LYREBIRD_START_HERE.md` for discovery.
---
## 1.4.0 — Live-coding scratch editor, interpreted Graph DSL, `ClosureSynthesizer` + `SampleLoop`
A minor release. Fully backward-compatible — no changes to existing public API.
+188
View File
@@ -0,0 +1,188 @@
# 1 · Hello, World
The programmer's tradition is a program that prints `Hello, World`. Lyrebird's tradition is a program that makes a **tone**. We'll do both — the print first (to prove your toolchain works), then the sound.
By the end of this page you will have written, built, and run a Swift program that plays a 440 Hz sine wave, and you'll understand every line.
---
## Part 0 — Prove Swift works
Open **Terminal** (Applications → Utilities → Terminal). Check you have a Swift toolchain:
```sh
swift --version
```
You should see something like `Apple Swift version 6.0`. If you get "command not found", install Xcode from the Mac App Store, launch it once, and let it install command-line tools. (Guide 4 covers Xcode in depth.)
Now the classic:
```sh
echo 'print("Hello, World")' > hello.swift
swift hello.swift
```
Swift can run a single file like a script. If you see `Hello, World`, your toolchain is alive. That's the smallest possible Swift program:
```swift
print("Hello, World")
```
- `print(...)` is a function that writes text to the console.
- `"Hello, World"` is a **String** — text in double quotes.
- No `main`, no boilerplate, no semicolons required. Swift keeps simple things simple.
---
## Part 1 — The shape of a Lyrebird program
A Lyrebird program is a normal Swift program that uses the Lyrebird library. Here is the entire "hello tone", which you'll build up in Part 2:
```swift
import Foundation
import LyrebirdSynth
// The engine owns Core Audio and runs the audio graph.
let engine: SynthesisEngine = SynthesisEngine(
blockSize: 512,
sampleRate: 48000,
numOutputChannels: 2,
numInputChannels: 0,
driver: CoreAudioDriver()
)
// A synthesizer describes the sound.
final class SineTone: SynthesizerBase {
override func build() {
let sine: OscSin.Audio = OscSin.Audio(freq: 440.0, mul: 0.2)
let panned: Pan2 = Pan2(input: sine, pan: 0.0)
output(bus: 0, source: panned)
}
}
do {
try engine.start() // open the audio device
try engine.add(SineTone()) // start sounding
print("Playing 440 Hz for 3 seconds…")
Thread.sleep(forTimeInterval: 3.0)
engine.stop() // close the device
print("Done.")
} catch {
print("Something went wrong: \(error)")
}
```
Run that and you hear a sine tone for three seconds. Now let's read it.
---
## Part 2 — Reading it line by line
### The imports
```swift
import Foundation
import LyrebirdSynth
```
`import` pulls in a module — a bundle of code someone else wrote. `Foundation` is Apple's standard utility library (it's where `Thread.sleep` lives). `LyrebirdSynth` is Lyrebird itself.
> **The naming quirk:** the Swift Package product is named `Lyrebird`, but the *module* you import is `LyrebirdSynth`. When you set up a project (guide 4) you'll add a dependency on `Lyrebird` — then write `import LyrebirdSynth`. Right for both, even though they don't match.
### Creating the engine
```swift
let engine: SynthesisEngine = SynthesisEngine(
blockSize: 512,
sampleRate: 48000,
numOutputChannels: 2,
numInputChannels: 0,
driver: CoreAudioDriver()
)
```
- `let engine: SynthesisEngine = ...` declares a **constant** named `engine`, and the `: SynthesisEngine` is a **type annotation** — it states the type explicitly. `let` means "this name won't be reassigned." (Swift also has `var` for values that change — guide 2.)
- **Every example in this series annotates the type**, even though Swift can infer it. It documents the code for the reader and, in a large project, makes Swift and Xcode compile faster — the compiler doesn't have to work out each type. Guide 2 explains this properly; for now, read `name: Type = value` as "a constant of this type." (Swift also has `var` for values that change — guide 2.)
- `SynthesisEngine(...)` **constructs** an engine. The words before each colon (`blockSize:`, `sampleRate:`, …) are **argument labels** — Swift names its arguments, which makes call sites read like sentences. You can't reorder or omit them.
- `blockSize: 512` — the engine processes audio 512 samples at a time. (Lyrebird caps this at 512.)
- `sampleRate: 48000` — 48,000 samples per second.
- `numOutputChannels: 2` — stereo out. `numInputChannels: 0` — no microphone input.
- `driver: CoreAudioDriver()` — talk to the Mac's audio hardware. (iOS uses a different driver; guide 4.)
### Describing the sound
```swift
final class SineTone: SynthesizerBase {
override func build() {
let sine: OscSin.Audio = OscSin.Audio(freq: 440.0, mul: 0.2)
let panned: Pan2 = Pan2(input: sine, pan: 0.0)
output(bus: 0, source: panned)
}
}
```
- `final class SineTone: SynthesizerBase` defines a new type called `SineTone` that **inherits from** `SynthesizerBase`. The colon means "is a." Everything a synthesizer needs is in `SynthesizerBase`; you fill in the blanks. `final` means "no one will subclass this further" (good default; guide 2).
- `override func build()` — `SynthesizerBase` has an empty `build()` method; you **override** it to supply your graph. Lyrebird calls `build()` for you when the synth is added.
- `OscSin.Audio(freq: 440.0, mul: 0.2)` — an audio-rate sine oscillator at 440 Hz, with output multiplied by 0.2 so it isn't harsh. A raw sine at full scale is loud; `mul: 0.2` scales amplitude to 20%.
- `Pan2(input: sine, pan: 0.0)` — takes a mono signal and places it in the stereo field. `pan: 0.0` is dead center; `-1` is hard left, `+1` hard right.
- `output(bus: 0, source: panned)` — send the panned signal to output bus 0. `Pan2` produces two channels, so this fills both left and right. `output(...)` is a helper `SynthesizerBase` gives you.
Notice the **data flow**: `sine` feeds `panned` feeds `output`. Each generator is a node; wiring them by passing one as another's `input:` builds a graph. That's the core idea of Lyrebird.
### Running it
```swift
do {
try engine.start()
try engine.add(SineTone())
print("Playing 440 Hz for 3 seconds…")
Thread.sleep(forTimeInterval: 3.0)
engine.stop()
print("Done.")
} catch {
print("Something went wrong: \(error)")
}
```
- `do { … } catch { … }` is Swift's **error handling**. Some operations can fail; those are marked `try`. If a `try` fails, control jumps to `catch`, where `error` describes what happened. (Guide 2 covers this properly.)
- `try engine.start()` opens the audio device. It can fail (device busy, no output) — hence `try`.
- `try engine.add(SineTone())` constructs a fresh `SineTone` and hands it to the engine. It starts sounding immediately. `add` can also fail (hence `try`), for example if you add the same instance twice.
- `Thread.sleep(forTimeInterval: 3.0)` pauses the program for 3 seconds. Without this, the program would reach the end and exit instantly — you'd hear nothing. Audio runs on its own thread; the main program just needs to stay alive.
- `engine.stop()` closes the device cleanly. (Not `try` — stopping doesn't fail.)
- `\(error)` inside a string is **string interpolation**: it drops the value of `error` into the text.
---
## Part 3 — Make it yours
Change one thing at a time and re-run. This is the fastest way to build intuition:
- **Pitch:** `freq: 440.0` → `freq: 220.0` (an octave down) or `freq: 660.0` (a fifth up).
- **Loudness:** `mul: 0.2` → `mul: 0.4`. Careful with headphones.
- **Position:** `pan: 0.0` → `pan: -1.0` (hard left).
- **Duration:** `forTimeInterval: 3.0` → `10.0`.
- **A different wave:** `OscSin.Audio` → `OscSawtooth.Audio` (bright, buzzy) or `OscSquare.Audio` (hollow). Same `freq:`/`mul:` arguments.
Try two oscillators at once for a chord — a taste of what guide 3 makes systematic:
```swift
override func build() {
let a: OscSin.Audio = OscSin.Audio(freq: 440.0, mul: 0.15) // A4
let e: OscSin.Audio = OscSin.Audio(freq: 660.0, mul: 0.15) // E5
let mix: BinaryOpGenerator = a + e // generators add with +
output(bus: 0, source: Pan2(input: mix, pan: 0.0))
}
```
`a + e` sums two signals — Lyrebird overloads `+` so audio math reads like arithmetic. More of that in guide 3.
---
## What you learned
- A Swift program can be as small as one `print`, or a full Lyrebird patch — same language, same rules.
- `import`, `let` with a **type annotation** (`let x: Type = …`), argument labels, `class`/`override`, and `do`/`try`/`catch` — you've now seen Swift's most common building blocks in context.
- Lyrebird's shape: **engine → synthesizer → generator graph → output bus**.
Next: [Swift Basics & Best Practices](02-swift-basics.md) — the same building blocks, slowed down and explained properly, so you can write your own from scratch.
+276
View File
@@ -0,0 +1,276 @@
# 2 · Swift Basics & Best Practices
Guide 1 showed a working program. This one slows down and teaches the pieces so you can write your own. Every concept is paired with a Lyrebird use so nothing feels abstract.
Keep a terminal open. You can test tiny snippets by putting them in a file and running `swift file.swift`, or in Xcode's REPL (`swift` with no arguments gives you an interactive prompt).
---
## Values, constants, and variables
```swift
let sampleRate: Int = 48000 // a constant — cannot be reassigned
var gain: Double = 0.5 // a variable — can change
gain = 0.7 // fine
// sampleRate = 44100 // ERROR: cannot assign to a 'let'
```
- **`let` is your default.** Reach for `var` only when a value genuinely changes. Constants are easier to reason about and the compiler catches accidental mutation. This isn't just style — Lyrebird's whole design leans on immutable, copy-per-instance graphs, and `let` reinforces that habit.
- **Write the type after the name** — the `: Int` / `: Double` above. That's a **type annotation**, and this series recommends it on *every* binding. Read the next section for why.
### Annotate your types — a best practice, not just a Lyrebird rule
Swift *can* infer a binding's type: `let sampleRate = 48000` compiles fine and `sampleRate` is an `Int`. But writing the type explicitly — `let sampleRate: Int = 48000` — is worth the few extra characters, for two concrete reasons:
1. **Clarity.** Swift is strongly typed; every value has exactly one type, and stating it means a reader (including future-you) never has to trace an expression to learn what they're holding. `let voices: [OscSin.Audio] = …` tells you at a glance.
2. **Compile speed.** When you leave the type off, the compiler must *infer* it — and Swift's type inference is expensive, especially for the long, generic, operator-heavy expressions you build with audio graphs (`osc1 * env + osc2 * 0.3`, chains of `map`/`reduce`). Annotating the binding short-circuits that work. On a single file you won't notice; **across a large project it adds up to real build-time savings**, and Xcode's editor feels snappier too.
So: **annotate every `let` and `var`.** Every example in this series does. The Lyrebird codebase *requires* it for exactly these reasons — you'll see it in all the source — and it's a good habit in any Swift project of size.
> The rule has a few grammar exceptions where Swift simply won't accept an annotation — closure parameters (`{ x in … }`), tuple destructures (`let (a, b) = pair`), and pattern bindings (`case let .hz(f)`). Guide 3 points them out as they come up. Everywhere else: annotate.
---
## The basic scalar types
| Type | What it is | Example | Lyrebird use |
|------|-----------|---------|--------------|
| `Int` | whole number | `512` | block size, channel counts, bus numbers |
| `Double` | 64-bit decimal | `440.0` | frequency, gain, pan, time in seconds |
| `Bool` | true / false | `true` | flags, toggles |
| `String` | text | `"hello"` | messages, file paths |
**Audio is almost always `Double` in Lyrebird.** Frequencies, amplitudes, pan positions, seconds — all `Double`. When you write `440.0` (with the decimal point) you get a `Double`; `440` alone is an `Int`. Mixing them is an error Swift makes you resolve explicitly:
```swift
let freq: Double = 440.0
let ratio: Int = 2 // Int
// let up = freq * ratio // ERROR: Double * Int
let up: Double = freq * Double(ratio) // convert first — OK, = 880.0
```
That strictness feels fussy at first and saves you from whole categories of bugs. Convert deliberately with `Double(...)`, `Int(...)`, etc.
---
## Strings and interpolation
```swift
let note: String = "A4"
let hz: Double = 440.0
print("Note \(note) is \(hz) Hz") // Note A4 is 440.0 Hz
```
`\(...)` drops any value into a string. Great for `print` debugging. (One caution you'll meet later: building strings is forbidden on the real-time audio thread — but in your setup/control code it's free.)
---
## Collections
### Arrays — ordered lists
```swift
let frequencies: [Double] = [440.0, 550.0, 660.0] // a major chord
print(frequencies[0]) // 440.0 (indexing starts at 0)
print(frequencies.count) // 3
```
### Dictionaries — key/value lookups
```swift
let noteToHz: [String: Double] = ["A4": 440.0, "C5": 523.25]
print(noteToHz["A4"]) // Optional(440.0) — note the "Optional"!
```
That `Optional` wrapper is important, and it's next.
---
## Optionals — Swift's "maybe there's a value"
A dictionary lookup might find nothing (`noteToHz["Z9"]`). Rather than crash or return a bogus value, Swift returns an **Optional**: a box that either holds a value or is `nil` (empty). An optional type is written with a trailing `?`:
```swift
let maybeHz: Double? = noteToHz["A4"] // Double? — might be nil
```
You **unwrap** an optional before using it. The safe, idiomatic way is `if let` / `guard let`:
```swift
if let hz: Double = noteToHz["A4"] {
print("Found \(hz)") // hz is a plain Double in here
} else {
print("No such note")
}
```
The annotation on an `if let` / `guard let` names the **unwrapped** type — `hz` is a plain `Double` inside the block, not a `Double?`.
Or supply a fallback with `??`:
```swift
let hz: Double = noteToHz["Z9"] ?? 440.0 // use 440 if the lookup was nil
```
> **The one rule you'll hear repeated:** avoid the force-unwrap operator `!` (as in `noteToHz["A4"]!`). It says "I promise this isn't nil" — and if you're wrong, the program crashes. Lyrebird's coding rules **forbid `!`** entirely, especially on the audio thread where a crash means a dropout or worse. Use `if let`, `guard let`, or `??`. Build the habit now.
`guard let` is the early-exit form, common at the top of functions:
```swift
func describe(_ note: String) {
guard let hz: Double = noteToHz[note] else {
print("Unknown note")
return // guard MUST leave the scope on failure
}
print("\(note) = \(hz) Hz") // hz is available for the rest of the function
}
```
---
## Control flow
```swift
// if / else
if gain > 1.0 {
print("clipping risk")
} else {
print("safe")
}
// for-in over a range (the loop variable takes an annotation too)
for i: Int in 0..<4 { // 0, 1, 2, 3 (..< excludes the end)
print(i)
}
for i: Int in 1...4 { // 1, 2, 3, 4 (... includes the end)
print(i)
}
// for-in over a collection
for freq: Double in frequencies {
print(freq)
}
// while
var x: Double = 1.0
while x < 8.0 { x *= 2.0 } // 1, 2, 4 → x ends at 8
// switch — must be exhaustive
let wave: String = "saw"
switch wave {
case "sine": print("smooth")
case "saw": print("bright")
default: print("something else")
}
```
Swift's `switch` is powerful and must cover every case (add `default` for the rest). No fall-through by accident.
---
## Functions
```swift
func midiToHz(_ note: Int) -> Double {
return 440.0 * pow(2.0, Double(note - 69) / 12.0)
}
let hz: Double = midiToHz(69) // 440.0 (MIDI 69 = A4)
```
- `func name(params) -> ReturnType { … }`.
- `_ note: Int` — the `_` means "no argument label at the call site," so you write `midiToHz(69)` not `midiToHz(note: 69)`. Without the `_`, the label is required.
- `-> Double` is the return type. A function returning nothing omits the arrow.
**Argument labels make calls read like prose** — you saw this with `OscSin.Audio(freq: 440.0, mul: 0.2)`. Use them; they're a Swift strength.
Default values reduce noise at call sites:
```swift
func tone(freq: Double, mul: Double = 0.2) -> OscSin.Audio {
return OscSin.Audio(freq: freq, mul: mul)
}
let a: OscSin.Audio = tone(freq: 440.0) // mul defaults to 0.2
let b: OscSin.Audio = tone(freq: 440.0, mul: 0.5) // override it
```
Lyrebird generators lean on defaults heavily — most take `mul:` and `add:` with sensible defaults so you only specify what matters.
---
## Error handling
Some functions can fail. They're marked `throws`, and you must call them with `try` inside a `do/catch`:
```swift
do {
try engine.start()
try engine.add(SineTone())
} catch {
print("Engine problem: \(error)")
}
```
You saw this in guide 1. The rule: **if the compiler demands `try`, the call can fail** — decide what to do in `catch`. In small programs, printing the error and exiting is fine:
```swift
do {
try engine.start()
} catch {
print("Failed to start: \(error)")
exit(1)
}
```
---
## Structs vs classes — and why Lyrebird uses classes
Swift has two ways to make your own types:
- **`struct`** — a **value type**. Copied when assigned or passed. Two variables never share the same struct.
- **`class`** — a **reference type**. Assigning passes a reference; two variables can point at the *same* object. Classes support inheritance (`: SomeBaseClass`).
```swift
struct Point { var x: Double; var y: Double }
var p1: Point = Point(x: 0.0, y: 0.0)
var p2: Point = p1 // a COPY
p2.x = 5.0 // p1.x is still 0
final class Counter { var n: Int = 0 }
let c1: Counter = Counter()
let c2: Counter = c1 // SAME object
c2.n = 5 // c1.n is now 5 too
```
Rule of thumb: **prefer `struct`** for plain data (a note, a frequency pair, a color). Use **`class`** when you need identity or inheritance.
**Synthesizers and generators are classes** — that's why guide 1 wrote `final class SineTone: SynthesizerBase`. A synthesizer *is a* `SynthesizerBase` (inheritance), and the engine tracks it by identity. You'll subclass `SynthesizerBase` for every sound you design and `override func build()` to describe its graph.
Mark classes you don't intend to subclass as `final` — it's clearer and lets the compiler optimize. Lyrebird's own synthesizer examples are all `final`.
---
## Best practices checklist
Carry these from day one — they're the difference between Swift that fights you and Swift that flows:
1. **`let` by default, `var` only when it changes.**
2. **Annotate the type on every `let` and `var`** (`let freq: Double = 440.0`). Clearer for readers, and faster to compile because Swift skips inference — a real win on large projects. The only exceptions are the few places Swift's grammar forbids it (closure params, tuple destructures, pattern bindings).
3. **Never force-unwrap with `!`.** Use `if let`, `guard let`, or `?? fallback`. (Non-negotiable in Lyrebird.)
4. **Let argument labels do their job** — they make call sites self-documenting.
5. **Prefer `struct` for data, `class` for identity/inheritance.** Mark classes `final` unless subclassing is intended.
6. **Convert number types explicitly** (`Double(n)`); don't fight the compiler, follow it.
7. **Handle errors where they happen** — `do/catch`, don't ignore `try`.
8. **Name things for what they mean** — `cutoffHz`, not `f`; `voiceCount`, not `n`.
9. **Small functions.** If `build()` gets long, extract helpers (guide 3 shows how).
The Lyrebird codebase enforces #2 as a hard rule, and adds one more on top: **no magic numbers** — name every non-trivial literal with a `let` (`let killQueueCapacity: Int = 32`). Both are documented in the project's `CLAUDE.md`. Annotation is a good habit in any Swift project; the magic-number rule matters most when you contribute to Lyrebird itself.
---
## What you learned
You can now read and write the Swift that Lyrebird programs are made of: values, types, optionals, control flow, functions, errors, and the struct/class distinction — plus the habits that keep it clean.
Next: [Types & Functional Programming](03-types-and-functional.md) — Swift's type system in depth and the functional tools (`map`, `filter`, closures) that make building synthesis graphs elegant.
@@ -0,0 +1,272 @@
# 3 · Types & Functional Programming
Swift's type system and its functional tools are exactly the parts that make Lyrebird pleasant. Instead of hand-wiring twelve oscillators, you *describe* twelve oscillators and let Swift build them. This guide connects Swift's types and functional style directly to synthesis.
---
## Part 1 — Swift's type system, the parts that matter here
### Type annotations — write them, especially here
Guide 2 made the case; this guide is where it pays off. Swift *can* infer a binding's type, so both of these compile:
```swift
let freq = 440.0 // inferred Double — works, but don't
let freq: Double = 440.0 // annotated — do this
```
**Always annotate.** Two reasons, and both bite harder in this guide's territory:
- **Clarity.** The expressions you're about to build — `carrier * tremolo`, `voices.reduce(0.0) { $0 + $1 }`, chained `map`/`filter` — produce types that aren't obvious at a glance (`BinaryOpGenerator`, `GeneratorArray`, `any ValidGeneratorInput`). The annotation tells the reader exactly what they're holding.
- **Compile speed.** Swift's type inference is *most* expensive on exactly these long, generic, operator-heavy graph expressions. Annotating the binding short-circuits the inference work. One file won't matter; a large project full of synth graphs will feel the difference, and so will the Xcode editor.
Every example below is annotated. The only spots left un-annotated are the three where Swift's grammar forbids it — **closure parameters** (`{ x in … }`), **tuple destructures** (`let (a, b) = pair`), and **pattern bindings** (`case let .hz(f)`) — all of which appear in this guide and are flagged where they do.
### Enums — a fixed set of named choices
An `enum` is one of a closed list of cases. Perfect for a mode, a waveform choice, a rate:
```swift
enum Waveform {
case sine, saw, square, triangle
}
func makeOsc(_ w: Waveform, freq: Double) -> any AudioGenerator {
switch w {
case .sine: return OscSin.Audio(freq: freq)
case .saw: return OscSawtooth.Audio(freq: freq)
case .square: return OscSquare.Audio(freq: freq)
case .triangle: return OscTriangle.Audio(freq: freq)
}
}
```
The compiler forces the `switch` to handle every case — add a new waveform and it *tells* you every place that needs updating. That's the safety enums buy. Lyrebird uses them widely (rate kinds, distribution kinds, error kinds).
Enums can carry values, too:
```swift
enum Pitch {
case hz(Double) // raw frequency
case midi(Int) // MIDI note number
}
func frequency(of p: Pitch) -> Double {
switch p {
case .hz(let f): return f
case .midi(let n): return 440.0 * pow(2.0, Double(n - 69) / 12.0)
}
}
frequency(of: .midi(69)) // 440.0
frequency(of: .hz(500.0)) // 500.0
```
### Protocols — "any type that can do X"
A **protocol** is a contract: a set of capabilities a type promises to provide. This is the backbone of Lyrebird's design. You've already used several without naming them:
- `Generator` — anything that produces samples (oscillators, filters, effects).
- `AudioGenerator` / `ControlGenerator` — generators that run at audio rate vs. control (block) rate.
- `ValidGeneratorInput` — anything you can pass as a generator's input.
That last one is why you can write **any** of these as a `freq:` argument:
```swift
OscSin.Audio(freq: 440.0) // a Double is a ValidGeneratorInput
OscSin.Audio(freq: 440) // an Int is too
OscSin.Audio(freq: someOtherOscillator) // a Generator is too — that's FM!
```
`freq:` accepts `any ValidGeneratorInput`. A literal number gives a fixed frequency; passing another generator means that generator *modulates* the frequency. One protocol, three behaviors, no overloads to memorize.
The keyword `any` (as in `any AudioGenerator`, `any ValidGeneratorInput`) means "some value whose exact type I don't need to name, as long as it satisfies this protocol." You'll type it often.
### Operator overloading — audio math reads like math
Lyrebird defines `+ - * /` on generators, so signal processing looks like arithmetic:
```swift
let carrier: OscSin.Audio = OscSin.Audio(freq: 440.0)
let tremolo: OscSin.Audio = OscSin.Audio(freq: 5.0, mul: 0.5, add: 0.5) // 5 Hz, range 0…1
let wobbled: BinaryOpGenerator = carrier * tremolo // amplitude modulation
let mixed: BinaryOpGenerator = wobbled + noiseLayer // sum two signals
```
Note the annotations: `carrier * tremolo` and `wobbled + noiseLayer` both produce a `BinaryOpGenerator` — the type Lyrebird's overloaded `*` and `+` return. Writing it out means you (and the compiler) don't have to work it out.
`carrier * tremolo` isn't multiplying two numbers — it builds a new generator that multiplies the two signals sample by sample. The result is itself a `Generator`, so you keep composing. This is the single most Swift-flavored thing about Lyrebird, and it comes straight from operator overloading.
---
## Part 2 — Closures, the gateway to functional style
A **closure** is a block of code you can pass around like a value — an anonymous function. Full form:
```swift
let double: (Double) -> Double = { x in
return x * 2.0
}
double(21.0) // 42.0
```
The binding's type is `(Double) -> Double` — "takes a Double, returns a Double." Because we annotated it, the closure's own parameter `x` is inferred (closure parameters are one of the three places you *can't* write an annotation). Swift lets you shrink closures aggressively. When the type is known from context, you can drop the parameter types, the `return`, and even name parameters positionally with `$0`, `$1`:
```swift
// These are the same closure, progressively shortened:
{ (x: Double) -> Double in return x * 2.0 }
{ x in x * 2.0 }
{ $0 * 2.0 }
```
`$0` is "the first argument." This terse form is everywhere in Swift and in Lyrebird — you saw it already:
```swift
let oscs: GeneratorArray = expand([440.0, 880.0]) { OscSin.Audio(freq: $0) }
// └── a closure: "given a frequency $0, make an oscillator"
```
When a closure is the **last** argument, it moves outside the parentheses (trailing-closure syntax) — that's why `expand([...]) { … }` has the braces hanging off the end.
---
## Part 3 — `map`, `filter`, `reduce` on collections
These three functions replace most `for` loops in idiomatic Swift, and they shine when generating synthesis material.
### `map` — transform every element
```swift
let midiNotes: [Int] = [60, 64, 67, 71] // a Cmaj7 chord
let freqs: [Double] = midiNotes.map { midiToHz($0) } // → [261.6, 329.6, 392.0, 493.9]
```
`map` runs the closure on each element and collects the results into a new array. No loop, no mutable accumulator, no index bookkeeping.
### `filter` — keep the elements that pass a test
```swift
let audible: [Double] = freqs.filter { $0 < 20000.0 } // drop anything above hearing
```
### `reduce` — combine everything into one value
```swift
let total: Double = freqs.reduce(0.0) { $0 + $1 } // sum
// or the shorthand:
let total2: Double = freqs.reduce(0.0, +)
```
`reduce` starts from an initial value (`0.0`) and folds each element in. `$0` is the running result, `$1` the current element.
### Chaining them
```swift
let detuned: [Double] = midiNotes
.map { midiToHz($0) } // notes → frequencies
.map { $0 * 1.003 } // detune each up ~5 cents
.filter { $0 < 8000.0 } // drop the highest partials
```
Each step is a small, obvious transformation. Read top to bottom, it's a pipeline.
---
## Part 4 — Putting it together in a Synthesizer
Here's where functional style pays off. A chord synthesizer, built from an array of MIDI notes — no matter how many notes, the code is the same length:
```swift
final class Chord: SynthesizerBase {
// The notes to play. Change this array; the graph adapts.
let notes: [Int] = [60, 64, 67, 71] // Cmaj7
override func build() {
// 1. Notes → frequencies (map).
let freqs: [Double] = notes.map { midiToHz($0) }
// 2. Frequencies → oscillators, one per note. Quieter as the chord grows.
let level: Double = 0.2 / Double(freqs.count)
let voices: [OscSin.Audio] = freqs.map {
OscSin.Audio(freq: $0, mul: level)
}
// 3. Sum all voices to a single mono signal (reduce, starting from silence).
let mix: any ValidGeneratorInput = voices.reduce(0.0) { $0 + $1 }
// 4. Center it and send to output.
output(bus: 0, source: Pan2(input: mix, pan: 0.0))
}
// MIDI note number → frequency in Hz.
func midiToHz(_ note: Int) -> Double {
return 440.0 * pow(2.0, Double(note - 69) / 12.0)
}
}
```
Read step 3 carefully: `voices.reduce(0.0) { $0 + $1 }` starts from the scalar `0.0` and adds each oscillator in turn using Lyrebird's overloaded `+`. The result is a generator that sums the whole chord. Add a note to `notes` and everything downstream just works.
### Multichannel with `expand`
If instead of *mixing* the notes you want each on its **own output channel**, Lyrebird gives you `expand`, the generator-graph cousin of `map`:
```swift
override func build() {
let freqs: [Double] = notes.map { midiToHz($0) }
// One generator per channel: channel 0 = first note, channel 1 = second, …
let spread: GeneratorArray = expand(freqs) { OscSin.Audio(freq: $0, mul: 0.15) }
output(bus: 0, source: spread)
}
```
`expand(inputs) { factory }` is `map` for building a multichannel `GeneratorArray`: it applies the factory closure to each input and bundles the results into one channel-per-element generator. Same mental model as `map`, tuned for the audio graph.
---
## Part 5 — Value types keep synthesizers safe
Recall from guide 2: `struct` is a value type, copied on assignment. Lyrebird leans on this. When the engine runs your synthesizer, it works with a **copy of the graph per instance** — no two playing voices share mutable state, which is what makes polyphony safe on the audio thread.
You benefit by keeping your *own* data in `struct`s and `let`s. A little value type to bundle note parameters:
```swift
struct VoiceSpec {
let freq: Double
let amp: Double
let pan: Double
}
let specs: [VoiceSpec] = [
VoiceSpec(freq: 220.0, amp: 0.2, pan: -0.5),
VoiceSpec(freq: 440.0, amp: 0.2, pan: 0.5),
]
```
Then drive the graph from data:
```swift
override func build() {
let voices: [any ValidGeneratorInput] = specs.map { spec in
let osc: OscSin.Audio = OscSin.Audio(freq: spec.freq, mul: spec.amp)
return Pan2(input: osc, pan: spec.pan)
}
// Two Pan2 outputs, each already stereo — sum them.
let mix: any ValidGeneratorInput = voices.reduce(0.0) { $0 + $1 }
output(bus: 0, source: mix)
}
```
**Data describes the sound; `map` turns data into graph.** That separation — a plain array of specs, a functional transform into generators — is the pattern you'll reuse constantly.
---
## What you learned
- Swift's **enums, protocols, and operator overloading** are the machinery behind Lyrebird's expressive API — `any ValidGeneratorInput`, `freq:` accepting a modulator, `a + b` mixing signals.
- **Closures** (`{ $0 * 2 }`) and the **functional trio** (`map`, `filter`, `reduce`) let you generate synthesis material from data with no loops.
- `expand` is `map` for building multichannel generators.
- Keeping your parameters in **value types** mirrors how Lyrebird keeps voices independent.
- **Annotating every binding** earns the most here: graph expressions have non-obvious types, and inference on them is the slowest thing you can ask the compiler to do.
Next: [Xcode, Packages & Debugging](04-xcode-and-packages.md) — moving from single files to real projects: the IDE, adding Lyrebird as a package, Debug vs Release, and breakpoints.
@@ -0,0 +1,260 @@
# 4 · Xcode, Packages & Debugging
So far you've run single `.swift` files. Real work happens in **projects**: multiple files, dependencies like Lyrebird, a build configuration, and a debugger. This guide covers the tools — Xcode and Swift Package Manager — plus how to add Lyrebird, how to set up Debug vs Release, and how to debug a running synth without breaking the audio.
---
## Part 1 — Two ways to build, and when to use each
You have two toolchains, and they're two views of the *same* project:
| | Swift Package Manager (CLI) | Xcode (IDE) |
|---|---|---|
| Invoked with | `swift build`, `swift run`, `swift test` | GUI: pick a scheme, press ▶ |
| Best for | quick iteration, servers, CI, headless CLI synths | editing with autocomplete, the visual debugger, GUI/iOS apps |
| Debugger | `lldb` on the command line | graphical breakpoints, variable inspector |
They read the **same `Package.swift`**. Use the CLI for fast loops on a command-line piece; use Xcode when you want autocomplete, breakpoints you can click, or you're building a windowed/iOS app. Learn both — they complement each other.
### Installing Xcode
Install **Xcode** from the Mac App Store (it's large — several GB). Launch it once so it finishes installing components. That also gives you the command-line tools (`swift`, `xcodebuild`, `lldb`). Lyrebird needs **Xcode 16+, macOS 15+**.
Verify from Terminal:
```sh
swift --version # expect Apple Swift version 6.0
xcode-select -p # should print a path, not an error
```
---
## Part 2 — What a Swift package is
A **Swift package** is a folder with a `Package.swift` manifest describing what to build and what it depends on. The manifest *is* Swift code:
```swift
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "MyPiece",
platforms: [.macOS(.v15)],
dependencies: [
// Lyrebird, fetched from its git host:
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
],
targets: [
.executableTarget(
name: "MyPiece",
dependencies: [
.product(name: "Lyrebird", package: "Lyrebird"),
// add this line only if you use the GUI module:
// .product(name: "LyrebirdUI", package: "Lyrebird"),
]
),
]
)
```
Key ideas:
- **`dependencies`** lists packages you rely on. `from: "1.0.0"` means "1.0.0 or any compatible later version." SwiftPM downloads and pins them for you.
- **`targets`** are the things *you* build. An `.executableTarget` produces a runnable program (it needs a `main.swift`); a `.testTarget` holds tests; a `.library` target is reusable code.
- A target lists which **products** of a dependency it uses. Lyrebird vends `Lyrebird` (the core), `LyrebirdUI` (SwiftUI controls), and a few others.
> One inconsistency you may notice: `let package = Package(…)` here has **no** type annotation, even though guide 2 told you to annotate everything. `Package.swift` is a manifest, and every Swift package — Lyrebird's included — writes that line un-annotated by convention. It's the one place to follow the crowd. In your actual *program* code (`main.swift`, your synthesizers), keep annotating.
> **The naming quirk, one more time:** you depend on the product `Lyrebird`, but in your Swift files you write `import LyrebirdSynth`. Product name ≠ module name. This trips up everyone once; now it won't trip up you.
### The fastest way to scaffold: the `lyrebird` CLI
Lyrebird ships a command-line tool that writes the whole package for you:
```sh
lyrebird new MyPiece # creates MyPiece/ with Package.swift + main.swift
cd MyPiece
lyrebird run # build and play
```
That's the shortest path and it generates a correct `Package.swift`. See [`docs/tooling/cli-guide.md`](../tooling/cli-guide.md) for the full CLI. If you'd rather do it by hand, the manifest above is all you need.
### Using a local Lyrebird checkout
If you've cloned Lyrebird next to your project (common while learning, so you can read the source), depend on it by **path** instead of URL:
```swift
dependencies: [
.package(path: "../Lyrebird"), // relative to your Package.swift
],
```
This is exactly what the bundled demos do — look at `Demos/LyrebirdQuickstartDemo/Package.swift`.
---
## Part 3 — Opening and running in Xcode
Two ways to open a package in Xcode:
- **A package folder:** `File → Open…` and select the folder containing `Package.swift` (or run `xed .` from inside it in Terminal). Xcode reads the manifest, resolves dependencies, and you're ready.
- **A workspace/project:** the Lyrebird demos ship a `Lyrebird.xcworkspace` — open *that*, not an individual `.xcodeproj`, so all demos share the one local package.
Once open:
1. **Pick a scheme** in the toolbar (top, next to the ▶/■ buttons). A **scheme** says *what to run* — e.g. `MyPiece`, or `LyrebirdQuickstartDemo`. For a package, Xcode makes one scheme per executable/test target.
2. **Pick a destination** — "My Mac" for a macOS piece, or a connected iPhone / simulator for iOS. (iOS simulators produce no audio; use a real device for sound.)
3. **Press ▶ (Run)** or `⌘R`. Xcode builds and launches. Output appears in the **console** at the bottom.
4. **Press ■ (Stop)** or `⌘.` to end it.
**Targets vs. schemes, briefly:** a *target* is a buildable unit defined in `Package.swift` (your executable, the test bundle). A *scheme* is a saved recipe for building and running one or more targets in a chosen configuration. You edit build behavior (including Debug vs Release, next) by editing the scheme.
The CLI equivalents, for reference:
```sh
swift build # compile (Debug by default)
swift run # build + run
swift test # run tests
swift run -c release # build + run optimized (see below)
```
---
## Part 4 — Debug vs Release configurations
Every build uses a **configuration**. Two ship by default:
| | **Debug** | **Release** |
|---|---|---|
| Optimization | none (`-Onone`) | full (`-O`) |
| Speed | slow | fast (often 5–20× on DSP) |
| Symbols / debug info | full | present, but code is reordered/inlined |
| Safety checks | on | some elided |
| Use for | editing, breakpoints, stepping | performance, real audio, shipping |
### Why this matters *a lot* for audio
Lyrebird runs your generator graph on a real-time thread that must finish each 512-sample block before the deadline. **Debug builds are unoptimized and can be 10× slower** — heavy patches that run cleanly in Release will glitch, crackle, or drop out in Debug. Two consequences:
- When something *sounds* wrong but *is* logically correct, **try a Release build before assuming a bug** — you may just be starved for CPU.
- Any performance measurement in Debug is meaningless. Lyrebird's own benchmark docs say it outright: *"Always run with `-c release`; debug builds give meaningless numbers."*
So: **debug logic in Debug, judge sound and speed in Release.**
### Switching configuration — command line
```sh
swift run # Debug
swift run -c release # Release
swift build -c release # Release build only
```
### Switching configuration — Xcode
Xcode's ▶ Run button uses your scheme's **Run** action, which defaults to **Debug**. To change it:
1. Menu **Product → Scheme → Edit Scheme…** (or click the scheme name → *Edit Scheme…*).
2. Select the **Run** action in the left column.
3. On the **Info** tab, set **Build Configuration** to **Release** (or back to **Debug**).
4. Close. Now ▶ builds that configuration.
A common workflow is to leave **Run = Debug** (so breakpoints and stepping work well) and switch to **Release** only when you want to hear the patch at full performance or profile it. The **Profile** action (`⌘I`, opens Instruments) already defaults to Release for exactly this reason.
### Per-target build settings
If you need finer control (a custom optimization flag, a compilation condition), a SwiftPM target can carry settings in `Package.swift`:
```swift
.executableTarget(
name: "MyPiece",
dependencies: [ .product(name: "Lyrebird", package: "Lyrebird") ],
swiftSettings: [
// Example: define a flag you can check with #if in code.
.define("VERBOSE_LOGGING", .when(configuration: .debug)),
// Example: force optimization even in Debug for a hot target.
.unsafeFlags(["-Ounchecked"], .when(configuration: .release)),
]
)
```
Then in code:
```swift
#if VERBOSE_LOGGING
print("Voice started at \(freq) Hz") // compiled in only for Debug
#endif
```
`#if … #endif` is **conditional compilation** — the code inside only exists in builds where the flag is set. Great for debug-only logging that costs nothing in Release. (You'll also see `#if os(iOS)` / `#if os(macOS)` in Lyrebird for platform-specific code.)
---
## Part 5 — Breakpoints and debugging
### Setting a breakpoint
In Xcode, click the **gutter** (the margin left of the line numbers) next to a line. A blue arrow appears — that's a breakpoint. Run in **Debug**; when execution reaches that line it **pauses**, and you can:
- **Inspect variables** in the Variables View (bottom-left), or hover over a value in the editor.
- **Step** with the toolbar: *Step Over* (`F6`, run this line), *Step Into* (`F7`, descend into the call), *Step Out* (`F8`, finish the current function), *Continue* (`⌃⌘Y`, resume).
- **Evaluate expressions** in the console with `po` (print object) or `p`:
```
(lldb) po freqs
(lldb) po engine.sampleRate
(lldb) p 440.0 * 2
```
### Conditional and action breakpoints
Right-click a breakpoint → **Edit Breakpoint…** to:
- Add a **condition** — pause only when it's true, e.g. `note > 100`. Invaluable when a loop runs thousands of times and only one iteration is wrong.
- Add an **action** like *Log Message* or *Debugger Command*, optionally with **"Automatically continue"** — so it logs without stopping. This is a print statement you can add/remove without editing and rebuilding.
### The audio-thread rule — do NOT breakpoint the render callback
This is the one debugging pitfall unique to real-time audio, and it's important:
> **Never set a breakpoint inside a Generator's `_computeSamples` / render path.** That code runs on the real-time audio thread. Pausing it freezes audio production entirely — the device underruns, you get a horrible glitch or silence, and the state you're inspecting is already unrepresentative. The same goes for `print` on that thread: allocating a `String` mid-render can itself cause a dropout. (This is why Lyrebird's rules forbid `print`, allocation, and locks on the RT thread.)
Where you **can** freely breakpoint and print: your **setup and control code** — `build()`, `main.swift`, parameter changes, scheduling, anything that runs on the main thread before or between audio blocks. Break in `build()` to inspect the graph you're wiring; that's on the main thread and perfectly safe.
### Debugging what the audio thread is doing
Since you can't stop the render thread, Lyrebird gives you non-blocking tools instead:
- **`SynthesizerBase.debugTap`** — a per-instance, RT-safe tap for observing a live voice's output without breaking timing. See [`Sources/Lyrebird/Lyrebird.docc/Debugging.md`](../../Sources/Lyrebird/Lyrebird.docc/Debugging.md) for this and LLDB recipes for inspecting a live generator.
- **`GeneratorBase.debugTag`** — label a generator so you can find it in the debugger.
- The **message center** and **node-tree mirror** (`docs/diagnostics-guide.md`) surface what the engine is doing as inspectable, non-RT data.
For ordinary Swift logic bugs — a wrong frequency table, an off-by-one in a pattern, an optional that's unexpectedly `nil` — regular breakpoints in your main-thread code are exactly the right tool.
### Crashes and the "force-unwrap" reminder
If your program crashes with `Fatal error: Unexpectedly found nil while unwrapping an Optional`, you (or code you called) used `!` on a `nil` optional — the exact thing guide 2 warned against. The debugger stops on the offending line; read it, then replace the `!` with `if let` / `guard let` / `??`. In Lyrebird's own code this is a banned pattern precisely because on the audio thread that crash is a hard failure.
---
## Part 6 — A realistic workflow
Putting the whole toolchain together, a typical loop while developing a piece:
1. **Edit** in Xcode (autocomplete, inline errors) — or your editor of choice.
2. **Run in Debug** (`⌘R`) to check logic; set breakpoints in `build()`/`main.swift` if something's off.
3. **Switch the scheme to Release** (or `swift run -c release`) to hear it perform and confirm it's not CPU-starved.
4. **Iterate.** For fast headless loops, `swift run` from Terminal beats a full IDE cycle.
5. **Test** with `swift test` if you've written any (Lyrebird uses Swift Testing — `@Test`, `#expect`).
---
## What you learned
- A **Swift package** (`Package.swift`) declares dependencies and targets; add Lyrebird by URL or local path, then `import LyrebirdSynth`.
- **Xcode** (schemes, destinations, ▶) and the **`swift` CLI** are two views of the same package — use each where it's strongest.
- **Debug vs Release**: debug logic in Debug, judge sound and speed in Release; switch via *Edit Scheme → Run → Build Configuration* or `-c release`. Debug audio can glitch purely from being unoptimized.
- **Breakpoints** are for your main-thread setup/control code. **Never** breakpoint or `print` on the render thread — use `debugTap`, `debugTag`, and the diagnostics tools instead.
---
That's the series. You can now write Swift, understand Lyrebird's shape, use its expressive type-driven API, and build/run/debug real projects. From here, the [main documentation](../../README.md) — the generator catalog, the synthesizer protocol, routines and patterns — is open to you. Go make sound.
+36
View File
@@ -0,0 +1,36 @@
# Learning Swift for Lyrebird
You saw Lyrebird make sound and you want in — but you've never written Swift, and every Swift tutorial you find is about buttons, table views, and iPhone apps. This series is different. It teaches **just enough Swift to be productive in Lyrebird**, using audio examples the whole way.
You do **not** need to be an iOS developer. You do not need SwiftUI (though it helps later, once you build GUIs). You need to be comfortable reading and writing small programs, understanding types, and running them. That's what these four documents give you.
## Who this is for
- Musicians, composers, and sound designers coming from SuperCollider, Max/MSP, Pd, Csound, or Faust.
- Programmers in other languages (Python, JavaScript, C++) who want the Swift-specific parts fast.
- Anyone who felt "I get the *idea* of Lyrebird, I just don't know how to type the Swift."
## The path
Read them in order. Each is short and ends where the next begins.
| # | Document | What you'll be able to do |
|---|----------|---------------------------|
| 1 | [Hello, World](01-hello-world.md) | Make Lyrebird produce a tone from a program you wrote and ran yourself. Understand every line of it. |
| 2 | [Swift Basics & Best Practices](02-swift-basics.md) | Read and write Swift confidently: variables, functions, control flow, optionals, classes vs structs, and the style Lyrebird expects. |
| 3 | [Types & Functional Programming](03-types-and-functional.md) | Use Swift's type system and functional tools (`map`, `filter`, closures) to build and control synthesis graphs cleanly. |
| 4 | [Xcode, Packages & Debugging](04-xcode-and-packages.md) | Open, build, and run projects in Xcode; add Lyrebird as a package; configure Debug vs Release; set breakpoints and debug a running synth. |
## The one-minute mental model
Lyrebird is a **library**, not an app and not a language. You write a normal Swift program. In it you:
1. Create a `SynthesisEngine` — it owns the audio hardware.
2. Describe sound by subclassing `SynthesizerBase` and wiring **generators** (oscillators, filters, effects) together in a `build()` method.
3. Hand your synthesizer to the engine with `engine.add(...)`.
There is no separate scripting language to learn (unlike SuperCollider's sclang or Csound's orchestra). The language *is* Swift. That's the whole reason this series exists: learn a slice of Swift, and you've learned how to drive Lyrebird.
> **A naming quirk to know from the start:** in `Package.swift` you depend on a product called `Lyrebird`, but in your source you write `import LyrebirdSynth`. That's expected — the product and the module have different names. Both guides 1 and 4 remind you.
Start with [Hello, World](01-hello-world.md).