Looper: MIDI-mappable transport; clean-through + Playback balance

MIDI: add looperStop / looperCueStop / looperReverse PedalActionKind cases and
dispatch them (stopPlayback / toggleStopAtLoopEnd / toggleReverse). The MIDI
mapping sheet now lists Record / Stop / Cue Stop / Reverse / Reset as
Program-Change-mappable switch actions for each looper pedal (previously only
Bypass was surfaced).

Mix: the clean guitar now always passes through at full level and the loop bank
is summed on top (dry + loop·gate) instead of crossfading dry against the loop.
The Playback knob therefore sets the looped-vs-live balance. Hide the confusing
wet/dry Mix knob for the looper via a new Pedal.showsMixControl (mix stays fully
wet); other pedals are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 16:08:25 -07:00
parent d728bfa72a
commit b99a526df6
8 changed files with 88 additions and 5 deletions
@@ -395,6 +395,12 @@ public final class MIDIController {
node.update(node.value < toggleThreshold ? 1.0 : 0.0)
case .looperReset:
(pedal as? LooperPedal)?.resetLoop()
case .looperStop:
(pedal as? LooperPedal)?.stopPlayback()
case .looperCueStop:
(pedal as? LooperPedal)?.toggleStopAtLoopEnd()
case .looperReverse:
(pedal as? LooperPedal)?.toggleReverse()
}
}
@@ -77,6 +77,12 @@ public struct MIDIMap: Codable, Equatable, Sendable {
case looperLoopToggle
/// Looper: reset — clears all tracks and returns to the clear state.
case looperReset
/// Looper: immediately stops playback (`LooperPedal.stopPlayback()`).
case looperStop
/// Looper: arms / cancels a stop at the loop end (`LooperPedal.toggleStopAtLoopEnd()`).
case looperCueStop
/// Looper: flips playback direction (`LooperPedal.toggleReverse()`).
case looperReverse
}
// MARK: - Switch binding
+6
View File
@@ -107,6 +107,12 @@ open class Pedal: SynthesizerBase {
/// Override in a widener or stereo-native subclass.
open var channelKind: PedalChannelKind { .mono }
/// Whether the UI shows the common wet/dry `Mix` control for this pedal. Defaults to `true`.
/// A pedal that manages its own dry/wet balance internally (e.g. the looper, where the clean
/// signal always passes through) overrides this to `false` so the confusing Mix knob is hidden
/// and `mix` stays at its fully-wet default.
open var showsMixControl: Bool { true }
/// Called on the main thread when the audio engine is stopped by the user (via
/// `ShoeGaze.stopEngine()`), not during a transient stop-around-rebuild. Stateful pedals
/// (e.g. the looper) override this to return to a clean state. Default: no-op.
@@ -43,6 +43,10 @@ public final class LooperPedal: Pedal {
/// Double-width card: the looper carries a full transport plus a track strip and timeline.
public override var widthUnits: Int { 2 }
/// The looper always passes the clean signal through and adds the loop on top (see `effect`),
/// so the wet/dry Mix knob is meaningless — hide it and keep `mix` fully wet.
public override var showsMixControl: Bool { false }
// MARK: - Knobs
/// Fade time constant, in seconds, for the loop on/off mute and the record→play handoff.
@@ -353,15 +357,18 @@ public final class LooperPedal: Pedal {
// Loop bank audible only while playing and not muted; smoothed to avoid clicks.
let combinedGate: any ValidGeneratorInput = $isPlaying * $loopOn
let smoothedGate: Lag.Control = Lag.Control(input: combinedGate, time: $crossfadeTime)
let dryGate: any ValidGeneratorInput = unity - smoothedGate
// Sum all track players. Empty buffers contribute silence.
// Sum all track players. Empty buffers contribute silence. Each player is already
// scaled by the `Playback` level, so `Playback` sets the loop amount against the live
// signal below.
var loopSum: any ValidGeneratorInput = players[0]
for i: Int in 1 ..< players.count {
loopSum = loopSum + players[i]
}
return (dry * dryGate) + (loopSum * smoothedGate)
// The clean (dry) signal always passes through at full level; the loop bank is added on
// top, gated by play/mute. `Playback` controls the looped-vs-live balance.
return dry + (loopSum * smoothedGate)
}
// MARK: - Loop footswitch
@@ -118,6 +118,22 @@ public struct MIDIMappingSheet: View {
id: "sw-pb-\(pedal.id)",
action: .pedalBypass(pedalID: pedal.id),
label: "\(board.label) · \(pedal.displayName) · Bypass"))
// Loopers expose their transport footswitches as mappable switch actions.
if pedal is LooperPedal {
let looperActions: [(String, String, MIDIMap.PedalActionKind)] = [
("rec", "Record", .looperRecordStop),
("stop", "Stop", .looperStop),
("cue", "Cue Stop", .looperCueStop),
("rev", "Reverse", .looperReverse),
("reset", "Reset", .looperReset),
]
for (slug, name, kind): (String, String, MIDIMap.PedalActionKind) in looperActions {
rows.append(SwitchRowModel(
id: "sw-la-\(slug)-\(pedal.id)",
action: .pedalAction(pedalID: pedal.id, kind: kind),
label: "\(board.label) · \(pedal.displayName) · \(name)"))
}
}
}
}
return rows
+3 -2
View File
@@ -528,10 +528,11 @@ public struct PedalView: View {
}
/// The `Mix` knob — the second-to-last entry of `pedal.knobs` — placed right of the
/// bypass switch to mirror `Level`.
/// bypass switch to mirror `Level`. Hidden for pedals that manage their own dry/wet balance
/// (``Pedal/showsMixControl``), e.g. the looper.
@ViewBuilder
private var mixControl: some View {
if let mix: PedalKnob = pedal.knobs.dropLast().last {
if pedal.showsMixControl, let mix: PedalKnob = pedal.knobs.dropLast().last {
ParameterKnob(mix.label, node: mix.node, range: mix.range)
.foregroundStyle(Color.white)
}
@@ -173,6 +173,27 @@ struct LooperPedalTests {
#expect(LooperPedal.trackCount == 4)
}
@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.
#expect(LooperPedal().showsMixControl == false)
}
@Test func cleanSignalPassesThroughWhilePlaying() throws {
// With the loop muted (loopOn = 0) but a loop recorded and a live tone present, the
// output must still carry the clean signal at full level — it is never gated by the loop.
let recordDuration: Double = 0.1
let samples: [Float] = try render(totalDuration: 0.5) { _, _, pedal, scheduleAction in
pedal.pressLoop()
try scheduleAction(recordDuration) { pedal.pressLoop() } // play + overdub A
try scheduleAction(recordDuration + 0.02) { pedal.pressLoop() } // end overdub
try scheduleAction(0.2) { pedal.loopOn = 0.0 } // mute the loop, keep live tone
}
let tailStart: Int = Int(Double(samples.count) * 0.9)
let tail: [Float] = Array(samples[tailStart...])
#expect(hasNonSilentOutput(tail), "Clean signal must pass through even with the loop muted")
}
// MARK: - Audio behaviour (immediate / un-quantized)
@Test func clearStatePassesDryThrough() throws {
@@ -266,4 +266,24 @@ struct MIDIControllerPCTests {
"mapped Program Change should dispatch the looper record/stop action")
}
}
@Test func pedalActionDispatchesLooperReverse() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
let sg: ShoeGaze = ShoeGaze(engine: engine)
let board: PedalBoard = try sg.addBoard()
let looper: LooperPedal = LooperPedal()
try board.add(looper)
try sg.finalizeBoard(board)
let controller: MIDIController = MIDIController(engine: engine, shoeGaze: sg)
defer { try? FileManager.default.removeItem(at: url) }
withExtendedLifetime(sg) {
controller.armSwitchLearn(.pedalAction(pedalID: looper.id, kind: .looperReverse))
controller.ingestForTesting(.programChange(channel: 0, program: 20)) // learn only
#expect(looper.reverse == 0.0)
controller.ingestForTesting(.programChange(channel: 0, program: 20)) // fire → toggleReverse
#expect(looper.reverse == 1.0, "mapped Program Change should flip the looper's reverse")
}
}
}