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:
@@ -40,6 +40,8 @@ public final class LyrebirdScratchModel: ObservableObject {
|
||||
public nonisolated static let defaultPlaceholder: String = """
|
||||
// ⌘↩ — compile + run (removes synths from the previous run first).
|
||||
// ⌘⇧↩ — additive run (keep previously played synths around).
|
||||
// ⌘K — kill all sound (stop everything now; the engine stays running).
|
||||
// ⌃Space (or Esc / F5) — code completion (Swift mode).
|
||||
//
|
||||
// The snippet body has `context: SnippetContext` in scope.
|
||||
// `context.play { <graph> }` → play a bare generator graph, no subclass needed.
|
||||
@@ -212,9 +214,20 @@ public final class LyrebirdScratchModel: ObservableObject {
|
||||
|
||||
/// Which evaluator ``run(additive:)`` sends the buffer through. `.swift`
|
||||
/// compiles a snippet dylib; `.graphDSL` interprets a generator graph
|
||||
/// instantly. Toggle via ``switchMode(to:)`` so the seed placeholder swaps
|
||||
/// with the mode. See ``ScratchEvalMode``.
|
||||
@Published public private(set) var evalMode: ScratchEvalMode = .swift
|
||||
/// instantly. See ``ScratchEvalMode``.
|
||||
///
|
||||
/// Publicly settable so a SwiftUI `Picker` can two-way-bind it directly —
|
||||
/// a single synchronous `@Published` write with no deferred `Task`, which
|
||||
/// is what keeps the segmented control and this value from desyncing. The
|
||||
/// mode's *side-effects* (placeholder swap, baseline/diagnostic reset) are
|
||||
/// not run by the setter: a UI host applies them from
|
||||
/// `.onChange(of:)` via ``applyModeSwitchSideEffects(from:to:)`` (so the
|
||||
/// multi-property mutation runs outside the view-update pass), and
|
||||
/// programmatic callers use ``switchMode(to:)``, which does both. (A
|
||||
/// programmatic `switchMode` under a mounted view therefore applies the
|
||||
/// side-effects once directly and once more via `onChange` — an idempotent
|
||||
/// repeat; see ``applyModeSwitchSideEffects(from:to:)``.)
|
||||
@Published public var evalMode: ScratchEvalMode = .swift
|
||||
|
||||
public let session: LiveSession
|
||||
|
||||
@@ -495,12 +508,33 @@ public final class LyrebirdScratchModel: ObservableObject {
|
||||
/// markers against a buffer the current mode never evaluated.
|
||||
public func switchMode(to mode: ScratchEvalMode) {
|
||||
guard mode != evalMode else { return }
|
||||
if text == LyrebirdScratchModel.defaultPlaceholder(for: evalMode) {
|
||||
let previous: ScratchEvalMode = evalMode
|
||||
evalMode = mode
|
||||
applyModeSwitchSideEffects(from: previous, to: mode)
|
||||
}
|
||||
|
||||
/// Apply the consequences of a mode change — swap the seed placeholder (only
|
||||
/// when the buffer still holds the previous mode's untouched placeholder),
|
||||
/// drop the last-run baseline, and clear diagnostics from a prior run in the
|
||||
/// old mode.
|
||||
///
|
||||
/// Split out of ``switchMode(to:)`` so a SwiftUI host can bind ``evalMode``
|
||||
/// directly and run these from `.onChange(of:)` — outside the view-update
|
||||
/// pass, which is where mutating several `@Published` properties at once is
|
||||
/// allowed. The UI's normal path is a plain `evalMode` write reacted to in
|
||||
/// `onChange`; `switchMode(to:)` is the programmatic path and applies the
|
||||
/// side-effects itself. When a programmatic `switchMode(to:)` happens while a
|
||||
/// view is mounted, `onChange` then fires this a *second* time — a harmless
|
||||
/// repeat: the placeholder swap is a no-op (the buffer no longer equals the
|
||||
/// previous placeholder after the first pass) and the baseline/diagnostic
|
||||
/// resets are idempotent. No-op when `previous == to`.
|
||||
public func applyModeSwitchSideEffects(from previous: ScratchEvalMode, to mode: ScratchEvalMode) {
|
||||
guard previous != mode else { return }
|
||||
if text == LyrebirdScratchModel.defaultPlaceholder(for: previous) {
|
||||
text = LyrebirdScratchModel.defaultPlaceholder(for: mode)
|
||||
}
|
||||
lastEvaluatedText = nil
|
||||
diagnostics = []
|
||||
evalMode = mode
|
||||
reevalState = derivedIdleState()
|
||||
}
|
||||
|
||||
@@ -671,7 +705,7 @@ public final class LyrebirdScratchModel: ObservableObject {
|
||||
// (unsafe), so the mapped-snippet count is unchanged — refresh the mirror
|
||||
// so the UI stays truthful about it.
|
||||
loadedSnippetCount = session.loadedSnippetCount
|
||||
statusMessage = "Cleared all synths (tracked + slots)."
|
||||
statusMessage = "Killed all sound (tracked synths + named slots cleared)."
|
||||
lastEvaluatedText = nil
|
||||
reevalState = derivedIdleState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user