Add rig-wide output volume + hard mute, MIDI-mappable
Volume is a CC-mappable [0,1] gain applied after every board's output; mute is a separate hard gate (not the existing dry bypass), togglable via Program Change. Both are lagged to avoid clicks and fan out across all boards from a single ShoeGaze-level setter. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,10 +17,11 @@ struct BoardEditAPITests {
|
||||
/// Builds an NRT-backed `ShoeGaze` with a single finalized board of the given pedal types.
|
||||
private func makeRig(
|
||||
pedals: [String],
|
||||
numAudioBuses: Int = 128
|
||||
numAudioBuses: Int = 128,
|
||||
duration: Double = 0.1
|
||||
) throws -> (ShoeGaze, SynthesisEngine, URL, PedalBoard) {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: 0.1,
|
||||
duration: duration,
|
||||
numAudioBuses: numAudioBuses
|
||||
)
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
@@ -281,6 +282,57 @@ struct BoardEditAPITests {
|
||||
#expect(board2.rigBypassNode?.value == 1.0, "new board comes up rig-bypassed")
|
||||
}
|
||||
|
||||
@Test func rigVolumeClampsAndAppliesToAllBoards() throws {
|
||||
let (sg, _, url, board): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
|
||||
try makeRig(pedals: ["Overdrive"])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
#expect(sg.rigVolume == 1.0, "rig volume starts at unity")
|
||||
sg.setRigVolume(0.5)
|
||||
#expect(sg.rigVolume == 0.5)
|
||||
#expect(board.rigVolumeNode?.value == 0.5)
|
||||
|
||||
sg.setRigVolume(2.0)
|
||||
#expect(sg.rigVolume == 1.0, "rig volume clamps to 1")
|
||||
sg.setRigVolume(-1.0)
|
||||
#expect(sg.rigVolume == 0.0, "rig volume clamps to 0")
|
||||
}
|
||||
|
||||
@Test func rigMuteSilencesOutputWithoutBypassing() throws {
|
||||
// Mute is smoothed by a short `Lag` to avoid a click, so the tail (well past the lag time)
|
||||
// must settle silent — the render must be long enough for that lag to fully resolve.
|
||||
let (sg, engine, url, _): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
|
||||
try makeRig(pedals: ["Overdrive"], duration: 1.0)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
#expect(!sg.rigMuted, "rig starts unmuted")
|
||||
sg.toggleRigMuted()
|
||||
#expect(sg.rigMuted, "rig reports muted after toggle")
|
||||
#expect(!sg.rigBypassed, "mute must not engage the dry bypass")
|
||||
|
||||
let samples: [Float] = try render(engine, url)
|
||||
let tail: [Float] = Array(samples.suffix(samples.count / 4))
|
||||
#expect(!hasNonSilentOutput(tail), "muted rig should settle to silence once the lag resolves")
|
||||
|
||||
sg.setRigMuted(false)
|
||||
#expect(!sg.rigMuted, "rig should unmute")
|
||||
}
|
||||
|
||||
@Test func boardFinalizedWhileRigVolumeAndMuteSetComesUpMatching() throws {
|
||||
let (sg, _, url, _): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
|
||||
try makeRig(pedals: ["Overdrive"])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
sg.setRigVolume(0.25)
|
||||
sg.setRigMuted(true)
|
||||
let board2: PedalBoard = try sg.addBoard()
|
||||
try board2.add(DelayPedal())
|
||||
try sg.finalizeBoard(board2)
|
||||
|
||||
#expect(board2.rigVolumeNode?.value == 0.25, "new board picks up current rig volume")
|
||||
#expect(board2.rigMuteNode?.value == 1.0, "new board picks up current rig mute")
|
||||
}
|
||||
|
||||
@Test func rigRebuildClearsTransientBypass() throws {
|
||||
let (sg, _, url, board): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
|
||||
try makeRig(pedals: ["Overdrive", "Delay"], numAudioBuses: 256)
|
||||
|
||||
@@ -165,6 +165,22 @@ struct MIDIControllerCCTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func ccCanTargetRigVolume() throws {
|
||||
let (controller, sg, _, url): (MIDIController, ShoeGaze, PedalBoard, URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
controller.armCCLearn(.rigVolume)
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 40, value: 0)) // learn
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 40, value: 127))
|
||||
#expect(abs(sg.rigVolume - 1.0) < 1e-9, "CC 127 should drive rig volume to max")
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 40, value: 0))
|
||||
#expect(abs(sg.rigVolume - 0.0) < 1e-9, "CC 0 should drive rig volume to min")
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 40, value: 64))
|
||||
#expect(abs(sg.rigVolume - 64.0 / 127.0) < 1e-9, "CC 64 should map mid-range")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func unboundCCIsIgnored() throws {
|
||||
let (controller, sg, board, url): (MIDIController, ShoeGaze, PedalBoard, URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
@@ -63,6 +63,23 @@ struct MIDIControllerPCTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func rigMuteLatchesOnEachPressAndIsSeparateFromBypass() throws {
|
||||
let (controller, sg, _, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
controller.armSwitchLearn(.rigMute)
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 1)) // learn only
|
||||
#expect(sg.rigMuted == false, "learn must not toggle")
|
||||
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 1))
|
||||
#expect(sg.rigMuted == true, "first press mutes")
|
||||
#expect(sg.rigBypassed == false, "mute must not engage bypass")
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 1))
|
||||
#expect(sg.rigMuted == false, "second press unmutes")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func pedalBypassLatches() throws {
|
||||
let (controller, sg, boards, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
Reference in New Issue
Block a user