v1.4.0 release: live-coding scratch editor, interpreted Graph DSL, ClosureSynthesizer + SampleLoop
This commit is contained in:
@@ -95,7 +95,7 @@ struct LyrebirdScratchModelTests {
|
||||
await model.run(additive: false)
|
||||
model.clearTracked()
|
||||
#expect(model.trackedSynthCount == 0)
|
||||
#expect(model.statusMessage == "Cleared tracked synths.")
|
||||
#expect(model.statusMessage == "Cleared all synths (tracked + slots).")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,6 +166,151 @@ struct LyrebirdScratchModelTests {
|
||||
#expect(model.text == original)
|
||||
#expect(model.documentURL == nil)
|
||||
}
|
||||
|
||||
// MARK: - Re-eval readiness signal
|
||||
|
||||
@Test
|
||||
func blankInitialTextIsEmptyState() {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(session: session, initialText: " \n\t")
|
||||
#expect(model.reevalState == .empty)
|
||||
#expect(model.reevalState.canEvaluate == false)
|
||||
}
|
||||
|
||||
@Test
|
||||
func nonBlankInitialTextIsDirtyState() {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(session: session, initialText: "// hi")
|
||||
#expect(model.reevalState == .dirty)
|
||||
#expect(model.reevalState.canEvaluate == true)
|
||||
}
|
||||
|
||||
@Test
|
||||
func editingBlankToContentGoesDirty() {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(session: session, initialText: "")
|
||||
#expect(model.reevalState == .empty)
|
||||
model.text = "context.reportMessage(\"x\")"
|
||||
#expect(model.reevalState == .dirty)
|
||||
}
|
||||
|
||||
// A successful run drives the buffer `.dirty` → `.compiling` → `.clean`.
|
||||
// (`LiveSession.discoverSPMModuleMaps` makes the snippet compile under a
|
||||
// bare `swift test`, so a valid snippet reliably succeeds here.)
|
||||
@Test
|
||||
func runSettlesToCleanOnSuccess() async {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(
|
||||
session: session,
|
||||
initialText: "context.reportMessage(\"x\")"
|
||||
)
|
||||
#expect(model.reevalState == .dirty)
|
||||
let ok: Bool = await model.run(additive: false)
|
||||
#expect(ok)
|
||||
#expect(model.reevalState == .clean)
|
||||
}
|
||||
|
||||
@Test
|
||||
func editingAfterCleanReturnsToDirty() async {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(
|
||||
session: session,
|
||||
initialText: "context.reportMessage(\"x\")"
|
||||
)
|
||||
let ok: Bool = await model.run(additive: false)
|
||||
#expect(ok)
|
||||
#expect(model.reevalState == .clean)
|
||||
model.text = "context.reportMessage(\"y\")"
|
||||
#expect(model.reevalState == .dirty)
|
||||
}
|
||||
|
||||
@Test
|
||||
func failedRunEntersFailedWithDiagnosticCount() async {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(
|
||||
session: session,
|
||||
initialText: "let x: Int = \"nope\"\n"
|
||||
)
|
||||
await model.run(additive: false)
|
||||
#expect(model.reevalState == .failed(diagnosticCount: model.diagnostics.count))
|
||||
#expect(model.diagnostics.isEmpty == false)
|
||||
}
|
||||
|
||||
@Test
|
||||
func clearTrackedDropsBaselineToDirty() async {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(
|
||||
session: session,
|
||||
initialText: "context.reportMessage(\"x\")"
|
||||
)
|
||||
let ok: Bool = await model.run(additive: false)
|
||||
#expect(ok)
|
||||
#expect(model.reevalState == .clean)
|
||||
model.clearTracked()
|
||||
// Nothing the buffer produced is still playing → a re-run is meaningful.
|
||||
#expect(model.reevalState == .dirty)
|
||||
}
|
||||
|
||||
@Test
|
||||
func quantizedRunEntersQueuedThenSettles() async throws {
|
||||
let session: LiveSession = makeSession()
|
||||
session.swapClock = LyrebirdClock(engine: session.engine, bpm: 120)
|
||||
session.swapQuantize = .nextBeat
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(
|
||||
session: session,
|
||||
initialText: "context.play(slot: \"bass\") { OscSin.Audio(freq: 110, mul: 0.1) }"
|
||||
)
|
||||
let ok: Bool = await model.run(additive: false)
|
||||
#expect(ok)
|
||||
// Compiled + scheduled: queued until beat 1 (offline clock sits at 0).
|
||||
if case .queued(let beat) = model.reevalState {
|
||||
#expect(beat == 1.0)
|
||||
} else {
|
||||
Issue.record("expected .queued, got \(model.reevalState)")
|
||||
}
|
||||
// Still pending → refresh is a no-op.
|
||||
model.refreshQueuedState()
|
||||
if case .queued = model.reevalState {} else {
|
||||
Issue.record("expected still .queued")
|
||||
}
|
||||
// Once the swap is no longer pending (here: clock dropped), it settles
|
||||
// to .clean since the buffer is unchanged.
|
||||
session.swapClock = nil
|
||||
model.refreshQueuedState()
|
||||
#expect(model.reevalState == .clean)
|
||||
}
|
||||
|
||||
@Test
|
||||
func clearTrackedFullResetAlsoClearsSlots() throws {
|
||||
let session: LiveSession = makeSession()
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(session: session, initialText: "// x")
|
||||
let slotted: ClosureSynthesizer = ClosureSynthesizer { 0.2 }
|
||||
try session.engine.add(slotted)
|
||||
session.assignSlot("bass", synth: slotted)
|
||||
#expect(session.slotCount == 1)
|
||||
// The model's "Clear Synths" is a full reset — tracked + slots.
|
||||
model.clearTracked()
|
||||
#expect(session.slotCount == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
func loadEntersDirtyEvenIfContentMatchesPriorRun() async throws {
|
||||
let session: LiveSession = makeSession()
|
||||
let source: String = "context.reportMessage(\"x\")"
|
||||
let model: LyrebirdScratchModel = LyrebirdScratchModel(session: session, initialText: source)
|
||||
let ok: Bool = await model.run(additive: false)
|
||||
#expect(ok)
|
||||
#expect(model.reevalState == .clean)
|
||||
// Load the *same* source from disk: the run baseline is dropped, so it
|
||||
// reads as dirty rather than clean.
|
||||
let url: URL = FileManager.default
|
||||
.temporaryDirectory
|
||||
.appendingPathComponent("scratch_\(UUID().uuidString).swift")
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
try source.write(to: url, atomically: true, encoding: .utf8)
|
||||
try model.load(from: url)
|
||||
#expect(model.reevalState == .dirty)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user