diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift index 4b992c8..cfd88ca 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift @@ -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() } } diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift index fe100e3..2c35264 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift @@ -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 diff --git a/Sources/LyrebirdShoeGaze/Pedal.swift b/Sources/LyrebirdShoeGaze/Pedal.swift index 4d08d2d..58832bd 100644 --- a/Sources/LyrebirdShoeGaze/Pedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedal.swift @@ -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. diff --git a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift index 0f12135..69cb407 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift @@ -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 diff --git a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift index 228bf1e..2ab0309 100644 --- a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift +++ b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift @@ -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 diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index 0377c89..0f69aa4 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -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) } diff --git a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift index d1d7a70..23bedbf 100644 --- a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift @@ -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 { diff --git a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift index 4aa4ba4..1e7dc3c 100644 --- a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift +++ b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift @@ -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") + } + } }