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:
2026-07-01 19:28:09 -07:00
parent d4664b3c1f
commit 75edf44b64
10 changed files with 230 additions and 11 deletions
@@ -207,19 +207,28 @@ public final class MIDIController {
/// Captures a learned CC binding for the armed control and clears the Learn state.
private func captureCC(controller: UInt8, channel: UInt8, target: MIDIMap.CCTarget) {
learnTarget = nil
guard let shoeGaze: ShoeGaze = shoeGaze,
let resolved: ResolvedCC = resolveCC(target) else { return }
guard let shoeGaze: ShoeGaze = shoeGaze else { return }
// `rigVolume` is applied via a setter (it has no single node) and is always valid, so it
// needs no resolve; pedal/board targets resolve to re-stamp their display-name hints.
let hinted: MIDIMap.CCTarget
if case .rigVolume = target {
hinted = .rigVolume
} else {
guard let resolved: ResolvedCC = resolveCC(target) else { return }
hinted = resolved.hinted
}
let binding: MIDIMap.CCBinding = MIDIMap.CCBinding(
controller: controller,
channel: channel,
target: resolved.hinted
target: hinted
)
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
// One binding per control — re-learning a control replaces its binding. A single CC may
// drive MULTIPLE controls on purpose (e.g. map one expression pedal to two board levels and
// invert one for a crossfade), so we deliberately do NOT steal by controller number.
map.ccs.removeAll { $0.target.addresses(resolved.hinted) }
map.ccs.removeAll { $0.target.addresses(hinted) }
map.ccs.append(binding)
shoeGaze.midiMap = map
onMapChanged?()
@@ -230,10 +239,15 @@ public final class MIDIController {
guard let shoeGaze: ShoeGaze = shoeGaze, let map: MIDIMap = shoeGaze.midiMap else { return }
for binding: MIDIMap.CCBinding in map.ccs where binding.controller == controller {
if let boundChannel: UInt8 = binding.channel, boundChannel != channel { continue }
guard let resolved: ResolvedCC = resolveCC(binding.target) else { continue }
let ccMax: Double = 127.0
var norm: Double = Double(value) / ccMax
if binding.inverted { norm = 1.0 - norm }
if case .rigVolume = binding.target {
shoeGaze.setRigVolume(norm) // rig volume spans [0, 1] directly
continue
}
guard let resolved: ResolvedCC = resolveCC(binding.target) else { continue }
let mapped: Double = resolved.range.lowerBound
+ norm * (resolved.range.upperBound - resolved.range.lowerBound)
resolved.node.update(mapped)
@@ -273,6 +287,9 @@ public final class MIDIController {
if let labelHint: String = labelHint, labelHint != board.label { return nil }
let hinted: MIDIMap.CCTarget = .boardLevel(boardIndex: boardIndex, boardLabelHint: board.label)
return ResolvedCC(node: node, range: boardLevelRange, hinted: hinted)
case .rigVolume:
// Applied via `ShoeGaze.setRigVolume` (fans out to every board), not a single node.
return nil
}
}
@@ -335,6 +352,8 @@ public final class MIDIController {
switch action {
case .rigBypass:
shoeGaze.toggleRigBypassed()
case .rigMute:
shoeGaze.toggleRigMuted()
case .allBoards:
// One-shot: cancel any solo and bring every board back up.
shoeGaze.selectAllBoards(crossfadeSeconds: boardActionCrossfade)
@@ -360,7 +379,7 @@ public final class MIDIController {
/// A display-name hint for an action, captured at learn time for stale-binding detection.
private func hint(for action: MIDIMap.Action) -> String? {
switch action {
case .rigBypass, .allBoards:
case .rigBypass, .rigMute, .allBoards:
return nil
case .boardSolo(let index), .boardAudible(let index), .boardBypass(let index):
return board(at: index)?.label