7dccf596f4
Add ChainRouter persistence so routed multi-board rigs survive save/load —
previously captureState/loadRig only handled plain boards, so any A/B router
rig was silently lost on save (a latent gap this fixes for user rigs too).
- New ChainRouterState (Codable): each router's two linear branches as
[PedalState] plus splitter branch levels and merger output levels.
- ShoeGazeState gains an additive `routers` field decoded with
decodeIfPresent (nil for old rigs) — no format-version bump; routerless
rigs stay byte-identical (nil, not []).
- captureState snapshots routers; rebuildAllBoards reconstructs each via
makeChainRouter/addTo{A,B}/finalize and restores the blend.
FactoryRig gains a session-scoped builder variant (FactoryRigBuild enum) so
a rig can create its own boards/routers; makeEntries branches on it.
Ships the Garcia OBEL Clean/Effects Split: an effects/lead board (octave,
envelope filter, overdrive, phaser, delay, amp) vs a clean direct board,
selectable via the router — showcasing the multi-board capability.
Tests: full router capture -> JSON -> load round-trip with structure and
branch-level assertions plus a render check, backward-compat (no routers
key when routerless), and the Garcia rig via the factory load+render suite.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
119 lines
4.8 KiB
Swift
119 lines
4.8 KiB
Swift
// FactoryRigLibraryTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
@testable import LyrebirdShoeGaze
|
|
|
|
@MainActor
|
|
@Suite("FactoryRigLibrary")
|
|
struct FactoryRigLibraryTests {
|
|
|
|
// MARK: - Catalog integrity
|
|
|
|
@Test func catalogIsWellFormed() {
|
|
let rigs: [FactoryRig] = FactoryRigLibrary.all
|
|
#expect(rigs.count >= 6, "expected a full starter slate")
|
|
|
|
let ids: Set<UUID> = Set(rigs.map { $0.id })
|
|
#expect(ids.count == rigs.count, "rig ids must be unique")
|
|
|
|
let names: Set<String> = Set(rigs.map { $0.name })
|
|
#expect(names.count == rigs.count, "rig names must be unique")
|
|
|
|
let minBlurbLength: Int = 20
|
|
for rig: FactoryRig in rigs {
|
|
#expect(!rig.name.isEmpty, "\(rig.name) has empty name")
|
|
#expect(rig.blurb.count >= minBlurbLength, "\(rig.name) blurb too short")
|
|
}
|
|
|
|
// The slate should span more than one sonic family.
|
|
let categories: Set<FactoryRigCategory> = Set(rigs.map { $0.category })
|
|
#expect(categories.count >= 3, "starter slate should cover several categories")
|
|
}
|
|
|
|
@Test func blurbsAvoidTrademarkedProductNames() {
|
|
// Guard against a blurb accidentally naming a real amp/pedal brand: factory rigs describe
|
|
// the sound, never a trademarked product.
|
|
let forbidden: [String] = [
|
|
"marshall", "fender", "vox", "mesa", "boss", "orange", "dumble", "roland", "ibanez",
|
|
]
|
|
for rig: FactoryRig in FactoryRigLibrary.all {
|
|
let haystack: String = (rig.name + " " + rig.blurb).lowercased()
|
|
for brand: String in forbidden {
|
|
#expect(!haystack.contains(brand), "\(rig.name) mentions '\(brand)'")
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test func factoryDetectionRecognisesEveryRigAndRejectsOthers() {
|
|
let rigs: [FactoryRig] = FactoryRigLibrary.all
|
|
#expect(FactoryRigLibrary.factoryIDs.count == rigs.count)
|
|
for rig: FactoryRig in rigs {
|
|
#expect(FactoryRigLibrary.isFactory(rig.id), "\(rig.name) not recognised as factory")
|
|
}
|
|
// A freshly generated id is not a factory rig.
|
|
#expect(!FactoryRigLibrary.isFactory(UUID()))
|
|
}
|
|
|
|
// MARK: - Seeding entries
|
|
|
|
@Test func makeEntriesMatchesCatalogAndIsStable() throws {
|
|
let entries: [RigEntry] = try FactoryRigLibrary.makeEntries()
|
|
let rigs: [FactoryRig] = FactoryRigLibrary.all
|
|
|
|
#expect(entries.count == rigs.count, "one entry per rig")
|
|
for (entry, rig): (RigEntry, FactoryRig) in zip(entries, rigs) {
|
|
#expect(entry.id == rig.id, "entry id must be the rig's stable id")
|
|
#expect(entry.name == rig.name)
|
|
// A rig builds either plain boards or a router (or both) — never nothing.
|
|
let routerStates: [ChainRouterState] = entry.state.routers ?? []
|
|
#expect(!entry.state.boards.isEmpty || !routerStates.isEmpty, "\(rig.name) built nothing")
|
|
let boardPedals: Int = entry.state.boards.reduce(0) { $0 + $1.pedals.count }
|
|
let routerPedals: Int = routerStates.reduce(0) { $0 + $1.boardA.count + $1.boardB.count }
|
|
#expect(boardPedals + routerPedals >= 3, "\(rig.name) should build a non-trivial chain")
|
|
}
|
|
|
|
// Stable ids: re-seeding yields identical ids (so a re-seed overwrites in place).
|
|
let again: [RigEntry] = try FactoryRigLibrary.makeEntries()
|
|
#expect(entries.map { $0.id } == again.map { $0.id })
|
|
}
|
|
|
|
@Test func entriesRoundTripThroughJSON() throws {
|
|
let encoder: JSONEncoder = JSONEncoder()
|
|
let decoder: JSONDecoder = JSONDecoder()
|
|
for entry: RigEntry in try FactoryRigLibrary.makeEntries() {
|
|
let data: Data = try encoder.encode(entry)
|
|
let decoded: RigEntry = try decoder.decode(RigEntry.self, from: data)
|
|
#expect(decoded == entry, "\(entry.name) did not survive a JSON round-trip")
|
|
}
|
|
}
|
|
|
|
// MARK: - Load + render (full ship path)
|
|
|
|
@Test func everyFactoryEntryLoadsAndRenders() throws {
|
|
let renderDuration: Double = 0.2
|
|
let numAudioBuses: Int = 128
|
|
|
|
for entry: RigEntry in try FactoryRigLibrary.makeEntries() {
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
|
duration: renderDuration,
|
|
numAudioBuses: numAudioBuses
|
|
)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
let session: ShoeGaze = ShoeGaze(engine: engine)
|
|
try session.loadRig(from: entry.state)
|
|
|
|
try engine.start()
|
|
let samples: [Float] = readStereoCAF(url: url)
|
|
#expect(hasNonSilentOutput(samples), "\(entry.name) rendered silence")
|
|
}
|
|
}
|
|
}
|