Looper: make effect() idempotent across graph rebuilds
The engine re-invokes build()/effect() via rebuildGraph() on every add — including the re-adds a board edit (reorder, insert/remove a neighbour, toggle a split) or a rig load performs on the same instance. effect() appended to the per-track arrays (buffers/players/overdubRecorders/overdubGates) each time, so a second build doubled them, desyncing the generators from the fixed-size state arrays and leaving the whole looper UI/transport wrong — a broken state that stuck and reproduced from a saved rig. Reset the arrays and transport state at the top of effect() (resetForRebuild) so a rebuild starts clean; the freshly re-allocated buffers are empty, so returning to the clear state is correct. Regression: rebuildDoesNotDoubleTrackGenerators (two effect() calls keep each array at trackCount). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,24 @@ struct LooperPedalTests {
|
||||
#expect(LooperPedal.trackCount == 4)
|
||||
}
|
||||
|
||||
@Test func rebuildDoesNotDoubleTrackGenerators() throws {
|
||||
// effect() runs from build(), which the engine re-invokes on every add — including the
|
||||
// re-adds a board edit performs on the same instance. It must be idempotent (not append
|
||||
// to the per-track arrays each time), or the looper's generators/state desync.
|
||||
let pedal: LooperPedal = LooperPedal()
|
||||
pedal.sampleRate = 44100.0
|
||||
let dry: any ValidGeneratorInput = OscSin.Audio(freq: 100.0)
|
||||
_ = pedal.effect(dry)
|
||||
_ = pedal.effect(dry) // simulate a second build()
|
||||
|
||||
let counts: (buffers: Int, players: Int, overdub: Int, gates: Int) = pedal.trackGeneratorCountsForTesting
|
||||
#expect(counts.buffers == LooperPedal.trackCount)
|
||||
#expect(counts.players == LooperPedal.trackCount)
|
||||
#expect(counts.overdub == LooperPedal.trackCount)
|
||||
#expect(counts.gates == LooperPedal.trackCount)
|
||||
#expect(pedal.transportState == .clear)
|
||||
}
|
||||
|
||||
@Test func looperHidesMixControl() throws {
|
||||
// The looper always passes the clean signal through and adds the loop on top, so the
|
||||
// wet/dry Mix knob is hidden; a plain pedal keeps it.
|
||||
|
||||
Reference in New Issue
Block a user