v2.4.1 release: scratchpad polish + demo cleanup
Maintenance release, no framework API changes. Scratchpad: Kill All Sound (⌘K) rename, mode-switch desync fix, code-completion prefix filtering restored (⌃Space Show Completions). Demos: GUIDemo voices + CLI EventPattern BlipVoice moved into Synthesizers/, EventPattern demo split into makeLead/makeBass, GUIDemo doc drift fixed (conductor default). LyrebirdScratch gains a SwiftPM package so the workspace shows it like GUIDemo (.xcodeproj kept for distribution). Linux live-coding scratchpad documented.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
C1A000000000000000000013 /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C1A000000000000000000012 /* Lyrebird */; };
|
||||
C1A000000000000000000016 /* SineTone.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A000000000000000000014 /* SineTone.swift */; };
|
||||
C1A000000000000000000017 /* DelaySample.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A000000000000000000015 /* DelaySample.swift */; };
|
||||
C1A00000000000000000001B /* BlipVoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A00000000000000000001A /* BlipVoice.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -40,6 +41,7 @@
|
||||
C1A000000000000000000006 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
C1A000000000000000000014 /* SineTone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SineTone.swift; sourceTree = "<group>"; };
|
||||
C1A000000000000000000015 /* DelaySample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelaySample.swift; sourceTree = "<group>"; };
|
||||
C1A00000000000000000001A /* BlipVoice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlipVoice.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -95,6 +97,7 @@
|
||||
035B00092FAB0000007F0001 /* General */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C1A00000000000000000001A /* BlipVoice.swift */,
|
||||
C1A000000000000000000015 /* DelaySample.swift */,
|
||||
C1A000000000000000000014 /* SineTone.swift */,
|
||||
);
|
||||
@@ -216,6 +219,7 @@
|
||||
C1A000000000000000000016 /* SineTone.swift in Sources */,
|
||||
035A2F472FAA6950007F6289 /* PercTimeStretch.swift in Sources */,
|
||||
C1A000000000000000000017 /* DelaySample.swift in Sources */,
|
||||
C1A00000000000000000001B /* BlipVoice.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
/// Demonstrates ``EventPattern`` — Lyrebird's event-driven player: bound value patterns drive a
|
||||
/// fresh self-freeing voice per event, played as a dur/legato-timed stream.
|
||||
/// fresh self-freeing ``BlipVoice`` per event, played as a dur/legato-timed stream.
|
||||
///
|
||||
/// Also shows two patterns running together via ``ParallelEventPattern``: a lead phrase and a
|
||||
/// bass line that enters a few beats in on the same beat grid, with a single
|
||||
@@ -17,87 +17,55 @@ import LyrebirdSynth
|
||||
final class EventPatternDemo: DemoProtocol {
|
||||
|
||||
private let engine: SynthesisEngine
|
||||
private let tempoBPM: Double = 132.0
|
||||
|
||||
/// Beats the bass waits before its first note. Shared tempo means both parts share a beat
|
||||
/// grid, so this is a plain offset on that grid.
|
||||
private let leadInBeats: Double = 2.0
|
||||
|
||||
init(engine: SynthesisEngine) {
|
||||
self.engine = engine
|
||||
}
|
||||
|
||||
/// A gated voice (``EventGated``): a sine through an `EnvelopeGen` whose gate holds it at full
|
||||
/// level while the note sounds, then plays a release and frees the voice via
|
||||
/// `doneAction: .freeNode` when `EventPattern` closes the gate at the note's sustain. No
|
||||
/// external removal, so the release is never hard-cut — nothing to tune, no click.
|
||||
private final class BlipVoice: SynthesizerBase, EventGated {
|
||||
/// Envelope release length in seconds — how long a note rings after its gate closes.
|
||||
/// Exposed so the demo can let the final note's tail finish before stopping the engine.
|
||||
nonisolated static let releaseSeconds: Double = 0.3
|
||||
/// Envelope attack length in seconds.
|
||||
nonisolated static let attackSeconds: Double = 0.01
|
||||
|
||||
@LiveParam var freq: Double = 440.0
|
||||
@LiveParam var amp: Double = 0.2
|
||||
@LiveParam var gate: Double = 1.0 // open by default so the attack fires on add
|
||||
|
||||
var eventGate: ParameterNode { $gate }
|
||||
|
||||
override func build() {
|
||||
// `releaseNode: 1` holds at `levels[1]` (full) while the gate is open; when the gate
|
||||
// drops to 0 the generator plays segment 1 (the release to 0) and then self-frees.
|
||||
let envelope: Envelope = Envelope(
|
||||
levels: [0.0, 1.0, 0.0],
|
||||
durations: [BlipVoice.attackSeconds, BlipVoice.releaseSeconds],
|
||||
curves: [.welch, .welch],
|
||||
releaseNode: 1
|
||||
)
|
||||
let shaped: EnvelopeGen.Audio = EnvelopeGen.Audio(
|
||||
envelope: envelope,
|
||||
gate: $gate,
|
||||
doneAction: .freeNode
|
||||
)
|
||||
let source: OscSin.Audio = OscSin.Audio(freq: $freq, mul: $amp)
|
||||
output(bus: 0, source: source * shaped)
|
||||
}
|
||||
}
|
||||
|
||||
func runDemo() {
|
||||
print("\n── EventPattern demo ──")
|
||||
|
||||
let tempoBPM: Double = 132.0
|
||||
|
||||
// Pattern 1 — the lead: a short A-minor-pentatonic phrase, written as named pitches rather
|
||||
// than raw Hz (equivalent MIDI form: `Pitch.midi(69).frequency`, etc.), played three times.
|
||||
/// The lead: a short A-minor-pentatonic phrase, written as named pitches rather than raw Hz
|
||||
/// (equivalent MIDI form: `Pitch.midi(69).frequency`, etc.), played three times.
|
||||
private func makeLead() -> EventPattern<BlipVoice> {
|
||||
let phrase: [Pitch] = [
|
||||
.named(.a, 4), .named(.c, 5), .named(.d, 5), .named(.e, 5),
|
||||
.named(.g, 5), .named(.e, 5), .named(.d, 5), .named(.c, 5),
|
||||
]
|
||||
let leadFreqs: [Double] = phrase.compactMap(\.frequency)
|
||||
let lead: EventPattern<BlipVoice> = EventPattern(make: { BlipVoice() })
|
||||
.bind(\.freq, .sequence(leadFreqs, repeats: 1))
|
||||
let freqs: [Double] = phrase.compactMap(\.frequency)
|
||||
return EventPattern(make: { BlipVoice() })
|
||||
.bind(\.freq, .sequence(freqs, repeats: 1))
|
||||
.bind(\.amp, .uniformRandom(low: 0.15, high: 0.3))
|
||||
.dur(.sequence([0.25, 0.25, 0.25, 0.5]))
|
||||
.legato(0.8)
|
||||
.tempo(tempoBPM)
|
||||
.repeats(3)
|
||||
}
|
||||
|
||||
// Pattern 2 — a bass line that enters `leadInBeats` after the lead and outlasts it.
|
||||
// There is no cross-pattern clock: `ParallelEventPattern` launches both children from the
|
||||
// one `play` call, so they share a start instant, and at the SAME tempo they share a beat
|
||||
// grid. `addAfter(beats:)` staggers the bass's entry on that grid — the bass simply waits
|
||||
// `leadInBeats` beats before its first note.
|
||||
let leadInBeats: Double = 2.0
|
||||
let bassPhrase: [Pitch] = [.named(.a, 2), .named(.a, 2), .named(.g, 2), .named(.e, 2)]
|
||||
let bassFreqs: [Double] = bassPhrase.compactMap(\.frequency)
|
||||
let bass: EventPattern<BlipVoice> = EventPattern(make: { BlipVoice() })
|
||||
.bind(\.freq, .sequence(bassFreqs, repeats: 1))
|
||||
/// The bass: one slow phrase at the same tempo, entered `leadInBeats` after the lead and
|
||||
/// outlasting it. No cross-pattern clock — ``ParallelEventPattern`` launches both children
|
||||
/// from the one `play` call, so they share a start instant and (at equal tempo) a beat grid.
|
||||
private func makeBass() -> EventPattern<BlipVoice> {
|
||||
let phrase: [Pitch] = [.named(.a, 2), .named(.a, 2), .named(.g, 2), .named(.e, 2)]
|
||||
let freqs: [Double] = phrase.compactMap(\.frequency)
|
||||
return EventPattern(make: { BlipVoice() })
|
||||
.bind(\.freq, .sequence(freqs, repeats: 1))
|
||||
.bind(\.amp, .uniformRandom(low: 0.2, high: 0.3))
|
||||
.dur(.sequence([1.0]))
|
||||
.legato(0.9)
|
||||
.tempo(tempoBPM)
|
||||
.repeats(1)
|
||||
}
|
||||
|
||||
// Start both together, staggering the bass two beats in, and control them as one handle.
|
||||
func runDemo() {
|
||||
print("\n── EventPattern demo ──")
|
||||
|
||||
// Start both together, staggering the bass `leadInBeats` in, and control them as one handle.
|
||||
let ensemble: ParallelEventPattern = ParallelEventPattern()
|
||||
ensemble.add(lead)
|
||||
ensemble.addAfter(beats: leadInBeats, eventPattern: bass)
|
||||
ensemble.add(makeLead())
|
||||
ensemble.addAfter(beats: leadInBeats, eventPattern: makeBass())
|
||||
let handle: EventPatternHandle = ensemble.play(on: engine)
|
||||
|
||||
// `waitUntilComplete` blocks until EVERY child task has finished — so it waits for the
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// BlipVoice.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
|
||||
/// A gated voice (``EventGated``): a sine through an `EnvelopeGen` whose gate holds it at full
|
||||
/// level while the note sounds, then plays a release and frees the voice via
|
||||
/// `doneAction: .freeNode` when ``EventPattern`` closes the gate at the note's sustain. No
|
||||
/// external removal, so the release is never hard-cut — nothing to tune, no click.
|
||||
///
|
||||
/// Used by ``EventPatternDemo`` for both the lead and the bass part.
|
||||
final class BlipVoice: SynthesizerBase, EventGated {
|
||||
/// Envelope release length in seconds — how long a note rings after its gate closes.
|
||||
/// Exposed so a caller can let the final note's tail finish before stopping the engine.
|
||||
nonisolated static let releaseSeconds: Double = 0.3
|
||||
/// Envelope attack length in seconds.
|
||||
nonisolated static let attackSeconds: Double = 0.01
|
||||
|
||||
@LiveParam var freq: Double = 440.0
|
||||
@LiveParam var amp: Double = 0.2
|
||||
@LiveParam var gate: Double = 1.0 // open by default so the attack fires on add
|
||||
|
||||
var eventGate: ParameterNode { $gate }
|
||||
|
||||
override func build() {
|
||||
// `releaseNode: 1` holds at `levels[1]` (full) while the gate is open; when the gate
|
||||
// drops to 0 the generator plays segment 1 (the release to 0) and then self-frees.
|
||||
let envelope: Envelope = Envelope(
|
||||
levels: [0.0, 1.0, 0.0],
|
||||
durations: [BlipVoice.attackSeconds, BlipVoice.releaseSeconds],
|
||||
curves: [.welch, .welch],
|
||||
releaseNode: 1
|
||||
)
|
||||
let shaped: EnvelopeGen.Audio = EnvelopeGen.Audio(
|
||||
envelope: envelope,
|
||||
gate: $gate,
|
||||
doneAction: .freeNode
|
||||
)
|
||||
let source: OscSin.Audio = OscSin.Audio(freq: $freq, mul: $amp)
|
||||
output(bus: 0, source: source * shaped)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user