Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e600f3a66 | |||
| 06bdcbbe92 | |||
| 162da89319 | |||
| 9f244b1939 | |||
| 24ea32e47c | |||
| c14efe998a | |||
| 63b630b317 | |||
| 3668739d20 | |||
| 6e7f4c0076 |
+1
-1
@@ -127,7 +127,7 @@ let package = Package(
|
||||
.library(name: "LyrebirdMyExtension", targets: ["LyrebirdMyExtension"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
// `makeDefaultAudioDriver()` selects the platform backend — Core Audio on Apple,
|
||||
// ALSA on Linux (needs libasound) — so the demo builds and runs on both.
|
||||
let engine = SynthesisEngine(
|
||||
blockSize: 512,
|
||||
sampleRate: 44100,
|
||||
numOutputChannels: 2,
|
||||
numInputChannels: 2,
|
||||
driver: CoreAudioDriver()
|
||||
driver: makeDefaultAudioDriver()
|
||||
)
|
||||
|
||||
do {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"originHash" : "c2996d6577ec0139a89be2f2d57d304047b7d5bf7f7eba2577fde9dc2fdc0b91",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "linenoise-swift",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/andybest/linenoise-swift",
|
||||
"state" : {
|
||||
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
||||
"version" : "0.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "nimble",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/Quick/Nimble.git",
|
||||
"state" : {
|
||||
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
||||
"version" : "7.3.4"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Package.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// swift-tools-version: 6.0
|
||||
import PackageDescription
|
||||
|
||||
// A single cross-platform GUI demo: one shared library of synths + views, and a
|
||||
// thin executable entry point that bootstraps the native toolkit per platform —
|
||||
// AppKit/SwiftUI on macOS, GTK4/SwiftOpenUI on Linux. The view bodies are written
|
||||
// to the subset of the View DSL that both backends share, so the UI is one source.
|
||||
//
|
||||
// macOS: swift run LyrebirdGUIDemo (or open the thin Xcode project)
|
||||
// Linux: swift run LyrebirdGUIDemo (needs libgtk-4-dev + libasound2-dev)
|
||||
//
|
||||
// Select the synth with LYREBIRD_DEMO=vector (default) or LYREBIRD_DEMO=sine.
|
||||
let package = Package(
|
||||
name: "LyrebirdGUIDemo",
|
||||
platforms: [.macOS(.v15)],
|
||||
products: [
|
||||
.library(name: "LyrebirdGUIDemoKit", targets: ["LyrebirdGUIDemoKit"]),
|
||||
.executable(name: "LyrebirdGUIDemo", targets: ["LyrebirdGUIDemo"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../.."),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "LyrebirdGUIDemoKit",
|
||||
dependencies: [
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdUI", package: "Lyrebird"),
|
||||
],
|
||||
path: "Sources/LyrebirdGUIDemoKit"
|
||||
),
|
||||
.executableTarget(
|
||||
name: "LyrebirdGUIDemo",
|
||||
dependencies: [
|
||||
"LyrebirdGUIDemoKit",
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdUI", package: "Lyrebird"),
|
||||
],
|
||||
path: "Sources/LyrebirdGUIDemo"
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,58 @@
|
||||
<!--
|
||||
README.md
|
||||
Lyrebird
|
||||
Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
SPDX-License-Identifier: MIT
|
||||
-->
|
||||
|
||||
# LyrebirdGUIDemo — one GUI demo, two platforms
|
||||
|
||||
A live-controllable synth GUI that builds and runs from a single source tree on
|
||||
**macOS** (AppKit + SwiftUI) and **Linux** (GTK4 + SwiftOpenUI). It is the
|
||||
cross-platform counterpart to the richer, macOS-only `LyrebirdMacOSDemo` Xcode
|
||||
project.
|
||||
|
||||
The split follows the "mostly in a package, thin entry points" shape:
|
||||
|
||||
| Piece | Where | Platform |
|
||||
|---|---|---|
|
||||
| Synths + views | `Sources/LyrebirdGUIDemoKit/` | shared — one source |
|
||||
| App bootstrap | `Sources/LyrebirdGUIDemo/main.swift` | one `#if` (AppKit vs GTK4) |
|
||||
|
||||
The view bodies are written to the subset of the View DSL that SwiftUI and
|
||||
SwiftOpenUI share, so there is **one** body per view — not a macOS copy and a
|
||||
Linux copy. Both back ends bind the same core `@UIParam` / `UIParamNode` model,
|
||||
so the controls, the oscilloscope, and the CPU meters are identical.
|
||||
|
||||
## Run it
|
||||
|
||||
```bash
|
||||
swift run LyrebirdGUIDemo # vector oscillator (default)
|
||||
LYREBIRD_DEMO=sine swift run LyrebirdGUIDemo # stereo sine tone
|
||||
```
|
||||
|
||||
- **macOS** — no extra setup; a native window opens with live audio via Core Audio.
|
||||
- **Linux** — needs `libgtk-4-dev` (GUI) and `libasound2-dev` + a sound device
|
||||
(audio). Without a sound backend the window still opens and the controls work;
|
||||
there is just no sound (`isLiveAudioAvailable` reports it, and the console says so).
|
||||
|
||||
## Open in an IDE
|
||||
|
||||
- **Xcode (macOS)** — open the folder (or `Package.swift`); Xcode treats it as a
|
||||
SwiftPM package. Pick the `LyrebirdGUIDemo` scheme and Run. No `.xcodeproj` to
|
||||
maintain — the package *is* the project.
|
||||
- **VS Code (Linux)** — open the folder with the Swift extension
|
||||
(`swiftlang.swift-vscode`); it picks up `Package.swift`. Run `LyrebirdGUIDemo`
|
||||
from the test/run explorer or a terminal.
|
||||
|
||||
## What each demo shows
|
||||
|
||||
- **vector** — `VectorOscillatorUI`: an XY pad crossfades four corner wavetables
|
||||
(sine / saw-ish / triangle / Hanning); frequency and amplitude knobs; a live
|
||||
oscilloscope and CPU-load strip.
|
||||
- **sine** — `SineToneUI`: a frequency slider, amplitude and pan knobs, a level
|
||||
readout, the scope and CPU strip, and a static envelope plot.
|
||||
|
||||
Add a synth by dropping a `SynthesizerBase` subclass and a node-based view into
|
||||
`LyrebirdGUIDemoKit`, then extend `DemoSelection` and the `demoContent()` switch
|
||||
in `main.swift`.
|
||||
@@ -0,0 +1,181 @@
|
||||
// main.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Thin cross-platform entry point. The shared synths + views live in
|
||||
// `LyrebirdGUIDemoKit`; this file only bootstraps the native toolkit and opens a
|
||||
// window hosting the selected demo view:
|
||||
//
|
||||
// • macOS — AppKit `NSApplication` + `LyrebirdWindow` (SwiftUI content).
|
||||
// • Linux — a GTK4 `App`/`WindowGroup` scene run by `GTK4Backend`.
|
||||
//
|
||||
// Run either with `swift run LyrebirdGUIDemo`. Pick the synth with
|
||||
// `LYREBIRD_DEMO=vector` (default) or `LYREBIRD_DEMO=sine`.
|
||||
//
|
||||
// `@ViewBuilder` and the window hosts come from SwiftUI on macOS and from
|
||||
// SwiftOpenUI (re-exported through `LyrebirdUI`) on Linux — hence the single
|
||||
// `#if canImport(SwiftUI)` import guard.
|
||||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
#endif
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
import LyrebirdGUIDemoKit
|
||||
|
||||
// MARK: - Shared setup (runs on both platforms)
|
||||
|
||||
let selection: DemoSelection = DemoSelection.fromEnvironment()
|
||||
|
||||
private let demoBlockSize: Int = 512
|
||||
private let demoSampleRate: Double = 44_100.0
|
||||
private let demoScopeBufferSize: Int = 2048
|
||||
|
||||
// Oscilloscope tap on the stereo output buses. Must be set before `start()`.
|
||||
let demoScope: ScopeCapture = ScopeCapture(buses: [0, 1], bufferSize: demoScopeBufferSize)
|
||||
|
||||
// Core Audio on Apple, ALSA on a Linux build with libasound, else a silent
|
||||
// OfflineDriver. The GUI runs either way; `isLiveAudioAvailable` reports which.
|
||||
let demoDriver: any AudioDriver = makeDefaultAudioDriver()
|
||||
let demoEngine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: demoBlockSize,
|
||||
sampleRate: demoSampleRate,
|
||||
numOutputChannels: 2,
|
||||
numInputChannels: 0,
|
||||
driver: demoDriver
|
||||
)
|
||||
demoEngine.scopeTap = demoScope
|
||||
|
||||
// Both synths are cheap to build; only the selected one is added to the engine.
|
||||
// Building both keeps the node extraction below branch-free (no force-unwrap).
|
||||
let vectorSynth: VectorOscillatorUI = VectorOscillatorUI()
|
||||
let sineSynth: SineToneUI = SineToneUI()
|
||||
let activeSynth: SynthesizerBase = (selection == .vector) ? vectorSynth : sineSynth
|
||||
|
||||
// Extract the projected parameter nodes here, in main.swift's top-level
|
||||
// `@MainActor` context: `SynthesizerBase` is `@MainActor`, so `synth.$…` is only
|
||||
// reachable on the main actor. The nodes are not actor-isolated, so the
|
||||
// (nonisolated, on Linux) view body can read them freely.
|
||||
let vectorX: UIParamNode = vectorSynth.$x
|
||||
let vectorY: UIParamNode = vectorSynth.$y
|
||||
let vectorFreq: UIParamNode = vectorSynth.$frequency
|
||||
let vectorAmp: UIParamNode = vectorSynth.$amplitude
|
||||
|
||||
let sineFreq: UIParamNode = sineSynth.$frequency
|
||||
let sineAmp: UIParamNode = sineSynth.$amplitude
|
||||
let sinePan: UIParamNode = sineSynth.$pan
|
||||
|
||||
// A static example envelope for the sine demo's envelope plot.
|
||||
let demoEnvelope: Envelope = Envelope(
|
||||
levels: [0.0001, 1.0, 0.6, 0.4, 0.0001],
|
||||
durations: [0.05, 0.15, 0.4, 0.3],
|
||||
curves: [.exponential, .exponential, .lin, .exponential],
|
||||
loopNode: 2,
|
||||
releaseNode: 4
|
||||
)
|
||||
|
||||
// `SynthesisEngine` is not Sendable; the status view only reads plain CPU-load
|
||||
// doubles off it, and this demo runs entirely on the UI thread, so a nonisolated
|
||||
// handle is safe (mirrors the Linux UI demo).
|
||||
nonisolated(unsafe) let statusEngine: SynthesisEngine = demoEngine
|
||||
|
||||
/// Builds the view for the active selection. `if`/`else` maps to the DSL's
|
||||
/// `buildEither`, which both backends provide.
|
||||
///
|
||||
/// Isolation differs by backend: SwiftUI's `View` is `@MainActor`, so on macOS
|
||||
/// this must be `@MainActor` to construct the view (and it is called from
|
||||
/// AppKit's main-actor launch). SwiftOpenUI's `View` is nonisolated, so on Linux
|
||||
/// this stays nonisolated and is callable from the nonisolated scene closure.
|
||||
#if canImport(SwiftUI)
|
||||
@MainActor
|
||||
#endif
|
||||
@ViewBuilder
|
||||
func demoContent() -> some View {
|
||||
if selection == .vector {
|
||||
VectorOscillatorDemoView(
|
||||
xNode: vectorX,
|
||||
yNode: vectorY,
|
||||
frequencyNode: vectorFreq,
|
||||
amplitudeNode: vectorAmp,
|
||||
scope: demoScope,
|
||||
engine: statusEngine
|
||||
)
|
||||
} else {
|
||||
SineToneDemoView(
|
||||
frequencyNode: sineFreq,
|
||||
amplitudeNode: sineAmp,
|
||||
panNode: sinePan,
|
||||
scope: demoScope,
|
||||
engine: statusEngine,
|
||||
envelope: demoEnvelope
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Start the engine and add the selected synth. `engine.start()` / `add` are
|
||||
// @MainActor; main.swift's top level is main-actor isolated, so these are direct
|
||||
// calls. On a build with no live backend the GUI still runs (silently).
|
||||
do {
|
||||
try demoEngine.start()
|
||||
try demoEngine.add(activeSynth)
|
||||
} catch {
|
||||
print("[Lyrebird] demo engine setup failed: \(error)")
|
||||
}
|
||||
|
||||
if !isLiveAudioAvailable {
|
||||
print("[Lyrebird] no live audio backend — the controls still work, but there is no sound.")
|
||||
}
|
||||
|
||||
// MARK: - macOS front end (AppKit + SwiftUI)
|
||||
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
|
||||
final class DemoAppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
var window: LyrebirdWindow?
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
let w: LyrebirdWindow = LyrebirdWindow(
|
||||
title: selection.windowTitle,
|
||||
width: 380,
|
||||
height: 620
|
||||
)
|
||||
w.open { demoContent() }
|
||||
window = w
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
demoEngine.stop()
|
||||
}
|
||||
}
|
||||
|
||||
MainActor.assumeIsolated {
|
||||
let app: NSApplication = NSApplication.shared
|
||||
app.setActivationPolicy(.regular)
|
||||
let delegate: DemoAppDelegate = DemoAppDelegate()
|
||||
app.delegate = delegate
|
||||
app.run()
|
||||
}
|
||||
|
||||
// MARK: - Linux front end (GTK4 + SwiftOpenUI)
|
||||
|
||||
#else
|
||||
|
||||
struct DemoApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup(selection.windowTitle) {
|
||||
demoContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GTK4Backend().run(DemoApp.self)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
// DemoSelection.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Which synthesizer the demo runs, chosen by the `LYREBIRD_DEMO` environment
|
||||
/// variable. Both front ends (AppKit on macOS, GTK4 on Linux) read the same
|
||||
/// selection so one binary covers every patch.
|
||||
public enum DemoSelection: String, Sendable {
|
||||
|
||||
/// Vector oscillator with an XY blend pad (the default).
|
||||
case vector
|
||||
|
||||
/// Stereo sine tone with frequency / amplitude / pan controls.
|
||||
case sine
|
||||
|
||||
/// Resolve the selection from `LYREBIRD_DEMO` (defaults to `.vector`).
|
||||
public static func fromEnvironment() -> DemoSelection {
|
||||
let raw: String = ProcessInfo.processInfo.environment["LYREBIRD_DEMO"]?.lowercased() ?? "vector"
|
||||
return DemoSelection(rawValue: raw) ?? .vector
|
||||
}
|
||||
|
||||
/// Title-bar text for the window hosting this demo.
|
||||
public var windowTitle: String {
|
||||
switch self {
|
||||
case .vector: return "Lyrebird — Vector Oscillator"
|
||||
case .sine: return "Lyrebird — Sine Tone"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// SineToneDemoView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
#endif
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Live controls for ``SineToneUI``: a frequency slider, amplitude and pan knobs,
|
||||
/// a level readout, a CPU-load strip, an oscilloscope, and a static envelope plot.
|
||||
///
|
||||
/// Node-based for the same reason as ``VectorOscillatorDemoView`` — the body must
|
||||
/// compile under both SwiftUI's `@MainActor` body and SwiftOpenUI's nonisolated one.
|
||||
public struct SineToneDemoView: View {
|
||||
|
||||
let frequencyNode: UIParamNode
|
||||
let amplitudeNode: UIParamNode
|
||||
let panNode: UIParamNode
|
||||
let scope: ScopeCapture
|
||||
let engine: SynthesisEngine
|
||||
let envelope: Envelope
|
||||
|
||||
public init(
|
||||
frequencyNode: UIParamNode,
|
||||
amplitudeNode: UIParamNode,
|
||||
panNode: UIParamNode,
|
||||
scope: ScopeCapture,
|
||||
engine: SynthesisEngine,
|
||||
envelope: Envelope
|
||||
) {
|
||||
self.frequencyNode = frequencyNode
|
||||
self.amplitudeNode = amplitudeNode
|
||||
self.panNode = panNode
|
||||
self.scope = scope
|
||||
self.engine = engine
|
||||
self.envelope = envelope
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
Text("Lyrebird — Sine Tone")
|
||||
.font(.headline)
|
||||
ParameterSlider("Frequency", node: frequencyNode, range: 440.0...880.0)
|
||||
HStack {
|
||||
ParameterKnob("Amplitude", node: amplitudeNode, range: 0.0...1.0)
|
||||
ParameterKnob("Pan", node: panNode, range: -1.0...1.0)
|
||||
ParameterLabel("Level", node: amplitudeNode, decimalPlaces: 2)
|
||||
}
|
||||
LyrebirdStatusView(engine: engine)
|
||||
LyrebirdScopeView(capture: scope)
|
||||
.frame(height: 120)
|
||||
LyrebirdEnvelopeView(envelope)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// SineToneUI.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
|
||||
/// A stereo sine tone whose frequency, amplitude, and pan are live-controllable
|
||||
/// from the UI. The `@UIParam` slots are the same model both the SwiftUI (macOS)
|
||||
/// and SwiftOpenUI (Linux) controls bind to — one synthesizer, two front ends.
|
||||
public final class SineToneUI: SynthesizerBase {
|
||||
|
||||
/// Frequency in Hz. Slider range: 440–880 Hz.
|
||||
@UIParam public var frequency: Double = 440.0
|
||||
|
||||
/// Output amplitude (linear gain). Knob range: 0–1.
|
||||
@UIParam public var amplitude: Double = 0.25
|
||||
|
||||
/// Stereo pan position. Knob range: -1 (hard left) … 0 (center) … +1 (hard right).
|
||||
@UIParam public var pan: Double = 0.0
|
||||
|
||||
public override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
public override func build() {
|
||||
let osc: OscSin.Audio = OscSin.Audio(freq: $frequency)
|
||||
output(bus: 0, source: Pan2(input: osc * $amplitude, pan: $pan))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// VectorOscillatorDemoView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// One platform `#if` at the import site; identical body beneath. On macOS SwiftUI
|
||||
// supplies the View DSL; on Linux `LyrebirdUI` re-exports the SwiftOpenUI DSL, so
|
||||
// `VStack` / `Text` / `.padding()` resolve on both. The Lyrebird controls
|
||||
// (`ParameterXY`, `ParameterKnob`, …) and views live in `LyrebirdUI` on every
|
||||
// platform and bind the same core `UIParamNode`s this view is handed.
|
||||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
#endif
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Live controls for ``VectorOscillatorUI``: an XY blend pad, frequency and
|
||||
/// amplitude knobs, a CPU-load strip, and an oscilloscope of the stereo output.
|
||||
///
|
||||
/// The view holds the projected `UIParamNode`s rather than the `@MainActor`
|
||||
/// synthesizer, because SwiftOpenUI's `body` is nonisolated (unlike SwiftUI's).
|
||||
/// The caller extracts the nodes on the main actor and hands them in; the nodes
|
||||
/// themselves are not actor-isolated, so a nonisolated body reads them freely.
|
||||
public struct VectorOscillatorDemoView: View {
|
||||
|
||||
let xNode: UIParamNode
|
||||
let yNode: UIParamNode
|
||||
let frequencyNode: UIParamNode
|
||||
let amplitudeNode: UIParamNode
|
||||
let scope: ScopeCapture
|
||||
let engine: SynthesisEngine
|
||||
|
||||
public init(
|
||||
xNode: UIParamNode,
|
||||
yNode: UIParamNode,
|
||||
frequencyNode: UIParamNode,
|
||||
amplitudeNode: UIParamNode,
|
||||
scope: ScopeCapture,
|
||||
engine: SynthesisEngine
|
||||
) {
|
||||
self.xNode = xNode
|
||||
self.yNode = yNode
|
||||
self.frequencyNode = frequencyNode
|
||||
self.amplitudeNode = amplitudeNode
|
||||
self.scope = scope
|
||||
self.engine = engine
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
Text("Lyrebird — Vector Oscillator")
|
||||
.font(.headline)
|
||||
ParameterXY(
|
||||
xLabel: "X (A↔B)", xNode: xNode, xRange: 0.0...1.0,
|
||||
yLabel: "Y (AB↔CD)", yNode: yNode, yRange: 0.0...1.0
|
||||
)
|
||||
.frame(width: 240, height: 240)
|
||||
HStack {
|
||||
ParameterKnob("Frequency", node: frequencyNode, range: 40.0...2000.0)
|
||||
ParameterKnob("Amplitude", node: amplitudeNode, range: 0.0...1.0)
|
||||
ParameterLabel("Freq (Hz)", node: frequencyNode, decimalPlaces: 1)
|
||||
}
|
||||
LyrebirdStatusView(engine: engine)
|
||||
LyrebirdScopeView(capture: scope)
|
||||
.frame(height: 120)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// VectorOscillatorUI.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
|
||||
/// A stereo vector oscillator whose XY position, frequency, and amplitude are
|
||||
/// live-controllable from the UI.
|
||||
///
|
||||
/// Four corner wavetables are crossfaded on a 2D XY plane:
|
||||
///
|
||||
/// C (triangle) ── D (Hanning) (y = 1)
|
||||
/// │ │
|
||||
/// A (sine) ──── B (saw-ish) (y = 0)
|
||||
/// x=0 x=1
|
||||
///
|
||||
/// Moving X blends A↔B (and C↔D); moving Y blends the AB mix into the CD mix.
|
||||
public final class VectorOscillatorUI: SynthesizerBase {
|
||||
|
||||
/// X-axis blend position. 0 = corner A/C, 1 = corner B/D. Normalized [0, 1].
|
||||
@UIParam public var x: Double = 0.5
|
||||
|
||||
/// Y-axis blend position. 0 = bottom (A, B), 1 = top (C, D). Normalized [0, 1].
|
||||
@UIParam public var y: Double = 0.5
|
||||
|
||||
/// Oscillator frequency in Hz. Slider range: 40–2000 Hz.
|
||||
@UIParam public var frequency: Double = 220.0
|
||||
|
||||
/// Output amplitude (linear gain). Knob range: 0–1.
|
||||
@UIParam public var amplitude: Double = 0.25
|
||||
|
||||
private let bufferA: LyrebirdBuffer // corner A: sine
|
||||
private let bufferB: LyrebirdBuffer // corner B: 16-partial saw-ish
|
||||
private let bufferC: LyrebirdBuffer // corner C: triangle
|
||||
private let bufferD: LyrebirdBuffer // corner D: Hanning window shape
|
||||
|
||||
public override init() {
|
||||
let tableSize: Int = lyrebirdDefaultTableSize
|
||||
|
||||
let a: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||||
a.fillSine()
|
||||
|
||||
let b: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||||
b.fill(partials: 16)
|
||||
|
||||
let c: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||||
c.fillTriangle()
|
||||
|
||||
let d: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||||
d.fillHanning()
|
||||
|
||||
self.bufferA = a
|
||||
self.bufferB = b
|
||||
self.bufferC = c
|
||||
self.bufferD = d
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
public override func build() {
|
||||
let osc: VectorOscillator.Audio = VectorOscillator.Audio(
|
||||
bufferA: bufferA,
|
||||
bufferB: bufferB,
|
||||
bufferC: bufferC,
|
||||
bufferD: bufferD,
|
||||
freq: $frequency,
|
||||
x: $x,
|
||||
y: $y,
|
||||
mul: $amplitude
|
||||
)
|
||||
output(bus: 0, source: Pan2(input: osc, pan: 0.0))
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,21 @@
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
// Output to the Desktop — triggers the NSDesktopFolderUsageDescription TCC prompt on first run.
|
||||
let outputURL = FileManager.default.homeDirectoryForCurrentUser
|
||||
// Offline render has no audio device, so this demo runs the same on macOS and Linux.
|
||||
// Only the output container differs: CAF is Apple-only (it goes through `ExtAudioFile`),
|
||||
// so off Apple we write the portable WAV codec instead.
|
||||
#if canImport(AudioToolbox)
|
||||
// Apple: CAF on the Desktop — triggers the NSDesktopFolderUsageDescription TCC prompt on first run.
|
||||
let outputURL: URL = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent("Desktop/nrt_output.caf")
|
||||
let outputFormat: AudioFileFormat = .cafFloat32
|
||||
#else
|
||||
// Linux (and any non-Apple): WAV in the current working directory — no special-folder
|
||||
// permission needed, and `WavFileWriter` is the portable encoder off Apple.
|
||||
let outputURL: URL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
|
||||
.appendingPathComponent("nrt_output.wav")
|
||||
let outputFormat: AudioFileFormat = .wavFloat32
|
||||
#endif
|
||||
|
||||
// Render parameters.
|
||||
let sampleRate: Double = 48000
|
||||
@@ -43,7 +55,7 @@ let tailDuration: Double = 0.1
|
||||
let lastStart = voices.map(\.start).max() ?? 0.0
|
||||
let totalDur = lastStart + interSetDelay + voiceLength + tailDuration
|
||||
|
||||
let driver = NRTDriver(outputURL: outputURL, duration: totalDur)
|
||||
let driver = NRTDriver(outputURL: outputURL, duration: totalDur, format: outputFormat)
|
||||
let engine = SynthesisEngine(
|
||||
blockSize: blockSize,
|
||||
sampleRate: sampleRate,
|
||||
@@ -77,7 +89,7 @@ do {
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
fputs("engine.schedule failed: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("engine.schedule failed: \(error)\n".utf8))
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@@ -87,7 +99,7 @@ do {
|
||||
try engine.start()
|
||||
print("Done.")
|
||||
} catch {
|
||||
fputs("Render failed: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("Render failed: \(error)\n".utf8))
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,15 @@ import LyrebirdSynth
|
||||
let quickstartDuration: Double = 5.0
|
||||
|
||||
do {
|
||||
// The engine owns Core Audio and runs the graph on the RT thread.
|
||||
// The engine owns the audio device and runs the graph on the RT thread.
|
||||
// `makeDefaultAudioDriver()` picks the platform backend — Core Audio on Apple,
|
||||
// ALSA on Linux (needs libasound) — so this demo builds and runs on both.
|
||||
let engine = SynthesisEngine(
|
||||
blockSize: 512,
|
||||
sampleRate: 48000,
|
||||
numOutputChannels: 2,
|
||||
numInputChannels: 0,
|
||||
driver: CoreAudioDriver()
|
||||
driver: makeDefaultAudioDriver()
|
||||
)
|
||||
|
||||
try engine.start()
|
||||
@@ -39,6 +41,6 @@ do {
|
||||
engine.stop() // closes the device
|
||||
print("Done.")
|
||||
} catch {
|
||||
fputs("Lyrebird quickstart failed to start: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("Lyrebird quickstart failed to start: \(error)\n".utf8))
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,17 @@
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
/// Directory this demo writes its output files to: the Desktop on Apple (matching the
|
||||
/// Xcode scheme), the current working directory elsewhere (Linux has no Desktop folder
|
||||
/// to grant, and `swift run` starts from a known location).
|
||||
func demoOutputDirectory() -> URL {
|
||||
#if canImport(AudioToolbox)
|
||||
return FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Desktop")
|
||||
#else
|
||||
return URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Builds a multi-part Score using every DSL node type, exports MusicXML, round-trips
|
||||
/// the document, and reports render statistics.
|
||||
///
|
||||
@@ -58,15 +69,15 @@ final class ScoreDemo: DemoProtocol {
|
||||
/// Export MusicXML and print the round-trip event count. Does not interact with
|
||||
/// the engine or schedule any voices.
|
||||
func runDemo() {
|
||||
// Step 1 — write MusicXML to Desktop.
|
||||
let xmlURL: URL = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent("Desktop/LyrebirdScoreDemo.musicxml")
|
||||
// Step 1 — write MusicXML to the demo output directory.
|
||||
let xmlURL: URL = demoOutputDirectory()
|
||||
.appendingPathComponent("LyrebirdScoreDemo.musicxml")
|
||||
let xmlString: String = score.toMusicXMLString()
|
||||
do {
|
||||
try xmlString.write(to: xmlURL, atomically: true, encoding: .utf8)
|
||||
print("MusicXML written → \(xmlURL.path)")
|
||||
} catch {
|
||||
fputs("Failed to write MusicXML: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("Failed to write MusicXML: \(error)\n".utf8))
|
||||
}
|
||||
|
||||
// Step 2 — round-trip sanity check.
|
||||
@@ -105,7 +116,7 @@ final class ScoreDemo: DemoProtocol {
|
||||
print("Score key (G major): \(rt.keySignature == .gMajor ? "OK" : "MISMATCH(\(rt.keySignature))")")
|
||||
}
|
||||
} catch {
|
||||
fputs("MusicXML round-trip failed: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("MusicXML round-trip failed: \(error)\n".utf8))
|
||||
}
|
||||
|
||||
// Step 2b — sectioned showcase: multiple Sections assembled into one
|
||||
@@ -119,8 +130,8 @@ final class ScoreDemo: DemoProtocol {
|
||||
// `rehearsalMarksAsStaffText: true` option emits boxed <words> staff text
|
||||
// instead, but that attaches to a staff and can collide with notation.
|
||||
let showcase: Score = ScoreDemo.makeSectionedShowcase()
|
||||
let showcaseURL: URL = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent("Desktop/LyrebirdScoreSections.musicxml")
|
||||
let showcaseURL: URL = demoOutputDirectory()
|
||||
.appendingPathComponent("LyrebirdScoreSections.musicxml")
|
||||
do {
|
||||
try showcase.toMusicXMLString().write(to: showcaseURL, atomically: true, encoding: .utf8)
|
||||
print("Sectioned showcase written → \(showcaseURL.path)")
|
||||
@@ -132,7 +143,7 @@ final class ScoreDemo: DemoProtocol {
|
||||
print("Sections → rehearsal marks: \(markList)")
|
||||
print("Sectioned showcase parts: \(showcase.parts.map { $0.name }.joined(separator: ", "))")
|
||||
} catch {
|
||||
fputs("Failed to write sectioned showcase: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("Failed to write sectioned showcase: \(error)\n".utf8))
|
||||
}
|
||||
|
||||
// Step 3 — report render parameters.
|
||||
@@ -185,7 +196,7 @@ final class ScoreDemo: DemoProtocol {
|
||||
try engine.schedule(voice, after: startSeconds)
|
||||
scheduledCount += 1
|
||||
} catch {
|
||||
fputs("engine.schedule failed for beat \(event.beat): \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("engine.schedule failed for beat \(event.beat): \(error)\n".utf8))
|
||||
failedCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,16 @@
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
// Output paths — both land on the Desktop.
|
||||
let cafURL: URL = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent("Desktop/LyrebirdScoreDemo.caf")
|
||||
// Audio output. CAF is Apple-only (ExtAudioFile), so off Apple we render the
|
||||
// portable WAV codec; `demoOutputDirectory()` is the Desktop on Apple and the
|
||||
// current working directory elsewhere (see ScoreDemo.swift).
|
||||
#if canImport(AudioToolbox)
|
||||
let outputFormat: AudioFileFormat = .cafFloat32
|
||||
let audioURL: URL = demoOutputDirectory().appendingPathComponent("LyrebirdScoreDemo.caf")
|
||||
#else
|
||||
let outputFormat: AudioFileFormat = .wavFloat32
|
||||
let audioURL: URL = demoOutputDirectory().appendingPathComponent("LyrebirdScoreDemo.wav")
|
||||
#endif
|
||||
|
||||
// Render parameters.
|
||||
let sampleRate: Double = 48000
|
||||
@@ -23,7 +30,7 @@ let totalDuration: Double = demo.totalDuration
|
||||
demo.runDemo()
|
||||
|
||||
// Create NRTDriver and engine.
|
||||
let driver: NRTDriver = NRTDriver(outputURL: cafURL, duration: totalDuration)
|
||||
let driver: NRTDriver = NRTDriver(outputURL: audioURL, duration: totalDuration, format: outputFormat)
|
||||
let engine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: blockSize,
|
||||
sampleRate: sampleRate,
|
||||
@@ -37,12 +44,12 @@ let engine: SynthesisEngine = SynthesisEngine(
|
||||
// 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))
|
||||
print(String(format: "Rendering %.2f s → %@", totalDuration, audioURL.path))
|
||||
|
||||
do {
|
||||
try engine.start()
|
||||
print("Done.")
|
||||
} catch {
|
||||
fputs("Render failed: \(error)\n", stderr)
|
||||
FileHandle.standardError.write(Data("Render failed: \(error)\n".utf8))
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
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>.
|
||||
The package is hosted at <https://git.lyrebirdsynth.net/josh/Lyrebird>.
|
||||
|
||||
---
|
||||
|
||||
@@ -29,7 +29,7 @@ let package = Package(
|
||||
name: "MyPiece",
|
||||
platforms: [.macOS(.v15), .iOS(.v18)],
|
||||
dependencies: [
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
+3
@@ -10,6 +10,9 @@
|
||||
<FileRef
|
||||
location = "group:Demos/LyrebirdMacOSDemo/LyrebirdMacOSDemo.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Demos/LyrebirdGUIDemo">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Demos/LyrebirdiOSDemo/LyrebirdiOSDemo.xcodeproj">
|
||||
</FileRef>
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
# Lyrebird
|
||||
|
||||
A native macOS/iOS audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles Core Audio I/O and signal graph evaluation with no heap allocation on the real-time thread.
|
||||
A native macOS, iOS, and Linux audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles platform audio I/O (Core Audio on Apple, ALSA on Linux) and signal graph evaluation with no heap allocation on the real-time thread.
|
||||
|
||||
Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a single-process architecture.
|
||||
|
||||
---
|
||||
|
||||
## Try it — run a demo
|
||||
|
||||
The fastest way in is a demo project, not a snippet to copy. Each demo under [`Demos/`](Demos/) is a standalone SwiftPM package that depends on this checkout, so `swift run` from its folder builds and runs it — on **macOS** (Xcode optional) and **Linux** (VS Code optional), no project file to open:
|
||||
|
||||
```bash
|
||||
git clone https://git.lyrebirdsynth.net/josh/Lyrebird.git
|
||||
cd Lyrebird
|
||||
|
||||
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine — the shortest path to sound
|
||||
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → an audio file, no sound device needed
|
||||
(cd Demos/LyrebirdDemo && swift run) # a fuller reverb smoke-test through your default output
|
||||
```
|
||||
|
||||
These three run the same on macOS and Linux. Each has a `Synthesizers/` folder — drop a `SynthesizerBase` subclass in, re-run, and you are building your own voice. The GUI demos (SwiftUI on macOS/iOS; the GTK4 UI on Linux) and the full list are under [Demo projects](#demo-projects).
|
||||
|
||||
On Linux the live-audio demos need `libasound2-dev`; the offline NRT demo needs nothing. Full Linux setup is in the [On Linux](#on-linux--vs-code-or-any-editor-no-xcode) notes and [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||
|
||||
---
|
||||
|
||||
## A quick taste
|
||||
|
||||
Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives Core Audio and schedules voices sample-accurately.
|
||||
Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives the platform audio backend (Core Audio on Apple, ALSA on Linux) and schedules voices sample-accurately.
|
||||
|
||||
### Generators — compose a signal graph with operators
|
||||
|
||||
@@ -128,10 +147,15 @@ The REPL is text-only and works from any project that depends on Lyrebird; the s
|
||||
|
||||
## Requirements
|
||||
|
||||
| Platform | OS | Xcode | Swift |
|
||||
| Platform | OS | IDE | Swift |
|
||||
|---|---|---|---|
|
||||
| macOS | 15+ | 16+ | 6.0 |
|
||||
| iOS | 18+ | 16+ | 6.0 |
|
||||
| macOS | 15+ | Xcode 16+ | 6.0 |
|
||||
| iOS | 18+ | Xcode 16+ | 6.0 |
|
||||
| Linux | Ubuntu 22.04+ ¹ | VS Code ² | 6.0 |
|
||||
|
||||
¹ Any swift.org-supported distribution with a Swift 6.0+ toolchain. Install `libasound2-dev` for live audio via the ALSA driver; offline/NRT rendering needs no audio device or ALSA.
|
||||
|
||||
² VS Code with the [Swift extension](https://marketplace.visualstudio.com/items?itemName=swiftlang.swift-vscode) (build/debug via SourceKit-LSP); any editor works with the `swift` CLI. Linux setup walk-through: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||
|
||||
---
|
||||
|
||||
@@ -140,7 +164,7 @@ The REPL is text-only and works from any project that depends on Lyrebird; the s
|
||||
Add the package:
|
||||
|
||||
```
|
||||
https://realizedsound.mooo.com/josh/Lyrebird.git
|
||||
https://git.lyrebirdsynth.net/josh/Lyrebird.git
|
||||
```
|
||||
|
||||
**File ▸ Add Package Dependencies…** → that URL → **Up to Next Major** from `1.0.0` → add the `Lyrebird` product (and `LyrebirdUI` for the SwiftUI controls). Write `import LyrebirdSynth` in your code (the product is `Lyrebird`; the module it vends is `LyrebirdSynth`).
|
||||
@@ -149,7 +173,24 @@ That's it — the `Lyrebird` product links **statically**, so there's no dynamic
|
||||
|
||||
Full walk-through (SPM manifest form, local-path dev dependency, per-template details): [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md). DocC version: **Getting Started ▸ Adding Lyrebird to your own Xcode project**.
|
||||
|
||||
**On Linux?** The non-UI core — engine, generators, CLI, offline render, live ALSA audio, MIDI, and OSC — builds and runs on Linux (no Xcode, no SwiftUI). Start here: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||
**On Linux (or any SwiftPM project without the Xcode UI)** — there's no "Add Package Dependencies" dialog, so declare it in `Package.swift`:
|
||||
|
||||
```swift
|
||||
dependencies: [
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "MyApp",
|
||||
dependencies: [
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
// .product(name: "LyrebirdUI", package: "Lyrebird"), // Apple-only — SwiftUI controls
|
||||
]
|
||||
),
|
||||
]
|
||||
```
|
||||
|
||||
Then `import LyrebirdSynth`. On Linux the non-UI core — engine, generators, CLI, offline render, live ALSA audio, MIDI, and OSC — builds and runs with no Xcode and no SwiftUI (`LyrebirdUI` is Apple-only; a GTK4 UI ships as a separate demo). Full setup: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||
|
||||
---
|
||||
|
||||
@@ -165,18 +206,19 @@ xed . # opens Package.swift — Xcode auto-generates schemes for every target
|
||||
|
||||
### Schemes
|
||||
|
||||
Workspace scheme selector exposes ten entries:
|
||||
Workspace scheme selector exposes eleven entries:
|
||||
|
||||
| Scheme | Purpose | Platform |
|
||||
|---|---|---|
|
||||
| `Lyrebird-Package` | Umbrella — builds Lyrebird + LyrebirdUI + LyrebirdLiveCompile + LyrebirdC + LyrebirdBenchmark + LyrebirdCLI, runs the test suites, launches/profiles `LyrebirdCLI` | macOS |
|
||||
| `LyrebirdQuickstartDemo` | CLI — fastest sound: a one-oscillator `SineTone` that plays 440 Hz for 10 s and exits | macOS |
|
||||
| `LyrebirdQuickstartDemo` | CLI — fastest sound: a one-oscillator `SineTone` that plays 440 Hz for 10 s and exits | macOS · Linux |
|
||||
| `LyrebirdUI` | Builds the `LyrebirdUI` module only (SwiftUI parameter controls + visualisations) | macOS |
|
||||
| `LyrebirdDemo` | CLI — plays through default output via `CoreAudioDriver` | macOS |
|
||||
| `LyrebirdDemo` | CLI — plays through default output via `makeDefaultAudioDriver()` | macOS · Linux |
|
||||
| `LyrebirdMacOSDemo` | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
|
||||
| `LyrebirdGUIDemo` | Cross-platform GUI — one shared source; SwiftUI here, GTK4 on Linux (`LYREBIRD_DEMO=vector`/`sine`) | macOS · Linux |
|
||||
| `LyrebirdiOSDemo` | SwiftUI app — same UI via `iOSAudioDriver` (RemoteIO) | iOS |
|
||||
| `LyrebirdNRTDemo` | CLI — offline render to CAF via `NRTDriver` | macOS |
|
||||
| `LyrebirdScoreDemo` | CLI — builds notated `Score`s (result-builder DSL), exports MusicXML, renders to CAF via `NRTDriver` | macOS |
|
||||
| `LyrebirdNRTDemo` | CLI — offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
|
||||
| `LyrebirdScoreDemo` | CLI — builds notated `Score`s (result-builder DSL), exports MusicXML, renders via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
|
||||
| `LyrebirdAUv3Demo` | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro, etc. Run the host app once to register the extension. | macOS |
|
||||
| `LyrebirdScratch` | Live-coding scratchpad — type Swift snippets, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
|
||||
|
||||
@@ -192,6 +234,35 @@ Use `Lyrebird-Package` for day-to-day development of the engine and tests.
|
||||
| Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. |
|
||||
| `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. |
|
||||
|
||||
### On Linux — VS Code or any editor (no Xcode)
|
||||
|
||||
Xcode, the `.xcworkspace`, and the schemes above are Apple-only. On Linux there's no workspace to open — point an editor at the package directory and drive it from the terminal:
|
||||
|
||||
```bash
|
||||
code --install-extension swiftlang.swift-vscode # once: the official Swift extension (SourceKit-LSP: autocomplete, jump-to-def, debug)
|
||||
code . # open the package in VS Code
|
||||
```
|
||||
|
||||
There are no schemes — run targets directly:
|
||||
|
||||
```bash
|
||||
swift build && swift test # build + run the Linux test suites
|
||||
swift run LyrebirdCLI repl # the CLI (also `new`, scaffolding, …)
|
||||
LYREBIRD_ENABLE_LINUX_UI=1 swift run LyrebirdUILinuxDemo # the GTK4 UI demo
|
||||
```
|
||||
|
||||
The CLI demo projects build and run on Linux too — each is its own package, so run it from its folder (`swift run` picks up the single executable):
|
||||
|
||||
```bash
|
||||
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → ./nrt_output.wav (no audio device needed)
|
||||
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine (needs libasound + a sound device)
|
||||
(cd Demos/LyrebirdDemo && swift run) # reverb smoke-test through default output
|
||||
(cd Demos/LyrebirdScoreDemo && swift run) # notated Score → MusicXML + a rendered WAV (no device)
|
||||
(cd Demos/LyrebirdGUIDemo && swift run) # cross-platform GUI via GTK4 (needs libgtk-4-dev); LYREBIRD_DEMO=vector|sine
|
||||
```
|
||||
|
||||
The four CLI demos plus `LyrebirdGUIDemo` (a GTK4 window here, SwiftUI on macOS) run on Linux; the AUv3 / iOS / `LyrebirdMacOSDemo` GUI demos are Apple-only. Full walk-through — toolchain, VS Code, building, running a sample: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||
|
||||
---
|
||||
|
||||
## Building and testing from the terminal
|
||||
@@ -202,23 +273,24 @@ swift test # run all 5481 tests
|
||||
swift test --filter LyrebirdTests # run one suite
|
||||
swift run lyrebird # run the CLI
|
||||
swift run lyrebird repl # Swift REPL with Lyrebird available
|
||||
swift run LyrebirdDemo # run the hardware smoke-test demo
|
||||
(cd Demos/LyrebirdDemo && swift run) # run a demo project (each Demos/* is its own package)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Demo projects
|
||||
|
||||
All eight live in [`Demos/`](Demos/). Open via `Lyrebird.xcworkspace`.
|
||||
All nine live in [`Demos/`](Demos/). Each is its own SwiftPM package depending on the local checkout, so a demo runs with `swift run` from its folder on **any** platform it supports — no Xcode needed. On macOS you can also open them together via `Lyrebird.xcworkspace`. The demos marked **Linux** build and run on Linux as well (see the Linux VS Code section above); `LyrebirdGUIDemo` is the cross-platform GUI — SwiftUI on macOS, GTK4 on Linux, one source.
|
||||
|
||||
| Demo | What it does | Platform |
|
||||
|---|---|---|
|
||||
| [`LyrebirdQuickstartDemo`](Demos/LyrebirdQuickstartDemo/) | CLI — fastest sound: a one-oscillator `SineTone` plays 440 Hz for 10 s, then exits (mirrors the `quickstart` template) | macOS |
|
||||
| [`LyrebirdDemo`](Demos/LyrebirdDemo/) | CLI — plays through default output via `CoreAudioDriver` | macOS |
|
||||
| [`LyrebirdMacOSDemo`](Demos/LyrebirdMacOSDemo/) | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
|
||||
| [`LyrebirdQuickstartDemo`](Demos/LyrebirdQuickstartDemo/) | CLI — fastest sound: a one-oscillator `SineTone` plays 440 Hz for 10 s, then exits (mirrors the `quickstart` template) | macOS · Linux |
|
||||
| [`LyrebirdDemo`](Demos/LyrebirdDemo/) | CLI — plays through default output via `makeDefaultAudioDriver()` (Core Audio on macOS, ALSA on Linux) | macOS · Linux |
|
||||
| [`LyrebirdGUIDemo`](Demos/LyrebirdGUIDemo/) | GUI — live `@UIParam` controls, XY pad, oscilloscope, CPU meters, from one shared source; AppKit/SwiftUI on macOS, GTK4/SwiftOpenUI on Linux (`LYREBIRD_DEMO=vector`/`sine`) | macOS · Linux |
|
||||
| [`LyrebirdMacOSDemo`](Demos/LyrebirdMacOSDemo/) | SwiftUI app — live oscilloscope, `@UIParam` knobs, vector / sine / spectral-bin-delay patches | macOS |
|
||||
| [`LyrebirdiOSDemo`](Demos/LyrebirdiOSDemo/) | SwiftUI app — same UI system via `iOSAudioDriver` (RemoteIO) | iOS |
|
||||
| [`LyrebirdNRTDemo`](Demos/LyrebirdNRTDemo/) | CLI — offline render to CAF file via `NRTDriver` | macOS |
|
||||
| [`LyrebirdScoreDemo`](Demos/LyrebirdScoreDemo/) | CLI — notated `Score` → MusicXML export + offline render to CAF via `NRTDriver` | macOS |
|
||||
| [`LyrebirdNRTDemo`](Demos/LyrebirdNRTDemo/) | CLI — offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
|
||||
| [`LyrebirdScoreDemo`](Demos/LyrebirdScoreDemo/) | CLI — notated `Score` → MusicXML export + offline render via `NRTDriver` (CAF on macOS, WAV on Linux) | macOS · Linux |
|
||||
| [`LyrebirdAUv3Demo`](Demos/LyrebirdAUv3Demo/) | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro | macOS |
|
||||
| [`LyrebirdScratch`](Demos/LyrebirdScratch/) | Live-coding scratchpad — type Swift, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
|
||||
|
||||
@@ -256,14 +328,10 @@ Arrow-key editing, tab completion, persistent history (`~/.lyrebird_history`). `
|
||||
|
||||
Lyrebird supports out-of-tree Swift packages that add `Generator` or `Synthesizer` implementations. Extension packages depend on Lyrebird via SwiftPM, host their own source, and ship their own version releases — core users pin the version range they want.
|
||||
|
||||
| Package | Description |
|
||||
|---|---|
|
||||
| [`LyrebirdATK`](#) | First-order Ambisonics toolkit (37 `Foa*` UGens, MIT KEMAR HRIR set, binaural decoder). Worked example for the Extension SDK. |
|
||||
|
||||
Building your own extension package:
|
||||
|
||||
- **API contract**: [`docs/protocols/extension-sdk.md`](docs/protocols/extension-sdk.md) — tier-1 stable public surface + tier-2 `@_spi(LyrebirdExtensions)` symbols and versioning policy.
|
||||
- **Walk-through**: [`docs/extension-authors-guide.md`](docs/extension-authors-guide.md) — end-to-end build a new extension package using LyrebirdATK as the reference.
|
||||
- **Walk-through**: [`docs/extension-authors-guide.md`](docs/extension-authors-guide.md) — end-to-end build a new extension package.
|
||||
|
||||
---
|
||||
|
||||
@@ -281,6 +349,7 @@ LyrebirdII/
|
||||
├── Demos/
|
||||
│ ├── LyrebirdQuickstartDemo/ # fastest sound — SineTone plays 10 s then exits
|
||||
│ ├── LyrebirdDemo/ # (same as Sources/LyrebirdDemo — workspace target)
|
||||
│ ├── LyrebirdGUIDemo/ # cross-platform GUI — SwiftUI (macOS) + GTK4 (Linux), one source
|
||||
│ ├── LyrebirdMacOSDemo/ # macOS SwiftUI app
|
||||
│ ├── LyrebirdiOSDemo/ # iOS SwiftUI app
|
||||
│ ├── LyrebirdNRTDemo/ # offline renderer
|
||||
|
||||
+72
@@ -7,6 +7,78 @@ functionality in a backward-compatible way.
|
||||
|
||||
---
|
||||
|
||||
## 2.3.0 — Edit-ended callback on continuous controls
|
||||
|
||||
A small, additive, source-compatible release. The continuous `LyrebirdUI`
|
||||
controls drive their parameter node(s) continuously while dragging, which gives
|
||||
a host no single "the user finished this edit" signal. This adds one.
|
||||
|
||||
**New — `.onEditingEnded` on the continuous controls.** `ParameterKnob`,
|
||||
`ParameterSlider`, `ParameterXY`, and `MultiSlider` gain an `.onEditingEnded`
|
||||
modifier (both the SwiftUI and the Linux/GTK4 variants) that fires **once per
|
||||
drag gesture**, reporting the value(s) at the start and end of the drag. A host
|
||||
can use it to record a single edit per gesture — an undo checkpoint, say —
|
||||
instead of one per intermediate update. The payload matches each control:
|
||||
`(previous, new)` doubles for the knob and slider, a pair of `(x, y)` tuples for
|
||||
the XY pad, and the before/after cell-value arrays for the multi-slider.
|
||||
|
||||
Additive and drop-in over 2.2.x: every control's public initializer is
|
||||
unchanged (the callback is attached by the modifier), so existing call sites and
|
||||
DocC links are unaffected. See `docs/ui/gui-system.md` for examples.
|
||||
|
||||
---
|
||||
|
||||
## 2.2.0 — Live-parameter ramp origin primed at synth add
|
||||
|
||||
A small-but-behavioral release. One fix to how `@UIParam` / `@LiveParam` values
|
||||
are delivered on a synth's first rendered block, plus the internal hook that
|
||||
backs it. The public API is source-compatible — the one new protocol member is
|
||||
internal-facing and ships with a default implementation — so this is drop-in
|
||||
over 2.1.x, but the delivery change is observable and is called out below.
|
||||
|
||||
**Fix — a parameter set before the first render is now delivered flat.** When a
|
||||
value is assigned to an `@UIParam` / `@LiveParam` *after the synth is
|
||||
constructed but before it first renders* — most commonly when restoring saved
|
||||
state onto a freshly built synth — the parameter is now delivered as a flat
|
||||
block at that value from sample 0. Previously the first rendered block ramped
|
||||
from the property-declaration default up to the assigned value over one
|
||||
(sub-)block, because the property-wrapper setter advances the atomic target but
|
||||
not the interpolation origin, which stayed at the construction-time default.
|
||||
|
||||
For most parameters that one-block (~a few ms) glide was benign. For a value
|
||||
feeding a decision stage it was not: a `Schmidt` trigger fed a threshold that
|
||||
swept up from the default would latch on the transient and, if the steady signal
|
||||
sat inside the hysteresis band, never reset — e.g. a `NoiseGate` restored from a
|
||||
saved rig would open on load and ignore its threshold. Priming the origin at add
|
||||
removes the sweep.
|
||||
|
||||
Mechanically: `SynthesizerBase`, as part of the `Mirror`-based live-parameter
|
||||
auto-registration it already runs at add time (`rebuildGraph()`, main thread,
|
||||
before the node is visible to the RT thread), now also primes each parameter's
|
||||
ramp origin to its current value via a new `LiveParameterValue._primeRampOrigin()`.
|
||||
`ParameterNode` and `UIParamNode` implement it; external conformers inherit a
|
||||
no-op default, so nothing is source-broken. A re-add (`remove` → change value →
|
||||
`add`) likewise re-primes to the then-current value.
|
||||
|
||||
**Behavior change to be aware of.** Two deliveries changed, both toward "the
|
||||
value you set before starting is the value you get":
|
||||
|
||||
- A value assigned between construction and first render is **flat** on block
|
||||
one, not a ramp from the declaration default. Code that (knowingly or not)
|
||||
relied on that opening glide will no longer see it. If you want an opening
|
||||
ramp, drive the parameter from a source/envelope or change it after start.
|
||||
- A synth removed, re-assigned while out of the tree, then re-added starts
|
||||
**flat at the new value** rather than gliding from the value it last rendered.
|
||||
|
||||
Live changes made **while the synth is running** are unchanged — they still ramp
|
||||
per (sub-)block from the last rendered value, as before. The source-slot /
|
||||
crossfade path is unaffected (the source overwrites the origin each block).
|
||||
Pinned by `LiveParamRampOriginTests` (flat delivery for `@UIParam` and
|
||||
`@LiveParam`, live-change-still-ramps, remove/change/re-add, and source-slot
|
||||
non-interference).
|
||||
|
||||
---
|
||||
|
||||
## 2.1.1 — Delay-click fix + internal consolidation
|
||||
|
||||
A patch release: one audible bug fix in the delay/comb/allpass family, plus a
|
||||
|
||||
@@ -164,7 +164,7 @@ Generated `Package.swift` uses `.package(name: "Lyrebird", path: ...)`; the `.xc
|
||||
The generated `Package.swift` depends on the Lyrebird Bitbucket repository:
|
||||
|
||||
```swift
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
```
|
||||
|
||||
If you want to work against a local checkout instead, swap to a path dependency:
|
||||
@@ -201,7 +201,7 @@ single step — no special build settings required.
|
||||
**File ▸ Add Package Dependencies…**, enter the repository URL:
|
||||
|
||||
```
|
||||
https://realizedsound.mooo.com/josh/Lyrebird.git
|
||||
https://git.lyrebirdsynth.net/josh/Lyrebird.git
|
||||
```
|
||||
|
||||
Choose **Up to Next Major Version** from `1.0.0`, then add the `Lyrebird`
|
||||
|
||||
@@ -82,6 +82,12 @@ at the end of `rebuildGraph()`. The property name (with the leading `_` of prope
|
||||
backing storage stripped) becomes the parameter key for `updateParameter` and
|
||||
``LyrebirdMessageContext/set(_:to:on:)``. No `declareParameter` call is needed.
|
||||
|
||||
Auto-registration also **primes each parameter's ramp origin** to its current value (before the
|
||||
RT thread sees the node), so a value assigned between construction and the synth's first render —
|
||||
for example restoring saved state onto a freshly built synth — is delivered **flat on the first
|
||||
block**, not as a ramp up from the property-declaration default. Changes made after the synth is
|
||||
running still ramp as usual.
|
||||
|
||||
### Block-rate vs sub-block-rate ramping
|
||||
|
||||
When `controlBlockSize == blockSize` (the engine default), the framework calls
|
||||
|
||||
@@ -245,7 +245,10 @@ Do not call `engine.remove` from within the RT callback.
|
||||
|
||||
- `parameterTable.inputs` is populated by `_autoRegisterLiveParams()` at the end of
|
||||
`rebuildGraph()` (main thread, before add) and read during `evaluate()` (RT thread,
|
||||
after add). No concurrent access.
|
||||
after add). No concurrent access. The same pass also primes each live parameter's ramp
|
||||
origin to its current value, so a value assigned before the first render (e.g. restored
|
||||
state) is delivered flat; this write is main-thread-only and precedes the add, so it never
|
||||
races the RT thread.
|
||||
- `updateParameter` issues a releasing atomic store on the projected `ParameterNode` /
|
||||
`UIParamNode`; the RT thread picks up the new value via an acquiring atomic load at the
|
||||
start of the next (sub-)block — no queue, no dictionary mutation on the RT thread.
|
||||
|
||||
@@ -34,6 +34,32 @@ public protocol LiveParameterValue: AnyObject {
|
||||
/// `UIParamNode` (`@Observable` stored property) satisfy this requirement via their
|
||||
/// existing public `value` accessor.
|
||||
var value: Double { get }
|
||||
|
||||
/// Moves the interpolation origin (`previousOutputValue`) to the current target value, so the
|
||||
/// next rendered block is a flat buffer at that value with no ramp.
|
||||
///
|
||||
/// `SynthesizerBase` calls this on every live parameter when a synth is (re-)added to the engine
|
||||
/// — on the main thread, before the RT thread sees the node. Any value assigned to the parameter
|
||||
/// **before the first render** (e.g. restoring saved state) is therefore delivered flat, while a
|
||||
/// value changed **after** the synth is running still ramps from the last rendered value.
|
||||
///
|
||||
/// Without this, assigning a parameter after construction leaves the ramp origin at the
|
||||
/// property-declaration default, so the first block ramps default → assigned. For most
|
||||
/// parameters that is a brief, benign glide; for a decision threshold feeding a `Schmidt`
|
||||
/// trigger it can latch the trigger into the wrong state.
|
||||
///
|
||||
/// - Important: NOT RT-safe — must be called from the control side only, and only while the
|
||||
/// node is not yet observed by the RT thread. It writes `previousOutputValue` (a plain
|
||||
/// `Double`) without synchronisation, which is safe because `SynthesizerBase` calls it before
|
||||
/// the add event is enqueued. A node shared with a synth that is already active must not be
|
||||
/// primed.
|
||||
func _primeRampOrigin()
|
||||
}
|
||||
|
||||
public extension LiveParameterValue {
|
||||
/// Default no-op so external conformers are not source-broken by this requirement. The two
|
||||
/// in-tree conformers (`ParameterNode`, `UIParamNode`) provide real implementations.
|
||||
func _primeRampOrigin() {}
|
||||
}
|
||||
|
||||
/// A property wrapper that backs a synthesizer parameter with a `ParameterNode`.
|
||||
|
||||
@@ -320,6 +320,12 @@ public final class ParameterNode: GeneratorBase, ControlGenerator, LiveParameter
|
||||
value = newValue
|
||||
}
|
||||
|
||||
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
|
||||
/// block is flat (no ramp). See the protocol requirement for when `SynthesizerBase` calls this.
|
||||
public func _primeRampOrigin() {
|
||||
previousOutputValue = value
|
||||
}
|
||||
|
||||
// MARK: - Init-time priming
|
||||
|
||||
/// Resets both the atomic backing and the ramp origin (`previousOutputValue`) to
|
||||
|
||||
@@ -119,6 +119,13 @@ public final class UIParamNode: GeneratorBase, ControlGenerator, LiveParameterVa
|
||||
update(newValue)
|
||||
}
|
||||
|
||||
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
|
||||
/// block is flat (no ramp). Delegates to `_node`, which owns the RT interpolation state the
|
||||
/// render thread reads. See the protocol requirement for when `SynthesizerBase` calls this.
|
||||
public func _primeRampOrigin() {
|
||||
_node._primeRampOrigin()
|
||||
}
|
||||
|
||||
// MARK: - Source property (delegates to _node)
|
||||
|
||||
/// Generator wired into this parameter slot. When non-nil, the parameter's
|
||||
|
||||
@@ -666,9 +666,13 @@ open class SynthesizerBase: Synthesizer {
|
||||
///
|
||||
/// **Value survival across re-add.** `parameterTable.inputs` is repopulated by
|
||||
/// `_autoRegisterLiveParams()` on every call, but each `@LiveParam` / `@UIParam` property
|
||||
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` —
|
||||
/// the same instance is re-registered, so its atomic value and ramp state are preserved
|
||||
/// across `engine.remove` + `engine.add` cycles.
|
||||
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` — the same
|
||||
/// instance is re-registered, so its **atomic value** is preserved across `engine.remove` +
|
||||
/// `engine.add` cycles. The **ramp origin** is not preserved: `_autoRegisterLiveParams()`
|
||||
/// re-primes it to that current value on every add (see
|
||||
/// ``LiveParameterValue/_primeRampOrigin()``), so the first block after an add is flat at the
|
||||
/// value in effect — a value assigned between construction (or a remove) and the add is
|
||||
/// delivered without a ramp, while changes made after the synth is running still ramp.
|
||||
///
|
||||
/// - Precondition: the Synthesizer must NOT currently be active in the node tree.
|
||||
/// Calling this while `evaluate()` may be running on the RT thread is a data race on
|
||||
@@ -708,7 +712,16 @@ open class SynthesizerBase: Synthesizer {
|
||||
guard let label: String = child.label else { continue }
|
||||
let key: String = label.hasPrefix("_") ? String(label.dropFirst()) : label
|
||||
if let wrapper: any LiveParameterWrapper = child.value as? LiveParameterWrapper {
|
||||
parameterTable.inputs[key] = wrapper._projectedAsValidInput
|
||||
let node: any ValidGeneratorInput = wrapper._projectedAsValidInput
|
||||
parameterTable.inputs[key] = node
|
||||
// Flatten the ramp origin to the value held right now (before the RT thread first
|
||||
// sees this node). A value assigned after construction but before the engine
|
||||
// starts — e.g. restoring saved state — is otherwise delivered as a first-block
|
||||
// ramp from the property-declaration default, which can latch a downstream
|
||||
// Schmidt/decision stage into the wrong state. Live changes after start still ramp.
|
||||
if let primeable: any LiveParameterValue = node as? LiveParameterValue {
|
||||
primeable._primeRampOrigin()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ extension ProjectScaffolder {
|
||||
|
||||
/// SPM URL Lyrebird is resolved from. Single source of truth for both
|
||||
/// the generated `Package.swift` manifest and every embedded `.xcodeproj`.
|
||||
public static let lyrebirdPackageURL: String = "https://realizedsound.mooo.com/josh/Lyrebird"
|
||||
public static let lyrebirdPackageURL: String = "https://git.lyrebirdsynth.net/josh/Lyrebird"
|
||||
|
||||
/// Lower bound on the Lyrebird version range — `upToNextMajorVersion`.
|
||||
public static let lyrebirdMinimumVersion: String = "1.0.0"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/// The current Lyrebird framework and CLI version.
|
||||
public let lyrebirdVersion: String = "2.1.1"
|
||||
public let lyrebirdVersion: String = "2.3.0"
|
||||
|
||||
/// The banner printed when the interactive shell or REPL session starts.
|
||||
public let welcomeBanner: String = """
|
||||
|
||||
@@ -43,6 +43,14 @@ public struct MultiSlider: View {
|
||||
|
||||
@State private var values: [Double]
|
||||
|
||||
/// Snapshot of `values` captured when a drag begins, so ``onEditingEnded(_:)`` can report the
|
||||
/// cells' `(previous, new)` state — a drag can paint across several columns.
|
||||
@State private var dragStartValues: [Double]?
|
||||
|
||||
/// Called once when a drag ends, with the `count` cell values before and after the drag (aligned
|
||||
/// to `startIndex`). Set via ``onEditingEnded(_:)``; lets a host record one edit per gesture.
|
||||
private var onEditingEndedAction: ((_ previous: [Double], _ new: [Double]) -> Void)?
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// - Parameters:
|
||||
@@ -112,6 +120,7 @@ public struct MultiSlider: View {
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { drag in
|
||||
if dragStartValues == nil { dragStartValues = values }
|
||||
let column: Int = Int(drag.location.x / columnWidth)
|
||||
guard column >= 0 && column < count else { return }
|
||||
let yClamped: CGFloat = min(max(drag.location.y, 0), geo.size.height)
|
||||
@@ -126,6 +135,12 @@ public struct MultiSlider: View {
|
||||
values[column] = value
|
||||
buffer.setValue(value, at: startIndex + column)
|
||||
}
|
||||
.onEnded { _ in
|
||||
if let previous: [Double] = dragStartValues {
|
||||
onEditingEndedAction?(previous, values)
|
||||
}
|
||||
dragStartValues = nil
|
||||
}
|
||||
)
|
||||
}
|
||||
.frame(height: height)
|
||||
@@ -133,6 +148,18 @@ public struct MultiSlider: View {
|
||||
Rectangle().stroke(Color.lyrebirdSeparator, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a copy that calls `action` when a drag ends — once per gesture — with the `count` cell
|
||||
/// values before and after the drag (aligned to `startIndex`). A drag may paint several columns,
|
||||
/// so both arrays are supplied for the host to diff. Matches ``ParameterKnob/onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previous, new)` cell-value arrays.
|
||||
/// - Returns: A slider row that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (_ previous: [Double], _ new: [Double]) -> Void) -> MultiSlider {
|
||||
var copy: MultiSlider = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -168,6 +195,13 @@ public struct MultiSlider: View {
|
||||
|
||||
@State private var values: [Double]
|
||||
|
||||
/// Snapshot of `values` at drag start, so ``onEditingEnded(_:)`` can report `(previous, new)`.
|
||||
@State private var dragStartValues: [Double]?
|
||||
|
||||
/// Called once when a drag ends, with the `count` cell values before and after. Set via
|
||||
/// ``onEditingEnded(_:)``; mirrors the macOS multi-slider.
|
||||
private var onEditingEndedAction: ((_ previous: [Double], _ new: [Double]) -> Void)?
|
||||
|
||||
// Fixed per-column width (points). The Apple side fills the available width
|
||||
// via GeometryReader; on Linux the Canvas needs a concrete width, so each bar
|
||||
// gets a fixed column and the row is `count × columnWidth` wide.
|
||||
@@ -243,6 +277,7 @@ public struct MultiSlider: View {
|
||||
.onDrag(
|
||||
minimumDistance: 0,
|
||||
onChanged: { (drag: DragGestureValue) in
|
||||
if dragStartValues == nil { dragStartValues = values }
|
||||
let column: Int = Int(drag.location.x / columnWidth)
|
||||
guard column >= 0 && column < count else { return }
|
||||
let hgt: Double = Double(height)
|
||||
@@ -252,8 +287,26 @@ public struct MultiSlider: View {
|
||||
let value: Double = range.lowerBound + norm * span
|
||||
values[column] = value
|
||||
buffer.setValue(value, at: startIndex + column)
|
||||
},
|
||||
onEnded: { (_: DragGestureValue) in
|
||||
if let previous: [Double] = dragStartValues {
|
||||
onEditingEndedAction?(previous, values)
|
||||
}
|
||||
dragStartValues = nil
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a copy that calls `action` when a drag ends — once per gesture — with the `count` cell
|
||||
/// values before and after (aligned to `startIndex`). Mirrors the macOS multi-slider's
|
||||
/// ``onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previous, new)` cell-value arrays.
|
||||
/// - Returns: A slider row that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (_ previous: [Double], _ new: [Double]) -> Void) -> MultiSlider {
|
||||
var copy: MultiSlider = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,11 @@ public struct ParameterKnob: View {
|
||||
/// Pixels of vertical drag that span the full parameter range. Default 200.
|
||||
public var dragSensitivity: Double = 200
|
||||
|
||||
/// Called once when a drag gesture ends, with the value at the start of the drag and the final
|
||||
/// value. Set via ``onEditingEnded(_:)``. Lets a host record a single edit per gesture (e.g. for
|
||||
/// undo) rather than one per intermediate `node.update(_:)`.
|
||||
private var onEditingEndedAction: ((Double, Double) -> Void)?
|
||||
|
||||
// MARK: - Private drag state
|
||||
|
||||
@State private var dragStartPosition: CGFloat = 0
|
||||
@@ -116,12 +121,30 @@ public struct ParameterKnob: View {
|
||||
node.update(clamped)
|
||||
}
|
||||
.onEnded { _ in
|
||||
let previousValue: Double = dragStartValue
|
||||
dragInProgress = false
|
||||
dragStartPosition = 0
|
||||
dragStartValue = 0
|
||||
onEditingEndedAction?(previousValue, node.value)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Modifiers
|
||||
|
||||
/// Returns a copy of the knob that calls `action` each time a drag gesture ends — once per
|
||||
/// gesture, not per intermediate update — with the value at the start of the drag and the final
|
||||
/// value. Use it to record a single edit (for example an undo checkpoint) when the user finishes
|
||||
/// turning the knob.
|
||||
///
|
||||
/// - Parameter action: Receives `(previousValue, newValue)` — the knob's value when the drag
|
||||
/// began and when it ended.
|
||||
/// - Returns: A knob that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (Double, Double) -> Void) -> ParameterKnob {
|
||||
var copy: ParameterKnob = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func normalise(_ value: Double) -> Double {
|
||||
@@ -173,6 +196,10 @@ public struct ParameterKnob: View {
|
||||
/// macOS knob's default.
|
||||
public var dragSensitivity: Double = 200
|
||||
|
||||
/// Called once when a drag ends, with the drag's start value and final value. Set via
|
||||
/// ``onEditingEnded(_:)``; mirrors the macOS knob so a host can record one edit per gesture.
|
||||
private var onEditingEndedAction: ((Double, Double) -> Void)?
|
||||
|
||||
// Drag origin, captured on the first `onChanged` of each gesture. An
|
||||
// explicit flag avoids a sentinel collision when the value is genuinely at
|
||||
// the range's lower bound.
|
||||
@@ -235,7 +262,9 @@ public struct ParameterKnob: View {
|
||||
node.update(target)
|
||||
},
|
||||
onEnded: { (_: DragGestureValue) in
|
||||
let previousValue: Double = dragStartValue
|
||||
dragInProgress = false
|
||||
onEditingEndedAction?(previousValue, node.value)
|
||||
}
|
||||
)
|
||||
Text(label)
|
||||
@@ -243,6 +272,17 @@ public struct ParameterKnob: View {
|
||||
.padding()
|
||||
}
|
||||
|
||||
/// Returns a copy of the knob that calls `action` each time a drag ends — once per gesture —
|
||||
/// with the drag's start value and final value. Mirrors the macOS knob's ``onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previousValue, newValue)`.
|
||||
/// - Returns: A knob that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (Double, Double) -> Void) -> ParameterKnob {
|
||||
var copy: ParameterKnob = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
private func normalise(_ value: Double) -> Double {
|
||||
let lo: Double = range.lowerBound
|
||||
let hi: Double = range.upperBound
|
||||
|
||||
@@ -35,6 +35,13 @@ public struct ParameterSlider: View {
|
||||
private let range: ClosedRange<Double>
|
||||
private let taper: Taper
|
||||
|
||||
/// Called once when a drag ends, with the value when the drag began and the final value. Set via
|
||||
/// ``onEditingEnded(_:)``; lets a host record one edit per gesture (e.g. for undo).
|
||||
private var onEditingEndedAction: ((Double, Double) -> Void)?
|
||||
|
||||
/// Value captured when a drag begins, so ``onEditingEnded(_:)`` can report `(previous, new)`.
|
||||
@State private var dragStartValue: Double = 0
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a slider bound to a `UIParamNode`.
|
||||
@@ -63,13 +70,33 @@ public struct ParameterSlider: View {
|
||||
HStack {
|
||||
Text(label)
|
||||
.frame(minWidth: 80, alignment: .leading)
|
||||
Slider(value: binding, in: linearRange) { _ in }
|
||||
Slider(value: binding, in: linearRange) { editing in
|
||||
if editing {
|
||||
dragStartValue = node.value
|
||||
} else {
|
||||
onEditingEndedAction?(dragStartValue, node.value)
|
||||
}
|
||||
}
|
||||
Text(formattedValue)
|
||||
.frame(minWidth: 60, alignment: .trailing)
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Modifiers
|
||||
|
||||
/// Returns a copy of the slider that calls `action` each time a drag ends — once per gesture —
|
||||
/// with the value when the drag began and the final value. Use it to record a single edit (for
|
||||
/// example an undo checkpoint). Matches ``ParameterKnob/onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previousValue, newValue)`.
|
||||
/// - Returns: A slider that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (Double, Double) -> Void) -> ParameterSlider {
|
||||
var copy: ParameterSlider = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: - Private helpers
|
||||
|
||||
/// Linear range always 0...1; taper mapping happens inside the Binding.
|
||||
@@ -176,6 +203,14 @@ public struct ParameterSlider: View {
|
||||
/// visible at both ends.
|
||||
private let thumbRadius: Double = 7
|
||||
|
||||
/// Called once when a drag ends, with the drag's start value and final value. Set via
|
||||
/// ``onEditingEnded(_:)``; mirrors the macOS slider.
|
||||
private var onEditingEndedAction: ((Double, Double) -> Void)?
|
||||
|
||||
// Drag origin, captured on the first `onChanged`.
|
||||
@State private var dragStartValue: Double = 0
|
||||
@State private var dragInProgress: Bool = false
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a slider bound to a `UIParamNode`.
|
||||
@@ -237,11 +272,19 @@ public struct ParameterSlider: View {
|
||||
.onDrag(
|
||||
minimumDistance: 0,
|
||||
onChanged: { (drag: DragGestureValue) in
|
||||
if !dragInProgress {
|
||||
dragInProgress = true
|
||||
dragStartValue = node.value
|
||||
}
|
||||
// Absolute: the thumb follows the pointer x within the track.
|
||||
let x0: Double = thumbRadius
|
||||
let usable: Double = max(trackWidth - 2 * thumbRadius, 1)
|
||||
let pos: Double = min(1, max(0, (drag.location.x - x0) / usable))
|
||||
node.update(fromLinear(pos))
|
||||
},
|
||||
onEnded: { (_: DragGestureValue) in
|
||||
dragInProgress = false
|
||||
onEditingEndedAction?(dragStartValue, node.value)
|
||||
}
|
||||
)
|
||||
Text(formattedValue)
|
||||
@@ -250,6 +293,17 @@ public struct ParameterSlider: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a copy of the slider that calls `action` each time a drag ends — once per gesture —
|
||||
/// with the drag's start value and final value. Mirrors the macOS slider's ``onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previousValue, newValue)`.
|
||||
/// - Returns: A slider that reports the end of each edit.
|
||||
public func onEditingEnded(_ action: @escaping (Double, Double) -> Void) -> ParameterSlider {
|
||||
var copy: ParameterSlider = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: - Private helpers
|
||||
|
||||
private func toLinear(_ value: Double) -> Double {
|
||||
|
||||
@@ -31,6 +31,15 @@ public struct ParameterXY: View {
|
||||
private let yNode: UIParamNode
|
||||
private let yRange: ClosedRange<Double>
|
||||
|
||||
/// Called once when a drag ends, with the `(x, y)` values when the drag began and when it ended.
|
||||
/// Set via ``onEditingEnded(_:)``; lets a host record one edit per gesture across both axes.
|
||||
private var onEditingEndedAction: ((_ previous: (x: Double, y: Double), _ new: (x: Double, y: Double)) -> Void)?
|
||||
|
||||
// Both nodes' values captured when a drag begins.
|
||||
@State private var dragStartX: Double = 0
|
||||
@State private var dragStartY: Double = 0
|
||||
@State private var dragInProgress: Bool = false
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates an XY pad bound to two `UIParamNode` values.
|
||||
@@ -59,6 +68,20 @@ public struct ParameterXY: View {
|
||||
self.yRange = yRange
|
||||
}
|
||||
|
||||
/// Returns a copy of the pad that calls `action` each time a drag ends — once per gesture — with
|
||||
/// the `(x, y)` values when the drag began and when it ended. Use it to record a single
|
||||
/// two-axis edit (for example an undo checkpoint). Matches ``ParameterKnob/onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previous, new)`, each an `(x, y)` value pair.
|
||||
/// - Returns: A pad that reports the end of each edit.
|
||||
public func onEditingEnded(
|
||||
_ action: @escaping (_ previous: (x: Double, y: Double), _ new: (x: Double, y: Double)) -> Void
|
||||
) -> ParameterXY {
|
||||
var copy: ParameterXY = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
@@ -134,11 +157,20 @@ public struct ParameterXY: View {
|
||||
private func dragGesture(in size: CGSize) -> some Gesture {
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { gesture in
|
||||
if !dragInProgress {
|
||||
dragInProgress = true
|
||||
dragStartX = xNode.value
|
||||
dragStartY = yNode.value
|
||||
}
|
||||
let nx: CGFloat = min(max(gesture.location.x / size.width, 0), 1)
|
||||
let ny: CGFloat = min(max(gesture.location.y / size.height, 0), 1)
|
||||
xNode.update(denormalise(nx, range: xRange))
|
||||
yNode.update(denormalise(1.0 - ny, range: yRange)) // flip Y
|
||||
}
|
||||
.onEnded { _ in
|
||||
dragInProgress = false
|
||||
onEditingEndedAction?((x: dragStartX, y: dragStartY), (x: xNode.value, y: yNode.value))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
@@ -203,6 +235,14 @@ public struct ParameterXY: View {
|
||||
private let padSize: Double = 160
|
||||
private let cursorRadius: Double = 6
|
||||
|
||||
/// Called once when a drag ends, with the `(x, y)` values at the drag's start and end. Set via
|
||||
/// ``onEditingEnded(_:)``; mirrors the macOS pad.
|
||||
private var onEditingEndedAction: ((_ previous: (x: Double, y: Double), _ new: (x: Double, y: Double)) -> Void)?
|
||||
|
||||
@State private var dragStartX: Double = 0
|
||||
@State private var dragStartY: Double = 0
|
||||
@State private var dragInProgress: Bool = false
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates an XY pad bound to two `UIParamNode` values.
|
||||
@@ -274,11 +314,20 @@ public struct ParameterXY: View {
|
||||
.onDrag(
|
||||
minimumDistance: 0,
|
||||
onChanged: { (drag: DragGestureValue) in
|
||||
if !dragInProgress {
|
||||
dragInProgress = true
|
||||
dragStartX = xNode.value
|
||||
dragStartY = yNode.value
|
||||
}
|
||||
// Absolute position: the touch point is the cursor.
|
||||
let nx: Double = min(max(drag.location.x / padSize, 0), 1)
|
||||
let ny: Double = min(max(drag.location.y / padSize, 0), 1)
|
||||
xNode.update(denormalise(nx, range: xRange))
|
||||
yNode.update(denormalise(1.0 - ny, range: yRange)) // flip Y
|
||||
},
|
||||
onEnded: { (_: DragGestureValue) in
|
||||
dragInProgress = false
|
||||
onEditingEndedAction?((x: dragStartX, y: dragStartY), (x: xNode.value, y: yNode.value))
|
||||
}
|
||||
)
|
||||
Text("\(xLabel): \(formattedParameterValue(xNode.value))")
|
||||
@@ -289,6 +338,19 @@ public struct ParameterXY: View {
|
||||
.padding()
|
||||
}
|
||||
|
||||
/// Returns a copy of the pad that calls `action` each time a drag ends — once per gesture — with
|
||||
/// the `(x, y)` values at the drag's start and end. Mirrors the macOS pad's ``onEditingEnded(_:)``.
|
||||
///
|
||||
/// - Parameter action: Receives `(previous, new)`, each an `(x, y)` value pair.
|
||||
/// - Returns: A pad that reports the end of each edit.
|
||||
public func onEditingEnded(
|
||||
_ action: @escaping (_ previous: (x: Double, y: Double), _ new: (x: Double, y: Double)) -> Void
|
||||
) -> ParameterXY {
|
||||
var copy: ParameterXY = self
|
||||
copy.onEditingEndedAction = action
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func normalise(
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
// LiveParamRampOriginTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
/// A synth whose only output is a `@UIParam` written straight to a bus, so a rendered block
|
||||
/// reveals the parameter's delivered ramp. Declaration default `0.1`.
|
||||
@MainActor
|
||||
private final class UIParamProbe: SynthesizerBase {
|
||||
@UIParam var p: Double = 0.1
|
||||
let bus: Int
|
||||
init(bus: Int = 0) { self.bus = bus; super.init() }
|
||||
override func build() {
|
||||
output(bus: bus, source: $p)
|
||||
}
|
||||
}
|
||||
|
||||
/// Same, but backed by `@LiveParam` (`ParameterNode`) — a separate priming code path from
|
||||
/// `@UIParam`'s `UIParamNode` delegation.
|
||||
@MainActor
|
||||
private final class LiveParamProbe: SynthesizerBase {
|
||||
@LiveParam var p: Double = 0.1
|
||||
let bus: Int
|
||||
init(bus: Int = 0) { self.bus = bus; super.init() }
|
||||
override func build() {
|
||||
output(bus: bus, source: $p)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Suite("Live parameter ramp origin")
|
||||
struct LiveParamRampOriginTests {
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 16)
|
||||
|
||||
init() throws {
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func uiParamAssignedAfterConstructionIsDeliveredFlat() throws {
|
||||
// Assign AFTER construction (declaration default 0.1) but BEFORE the first render. Without
|
||||
// priming at add time the first block would ramp 0.1 → 0.9; the fix primes the ramp origin
|
||||
// when the synth is added, so the block is flat at 0.9 from sample 0.
|
||||
let probe: UIParamProbe = UIParamProbe(bus: 0)
|
||||
probe.p = 0.9
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: [])
|
||||
for i: Int in 0..<engine.blockSize {
|
||||
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||
"sample \(i) should be flat 0.9, not a ramp from the 0.1 default")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func liveParamAssignedAfterConstructionIsDeliveredFlat() throws {
|
||||
// Same guarantee for @LiveParam (ParameterNode direct, no UIParamNode delegation).
|
||||
let probe: LiveParamProbe = LiveParamProbe(bus: 0)
|
||||
probe.p = 0.9
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: [])
|
||||
for i: Int in 0..<engine.blockSize {
|
||||
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||
"@LiveParam sample \(i) should be flat 0.9, not a ramp from the 0.1 default")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func valueChangedWhileRunningStillRamps() throws {
|
||||
// A change made while the synth is running must still ramp from the last rendered value —
|
||||
// the fix must not flatten live updates, only prime the pre-first-render origin.
|
||||
let probe: UIParamProbe = UIParamProbe(bus: 0) // starts at 0.1
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: []) // render a block, origin settles at 0.1
|
||||
#expect(abs(engine.audioBuses[0][0] - 0.1) < 1e-6, "first block should be flat 0.1")
|
||||
|
||||
probe.p = 0.9 // live change → next block ramps
|
||||
engine.processBlock(inputSamples: [])
|
||||
let first: Float = engine.audioBuses[0][0]
|
||||
let last: Float = engine.audioBuses[0][engine.blockSize - 1]
|
||||
#expect(first < 0.9, "live change should ramp (first sample below target), got \(first)")
|
||||
#expect(abs(last - 0.9) < 1e-5, "ramp should reach the target by block end, got \(last)")
|
||||
}
|
||||
|
||||
@Test func valueChangedWhileRemovedIsDeliveredFlatOnReAdd() throws {
|
||||
// Add, render, remove, change the value while out of the tree, then re-add. The re-add
|
||||
// re-primes the origin to the new value, so the first block after re-add is flat at 0.9
|
||||
// (no glide up from the 0.1 it last rendered). Pins the "re-add re-primes" behaviour that
|
||||
// the rebuildGraph doc describes.
|
||||
let probe: UIParamProbe = UIParamProbe(bus: 0) // 0.1
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: []) // renders 0.1, origin now 0.1
|
||||
_ = engine.remove(probe)
|
||||
engine.processBlock(inputSamples: []) // the documented one block between remove and re-add
|
||||
|
||||
probe.p = 0.9 // changed while removed
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: [])
|
||||
for i: Int in 0..<engine.blockSize {
|
||||
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||
"re-added synth sample \(i) should be flat 0.9, not a ramp from 0.1")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func sourceSlotSetBeforeAddIsUnaffectedByPriming() throws {
|
||||
// With a generator wired into the parameter's source slot before add, the source output
|
||||
// drives the block — priming the scalar ramp origin must not interfere. The source holds a
|
||||
// constant 0.7, so the output is ~0.7 regardless of the 0.1 scalar default / 0.9 scalar set.
|
||||
let probe: UIParamProbe = UIParamProbe(bus: 0)
|
||||
probe.p = 0.9 // scalar value (should be overridden by source)
|
||||
let constantSource: ParameterNode = ParameterNode(0.7)
|
||||
probe.$p.source = constantSource
|
||||
try engine.add(probe)
|
||||
engine.processBlock(inputSamples: [])
|
||||
let last: Float = engine.audioBuses[0][engine.blockSize - 1]
|
||||
#expect(abs(last - 0.7) < 1e-5,
|
||||
"source-slot output should be ~0.7, not the scalar value, got \(last)")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// OnEditingEndedTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable import LyrebirdUI
|
||||
import LyrebirdSynth
|
||||
|
||||
/// Coverage for the `.onEditingEnded` edit-reporting modifier on the continuous controls.
|
||||
///
|
||||
/// A SwiftUI gesture can't be driven from a unit test (same limitation noted in
|
||||
/// ``MultiSliderTests``), so these are structural smokes: they construct each control, attach
|
||||
/// `.onEditingEnded` with that control's payload shape, and confirm the builder returns a usable
|
||||
/// value of the same concrete type. Their real job is to **lock the public API** — the per-control
|
||||
/// closure signatures — so a later signature change breaks the build here rather than silently at a
|
||||
/// call site. The gesture → `(previous, new)` firing itself is covered by the control's own drag
|
||||
/// handler and is exercised in app use, not here.
|
||||
@MainActor
|
||||
@Suite("onEditingEnded")
|
||||
struct OnEditingEndedTests {
|
||||
|
||||
@Test func knobBuilderCarriesTheAction() {
|
||||
let node: UIParamNode = UIParamNode(0.5)
|
||||
var reported: (Double, Double)?
|
||||
let knob: ParameterKnob = ParameterKnob("Cutoff", node: node, range: 0...1)
|
||||
.onEditingEnded { previous, new in reported = (previous, new) }
|
||||
_ = knob
|
||||
// The closure has not been invoked (no gesture), so nothing is reported yet.
|
||||
#expect(reported == nil)
|
||||
}
|
||||
|
||||
@Test func sliderBuilderCarriesTheAction() {
|
||||
let node: UIParamNode = UIParamNode(0.25)
|
||||
let slider: ParameterSlider = ParameterSlider("Amp", node: node, range: 0...1)
|
||||
.onEditingEnded { _, _ in }
|
||||
_ = slider
|
||||
}
|
||||
|
||||
@Test func xyBuilderCarriesTheAction() {
|
||||
let xNode: UIParamNode = UIParamNode(0.0)
|
||||
let yNode: UIParamNode = UIParamNode(0.0)
|
||||
let pad: ParameterXY = ParameterXY(
|
||||
xLabel: "Pan", xNode: xNode, xRange: -1...1,
|
||||
yLabel: "Amp", yNode: yNode, yRange: 0...1
|
||||
)
|
||||
.onEditingEnded { previous, new in
|
||||
// Payload is a pair of (x, y) tuples — reference the members so a shape change breaks here.
|
||||
_ = (previous.x, previous.y, new.x, new.y)
|
||||
}
|
||||
_ = pad
|
||||
}
|
||||
|
||||
@Test func multiSliderBuilderCarriesTheAction() {
|
||||
let buffer: LyrebirdBuffer = LyrebirdBuffer(count: 8)
|
||||
buffer.fill(with: 0.3)
|
||||
let bars: MultiSlider = MultiSlider(buffer: buffer, count: 4, range: 0...1)
|
||||
.onEditingEnded { previous, new in
|
||||
// Payload is the cell-value arrays before / after the drag.
|
||||
_ = (previous.count, new.count)
|
||||
}
|
||||
_ = bars
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,11 @@ EXCLUSIONS=(
|
||||
)
|
||||
|
||||
# Regex the release repo's origin URL must match — a guard so --apply can never
|
||||
# nuke the wrong directory. Requires the mooo host AND the `Lyrebird` repo path
|
||||
# (so a sibling mooo repo like ShoeGaze can't be mistaken for the release repo).
|
||||
RELEASE_REMOTE_REGEX='realizedsound\.mooo\.com.*/Lyrebird(\.git)?/?$'
|
||||
# nuke the wrong directory. Requires the gitea host AND the `Lyrebird` repo path
|
||||
# (so a sibling repo like ShoeGaze can't be mistaken for the release repo).
|
||||
# Accepts both the canonical host (git.lyrebirdsynth.net) and its legacy alias
|
||||
# (realizedsound.mooo.com) — a DNS CNAME to the same gitea server.
|
||||
RELEASE_REMOTE_REGEX='(git\.lyrebirdsynth\.net|realizedsound\.mooo\.com).*/Lyrebird(\.git)?/?$'
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
@@ -66,7 +68,7 @@ fail() { echo "ERROR: $*" >&2; exit 1; }
|
||||
|
||||
RELEASE_URL="$(git -C "$RELEASE" remote get-url origin 2>/dev/null || echo "")"
|
||||
if [[ ! "$RELEASE_URL" =~ $RELEASE_REMOTE_REGEX ]]; then
|
||||
fail "release origin ('$RELEASE_URL') is not the Lyrebird mooo release repo (must match /$RELEASE_REMOTE_REGEX/) — refusing to sync. Wrong --release path?"
|
||||
fail "release origin ('$RELEASE_URL') is not the Lyrebird gitea release repo (must match /$RELEASE_REMOTE_REGEX/) — refusing to sync. Wrong --release path?"
|
||||
fi
|
||||
|
||||
# --- Guard: dev working tree should be committed (we archive HEAD) -----------
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
---
|
||||
name: lyrebird_release_prep
|
||||
description: Prepare the public LyrebirdRelease (mooo) repo from the Lyrebird dev repo, replacing the manual "export → hand-copy in Finder" step. Syncs the dev repo's committed tree into the release working tree, excluding maintainer-only paths that never ship (legacy/, PLAN.md, .claude/, .githooks/, .swiftpm/) and cleaning accumulated Finder duplicate cruft. Dry-run first, then apply, then guides commit + tag + push to mooo. Use when cutting a new Lyrebird release (e.g. bumping to a new vX.Y.Z tag).
|
||||
description: Prepare the public LyrebirdRelease repo from the Lyrebird dev repo, replacing the manual "export → hand-copy in Finder" step. Syncs the dev repo's committed tree into the release working tree, excluding maintainer-only paths that never ship (legacy/, PLAN.md, .claude/, .githooks/, .swiftpm/) and cleaning accumulated Finder duplicate cruft. Dry-run first, then apply, then guides commit + tag + push to the gitea host. Use when cutting a new Lyrebird release (e.g. bumping to a new vX.Y.Z tag), and read it before ANY `git push` in Lyrebird, LyrebirdRelease or ShoeGaze: it records which remote is the private working repo (Bitbucket) and which is public (git.lyrebirdsynth.net, formerly realizedsound.mooo.com).
|
||||
---
|
||||
|
||||
# Lyrebird Release Prep
|
||||
|
||||
Replicates the Lyrebird **dev** repo (`~/Documents/src/Lyrebird`, origin = bitbucket) into
|
||||
the public **release** repo (`~/Documents/src/LyrebirdRelease`, origin = `realizedsound.mooo.com`)
|
||||
that SwiftPM consumers resolve from — without the manual Finder export/hand-copy.
|
||||
the public **release** repo (`~/Documents/src/LyrebirdRelease`, origin = `git.lyrebirdsynth.net`,
|
||||
formerly `realizedsound.mooo.com` — a CNAME to the same server) that SwiftPM consumers
|
||||
resolve from — without the manual Finder export/hand-copy.
|
||||
|
||||
## Remotes: where each repo pushes (read before any `git push`)
|
||||
|
||||
Two kinds of remote, with different rules:
|
||||
|
||||
| Repo | Local path | `origin` | Role |
|
||||
|---|---|---|---|
|
||||
| **Lyrebird** (dev) | `~/Documents/src/Lyrebird` | `git@bitbucket.org:realizedsound/lyrebird.git` | **Working repo, Bitbucket.** Private. Day-to-day commits, branches and WIP, including the maintainer-only paths listed below. Push here freely as work progresses. |
|
||||
| **LyrebirdRelease** | `~/Documents/src/LyrebirdRelease` | `ssh://git@git.lyrebirdsynth.net:2222/josh/Lyrebird.git` | **Public gitea.** Every commit and tag pushed here is publicly visible, and SwiftPM consumers resolve from it. Only ever updated through this skill (sync, commit, tag, push), at release time. |
|
||||
| **ShoeGaze** | `~/Documents/src/ShoeGaze` | `https://git.lyrebirdsynth.net/josh/ShoeGaze/` | **Public gitea.** No Bitbucket remote, so a push here is public. It depends on a published Lyrebird tag. |
|
||||
|
||||
The public gitea host is `git.lyrebirdsynth.net` (a DNS CNAME to `realizedsound.mooo.com`, the
|
||||
former hostname — both resolve to the same server, so old `mooo` URLs still work). "gitea" below
|
||||
means that public host.
|
||||
|
||||
Rules:
|
||||
1. **Bitbucket = working directory, gitea = public releases and commits.** Never push the dev repo
|
||||
to gitea, and never push maintainer-only files (`legacy/`, `PLAN.md`, `DOC_UPDATE_PLAN.md`,
|
||||
the two phase-planning docs, `.claude/`, `.githooks/`) or anything private to a public remote.
|
||||
2. Before anything goes to gitea, read the commit list and the file list as if a stranger will:
|
||||
no secrets, no private notes, no personal paths.
|
||||
3. Claude prepares (dry run, apply, commit message, tag), then **the maintainer runs the push**
|
||||
(it needs his key/touch). Claude does not push to gitea on its own.
|
||||
4. A ShoeGaze push to gitea is public too: confirm it builds against the tagged Lyrebird release
|
||||
it declares, not a local `swift package edit` override.
|
||||
|
||||
The gitea server (noted 2026-10-23): Gitea running in Docker on the Mac mini, reached at
|
||||
`git.lyrebirdsynth.net` (CNAME to `realizedsound.mooo.com`). It is written in Go, so the PHP2Shell
|
||||
vulnerability does not apply to it, but it is internet-facing: keep Gitea and the Docker host
|
||||
updated. If it is slow or unreachable (it intermittently was on 2026-10-23), check the Mac mini
|
||||
before suspecting the repo.
|
||||
|
||||
## What it does (and why it's safe)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ defined promotion path between them.
|
||||
| Remote | Role | Cadence |
|
||||
|---|---|---|
|
||||
| **Bitbucket** (`origin`) | Active development — fine-grained commits, experiments, in-progress branches, frequent pushes. | Continuous. Whatever your working rhythm is. |
|
||||
| **Gitea** (`realizedsound.mooo.com/josh/Lyrebird`) | Release / distribution — the repo external consumers pull as a SwiftPM dependency. | Deliberate. Only when a coherent set of features is ready. |
|
||||
| **Gitea** (`git.lyrebirdsynth.net/josh/Lyrebird`) | Release / distribution — the repo external consumers pull as a SwiftPM dependency. | Deliberate. Only when a coherent set of features is ready. |
|
||||
|
||||
The two are **not** mirrors. Bitbucket holds the full granular history; Gitea
|
||||
receives **consolidated** promotions when a feature set is release-ready.
|
||||
|
||||
@@ -78,7 +78,7 @@ let package = Package(
|
||||
// Pin tightly to the Lyrebird MINOR range — @_spi(LyrebirdExtensions)
|
||||
// symbols are documented as MINOR-mutable.
|
||||
.package(
|
||||
url: "https://realizedsound.mooo.com/josh/Lyrebird.git",
|
||||
url: "https://git.lyrebirdsynth.net/josh/Lyrebird.git",
|
||||
"0.9.1" ..< "1.0.0"
|
||||
),
|
||||
],
|
||||
@@ -112,7 +112,7 @@ If you are pulling Lyrebird from a private repository, use the SSH URL form:
|
||||
|
||||
```swift
|
||||
.package(
|
||||
url: "git@realizedsound.mooo.com:josh/Lyrebird.git",
|
||||
url: "git@git.lyrebirdsynth.net:josh/Lyrebird.git",
|
||||
"0.9.1" ..< "1.0.0"
|
||||
)
|
||||
```
|
||||
|
||||
@@ -42,7 +42,7 @@ let package = Package(
|
||||
platforms: [.macOS(.v15)],
|
||||
dependencies: [
|
||||
// Lyrebird, fetched from its git host:
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -124,6 +124,35 @@ swift run # a 440 Hz sine for a few seconds
|
||||
built with `LYREBIRD_DISABLE_ALSA=1`), in which case `makeDefaultAudioDriver()`
|
||||
returns a silent `OfflineDriver`.
|
||||
|
||||
### The bundled CLI demos
|
||||
|
||||
The scaffold templates above make a *new* project. To run the demos that ship in
|
||||
this repo instead, each lives in its own package under `Demos/` and runs with
|
||||
`swift run` from its folder — the same source as the macOS Xcode schemes:
|
||||
|
||||
```bash
|
||||
(cd Demos/LyrebirdNRTDemo && swift run) # offline render → ./nrt_output.wav (no audio device)
|
||||
(cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine (needs libasound + a device)
|
||||
(cd Demos/LyrebirdDemo && swift run) # reverb smoke-test through the default output
|
||||
(cd Demos/LyrebirdScoreDemo && swift run) # notated Score → MusicXML + a rendered WAV (no device)
|
||||
```
|
||||
|
||||
`LyrebirdNRTDemo` and `LyrebirdScoreDemo` write a WAV off Apple (CAF is Apple-only)
|
||||
into the current directory; the live demos use `makeDefaultAudioDriver()` →
|
||||
`ALSAAudioDriver`.
|
||||
|
||||
There is also a cross-platform **GUI** demo — `Demos/LyrebirdGUIDemo` — whose synths
|
||||
and views are one shared source that bootstraps SwiftUI on macOS and GTK4 on Linux.
|
||||
It needs `libgtk-4-dev` + `libgtksourceview-5-dev` (and `libasound2-dev` + a device
|
||||
for sound):
|
||||
|
||||
```bash
|
||||
(cd Demos/LyrebirdGUIDemo && swift run) # vector oscillator (default)
|
||||
(cd Demos/LyrebirdGUIDemo && LYREBIRD_DEMO=sine swift run) # stereo sine tone
|
||||
```
|
||||
|
||||
The AUv3 / iOS / `LyrebirdMacOSDemo` GUI demos are Apple-only.
|
||||
|
||||
### REPL and live coding
|
||||
|
||||
```bash
|
||||
|
||||
@@ -68,7 +68,7 @@ Each Xcode-project template lays out:
|
||||
└── ...
|
||||
```
|
||||
|
||||
Lyrebird is pulled in via a remote SPM dependency on `https://realizedsound.mooo.com/josh/Lyrebird` (configurable via `ProjectScaffolder.lyrebirdPackageURL`). The scaffolded project lives anywhere on disk and does not need a local checkout.
|
||||
Lyrebird is pulled in via a remote SPM dependency on `https://git.lyrebirdsynth.net/josh/Lyrebird` (configurable via `ProjectScaffolder.lyrebirdPackageURL`). The scaffolded project lives anywhere on disk and does not need a local checkout.
|
||||
|
||||
### Distribution & microphone input
|
||||
|
||||
@@ -117,7 +117,7 @@ let package = Package(
|
||||
name: "MyPiece",
|
||||
platforms: [.macOS(.v15)],
|
||||
dependencies: [
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -177,7 +177,7 @@ Open `MyPiece/Package.swift` and update the placeholder URL to the published
|
||||
Lyrebird repository:
|
||||
|
||||
```swift
|
||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||
.package(url: "https://git.lyrebirdsynth.net/josh/Lyrebird", from: "1.0.0"),
|
||||
```
|
||||
|
||||
Resolve the dependency graph:
|
||||
|
||||
@@ -189,6 +189,34 @@ ParameterLabel("Level", node: synth.$amplitude)
|
||||
ParameterLabel("Freq (Hz)", node: synth.$frequency, decimalPlaces: 1)
|
||||
```
|
||||
|
||||
### Reporting the end of an edit (`onEditingEnded`)
|
||||
|
||||
The continuous controls — `ParameterKnob`, `ParameterSlider`, `ParameterXY`, and `MultiSlider` —
|
||||
drive their node(s) continuously while dragging. Attach `.onEditingEnded` to be told **once per
|
||||
drag gesture**, with the value(s) at the start and end of the drag, so a host can record a single
|
||||
edit (an undo checkpoint, say) instead of one per intermediate update:
|
||||
|
||||
```swift
|
||||
ParameterKnob("Cutoff", node: synth.$cutoff, range: 20...20000)
|
||||
.onEditingEnded { previous, new in
|
||||
undo.record(previous, new) // called once, when the drag ends
|
||||
}
|
||||
```
|
||||
|
||||
The payload differs per control:
|
||||
|
||||
| Control | `onEditingEnded` closure |
|
||||
|---|---|
|
||||
| `ParameterKnob` / `ParameterSlider` | `(previous: Double, new: Double)` |
|
||||
| `ParameterXY` | `(previous: (x: Double, y: Double), new: (x: Double, y: Double))` — one gesture drives both nodes |
|
||||
| `MultiSlider` | `(previous: [Double], new: [Double])` — the `count` cell values before/after (a drag can paint several bars) |
|
||||
|
||||
Notes:
|
||||
- It fires once per gesture **even when the value didn't net-change** (e.g. a `MultiSlider` tap on an
|
||||
unchanged bar). Filter on `previous == new` if your host wants to skip no-op edits.
|
||||
- `ParameterSlider` (the SwiftUI variant) rides the native `Slider`'s editing-changed signal, so it
|
||||
also fires for keyboard / accessibility adjustments, not only pointer drags.
|
||||
|
||||
### LyrebirdStatusView
|
||||
|
||||
Compact engine status display showing average and peak CPU load. Polls the engine at 10 Hz;
|
||||
|
||||
Reference in New Issue
Block a user