feat(mutant): add Range switch, Sweep, and Attack/Release controls

The envelope filter's cutoff sweep was fixed (80 Hz -> 3200 Hz, 5 ms / 150 ms),
so it read as either muted (resting too low) or extreme (40x span). The
underlying MuTronIII generator already takes freqLo/freqHi/attack/release as
live params, so expose them:

- Range switch (Lo/Hi) on the face — shifts the whole sweep window low
  (rhythm/bass) or high (harmonics/solos), matching the original Mu-Tron III.
- Sweep, Attack, Release in the advanced pop-over — Sweep sets how far input
  amplitude drives the cutoff (peak = resting x sweep); Attack/Release shape
  the envelope response.
- Tamer defaults: resting 80 -> 120 Hz, span 40x -> 20x.

Serialization-safe: new continuous params live in advancedValues and Range is
a trailing switch, so a rig saved with the old 2-switch / no-advanced layout
loads unchanged with the new controls at their defaults (test covers it).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-13 09:42:52 -07:00
parent 850b86209a
commit 4a9bf0fb30
2 changed files with 161 additions and 26 deletions
@@ -100,28 +100,110 @@ struct MutantPedalTests {
pedal.mode = 2.0 // highpass
pedal.direction = 0.0 // down
pedal.range = 1.0 // high band
pedal.sweep = 12.0
pedal.attack = 0.02
pedal.release = 0.3
let state: PedalState = pedal.captureState()
#expect(state.switchValues == [0.0, 2.0]) // [direction, mode]
#expect(state.switchValues == [0.0, 2.0, 1.0]) // [direction, mode, range]
#expect(state.advancedValues == [12.0, 0.02, 0.3]) // [sweep, attack, release]
let restored: MutantPedal = MutantPedal()
restored.applyState(state)
#expect(restored.mode == 2.0)
#expect(restored.direction == 0.0)
#expect(restored.range == 1.0)
#expect(restored.sweep == 12.0)
#expect(restored.attack == 0.02)
#expect(restored.release == 0.3)
}
@Test func oldTwoSwitchStateStillLoads() throws {
// A rig saved before Range / the advanced knobs existed carries only [direction, mode] and
// an empty advancedValues; it must load without mis-mapping, leaving the new controls at
// their defaults.
let legacy: PedalState = PedalState(
type: "Mutant",
knobValues: [2.5, 4.0, 1, 1], // sensitivity, resonance, mix, level
switchValues: [1.0, 0.0], // direction=up, mode=lowpass
bypass: 0
)
let pedal: MutantPedal = MutantPedal()
pedal.applyState(legacy)
#expect(pedal.direction == 1.0)
#expect(pedal.mode == 0.0)
#expect(pedal.sensitivity == 2.5)
#expect(pedal.resonance == 4.0)
// New controls keep their defaults.
#expect(pedal.range == 0.0)
#expect(pedal.sweep == 20.0)
}
@Test func exposesSensitivityAndResonanceKnobs() throws {
let pedal: MutantPedal = MutantPedal()
let labels: [String] = pedal.effectKnobs.map { $0.label }
#expect(labels == ["Sensitivity", "Resonance"])
#expect(pedal.effectKnobs.map { $0.label } == ["Sensitivity", "Resonance"])
#expect(pedal.advancedKnobs.map { $0.label } == ["Sweep", "Attack", "Release"])
}
@Test func exposesTwoStateSweepAndThreeStateModeSwitches() throws {
@Test func exposesDirectionModeAndRangeSwitches() throws {
let pedal: MutantPedal = MutantPedal()
let switches: [PedalSwitch] = pedal.effectSwitches
#expect(switches.map { $0.label } == ["Sweep", "Mode"])
// Two-state sweep (Down/Up), three-state mode (LP/BP/HP).
#expect(switches.first?.options.map { $0.title } == ["Down", "Up"])
#expect(switches.last?.options.map { $0.title } == ["LP", "BP", "HP"])
#expect(switches.map { $0.label } == ["Direction", "Mode", "Range"])
#expect(switches[0].options.map { $0.title } == ["Down", "Up"])
#expect(switches[1].options.map { $0.title } == ["LP", "BP", "HP"])
#expect(switches[2].options.map { $0.title } == ["Lo", "Hi"])
}
/// Renders the test loop through a Mutant configured by `configure`, returning a mid-render window.
private func renderWindow(configure: (MutantPedal) -> Void) throws -> [Float] {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, numAudioBuses: 64)
defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: MutantPedal = MutantPedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url)
}
private func windowSSD(_ a: [Float], _ b: [Float]) -> Double {
let skip: Int = 1024
let window: Int = 2048
guard a.count >= skip + window, b.count >= skip + window else { return 0 }
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1)
return acc + d * d
}
}
@Test func sweepAmountChangesOutput() throws {
let narrow: [Float] = try renderWindow { $0.sweep = 3.0 }
let wide: [Float] = try renderWindow { $0.sweep = 45.0 }
#expect(hasNonSilentOutput(narrow))
#expect(hasNonSilentOutput(wide))
#expect(windowSSD(narrow, wide) > 0, "sweep amount did not change output")
}
@Test func rangeSwitchChangesOutput() throws {
let low: [Float] = try renderWindow { $0.range = 0.0 }
let high: [Float] = try renderWindow { $0.range = 1.0 }
#expect(windowSSD(low, high) > 0, "range band did not change output")
}
@Test func attackReleaseChangesOutput() throws {
let fast: [Float] = try renderWindow { $0.attack = 0.001; $0.release = 0.03 }
let slow: [Float] = try renderWindow { $0.attack = 0.06; $0.release = 0.5 }
#expect(windowSSD(fast, slow) > 0, "attack/release did not change output")
}
@Test func sweepDirectionChangesOutput() throws {