Looper: address review — router pedals + doc fixes
allPedals() (used by stopEngine / teardown to notify pedals) now also walks ChainRouter branch boards, so a looper placed in a parallel-router branch gets engineDidStop() / rigWillTeardown() like any other. Factor the per-board walk into pedals(in:). Restore addBoard()'s doc comment (it was displaced above stopEngine when that method was inserted) and document the engine-stopped precondition on Pedal.rigWillTeardown(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -121,6 +121,10 @@ open class Pedal: SynthesizerBase {
|
||||
/// Called on the main thread just before the rig is torn down (rig load / clear / input-source
|
||||
/// change), while the pedal is still live. Stateful pedals override this to stop any background
|
||||
/// work and return to a clean state before their instance is discarded. Default: no-op.
|
||||
///
|
||||
/// - Important: Fired from `ShoeGaze.teardown()`, which — like all node-removal paths — must
|
||||
/// run with the engine already stopped. An override that clears buffers or stops RT-adjacent
|
||||
/// work relies on that precondition; do not call `teardown()` with the engine running.
|
||||
open func rigWillTeardown() {}
|
||||
|
||||
/// Number of standard enclosure widths this pedal's card occupies in the UI. Defaults
|
||||
|
||||
@@ -178,6 +178,52 @@ public final class ShoeGaze {
|
||||
|
||||
// MARK: - Board management
|
||||
|
||||
/// Stops the audio engine as a deliberate user action: notifies every pedal via
|
||||
/// ``Pedal/engineDidStop()`` (so stateful pedals like the looper return to a clean state and
|
||||
/// post a notice) and then stops the engine. Use this for the user-facing Stop control — not
|
||||
/// for transient stop-around-rebuild sequences, which call `engine.stop()` directly so
|
||||
/// pedals keep their state across the restart.
|
||||
public func stopEngine() {
|
||||
for pedal: Pedal in allPedals() {
|
||||
pedal.engineDidStop()
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
/// Every live `Pedal` across all main boards and chain-router branches.
|
||||
private func allPedals() -> [Pedal] {
|
||||
var result: [Pedal] = []
|
||||
for board: PedalBoard in boards {
|
||||
result.append(contentsOf: pedals(in: board))
|
||||
}
|
||||
for router: ChainRouter in routers {
|
||||
result.append(contentsOf: pedals(in: router.boardA))
|
||||
result.append(contentsOf: pedals(in: router.boardB))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/// Every live `Pedal` in one board, including pedals inside its parallel and stereo-split
|
||||
/// branch sections (branch pedals live in their section objects, not as top-level segments).
|
||||
private func pedals(in board: PedalBoard) -> [Pedal] {
|
||||
var result: [Pedal] = []
|
||||
for segment: BoardSegment in board.orderedSegments {
|
||||
switch segment {
|
||||
case .pedal(let pedal):
|
||||
result.append(pedal)
|
||||
case .parallel(let section):
|
||||
result.append(contentsOf: section.branchA.pedals)
|
||||
result.append(contentsOf: section.branchB.pedals)
|
||||
case .stereoSplit(let section), .stereoUnzip(let section):
|
||||
result.append(contentsOf: section.left.pedals)
|
||||
result.append(contentsOf: section.right.pedals)
|
||||
case .mergeToMono:
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/// Allocates a new `PedalBoard` connected to the engine, wires the input source,
|
||||
/// and returns the board ready for pedals to be added via `board.add(_:)`.
|
||||
///
|
||||
@@ -195,41 +241,6 @@ public final class ShoeGaze {
|
||||
/// - `BusAllocatorError.noFreeBus` if no mono bus is available.
|
||||
/// - `EngineAddError` if the engine rejects a node insertion.
|
||||
@discardableResult
|
||||
/// Stops the audio engine as a deliberate user action: notifies every pedal via
|
||||
/// ``Pedal/engineDidStop()`` (so stateful pedals like the looper return to a clean state and
|
||||
/// post a notice) and then stops the engine. Use this for the user-facing Stop control — not
|
||||
/// for transient stop-around-rebuild sequences, which call `engine.stop()` directly so
|
||||
/// pedals keep their state across the restart.
|
||||
public func stopEngine() {
|
||||
for pedal: Pedal in allPedals() {
|
||||
pedal.engineDidStop()
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
/// Every live `Pedal` across all boards, including pedals inside parallel and stereo-split
|
||||
/// branches (branch pedals live in their section objects, not as top-level segments).
|
||||
private func allPedals() -> [Pedal] {
|
||||
var result: [Pedal] = []
|
||||
for board: PedalBoard in boards {
|
||||
for segment: BoardSegment in board.orderedSegments {
|
||||
switch segment {
|
||||
case .pedal(let pedal):
|
||||
result.append(pedal)
|
||||
case .parallel(let section):
|
||||
result.append(contentsOf: section.branchA.pedals)
|
||||
result.append(contentsOf: section.branchB.pedals)
|
||||
case .stereoSplit(let section), .stereoUnzip(let section):
|
||||
result.append(contentsOf: section.left.pedals)
|
||||
result.append(contentsOf: section.right.pedals)
|
||||
case .mergeToMono:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public func addBoard() throws -> PedalBoard {
|
||||
let board: PedalBoard = try PedalBoard(engine: engine, clock: clock)
|
||||
board.label = "Board \(boards.count + 1)"
|
||||
|
||||
Reference in New Issue
Block a user