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:
@@ -52,6 +52,20 @@ final class BoardOutputMaster: SynthesizerBase {
|
||||
/// The live `UIParamNode` backing `rigBypass` (rig-wide full bypass).
|
||||
var rigBypassNode: UIParamNode { $rigBypass }
|
||||
|
||||
/// Rig-wide output volume in [0, 1], applied to the final output. Driven across every board by
|
||||
/// `ShoeGaze.setRigVolume(_:)`. Defaults to `1` (unity).
|
||||
@UIParam var rigVolume: Double = 1.0
|
||||
|
||||
/// Rig-wide output mute — `0` = audible, `1` = silenced (a hard gate, not a dry bypass). Driven
|
||||
/// across every board by `ShoeGaze.setRigMuted(_:)`. Defaults to `0`.
|
||||
@UIParam var rigMute: Double = 0.0
|
||||
|
||||
/// The live `UIParamNode` backing `rigVolume` (rig-wide output volume).
|
||||
var rigVolumeNode: UIParamNode { $rigVolume }
|
||||
|
||||
/// The live `UIParamNode` backing `rigMute` (rig-wide output mute).
|
||||
var rigMuteNode: UIParamNode { $rigMute }
|
||||
|
||||
// MARK: - Routing
|
||||
|
||||
/// Left / mono board output bus index.
|
||||
@@ -102,19 +116,24 @@ final class BoardOutputMaster: SynthesizerBase {
|
||||
// seconds rather than clicking. The user master-gain knob is applied directly.
|
||||
let smoothedSelect: Lag.Control = Lag.Control(input: $selectGain, time: $crossfadeTime)
|
||||
|
||||
// Rig-wide output volume × mute, shared across both channels (like `smoothedSelect`).
|
||||
let rigOutputGain: any ValidGeneratorInput = rigOutputGainStage()
|
||||
|
||||
// The dry input tap — read once, used as the bypass source for both channels (the head
|
||||
// bus is mono, so a bypassed stereo board passes the same dry signal to both sides).
|
||||
let dry: In.Audio = input(bus: dryInputBusIndex)
|
||||
|
||||
let boardOutLeft: In.Audio = input(bus: boardOutputBusIndex)
|
||||
let switchedLeft: any ValidGeneratorInput = applyBypass(wet: boardOutLeft, dry: dry)
|
||||
let gainedLeft: any ValidGeneratorInput = (switchedLeft * smoothedSelect) * $masterGain
|
||||
let gainedLeft: any ValidGeneratorInput =
|
||||
((switchedLeft * smoothedSelect) * $masterGain) * rigOutputGain
|
||||
|
||||
if let rightIndex: Int = boardOutputBusRightIndex {
|
||||
// Stereo board: left tail → hardware 0, right tail → hardware 1, no pan spread.
|
||||
let boardOutRight: In.Audio = input(bus: rightIndex)
|
||||
let switchedRight: any ValidGeneratorInput = applyBypass(wet: boardOutRight, dry: dry)
|
||||
let gainedRight: any ValidGeneratorInput = (switchedRight * smoothedSelect) * $masterGain
|
||||
let gainedRight: any ValidGeneratorInput =
|
||||
((switchedRight * smoothedSelect) * $masterGain) * rigOutputGain
|
||||
output(bus: 0, source: gainedLeft)
|
||||
output(bus: 1, source: gainedRight)
|
||||
} else {
|
||||
@@ -123,6 +142,16 @@ final class BoardOutputMaster: SynthesizerBase {
|
||||
}
|
||||
}
|
||||
|
||||
/// Rig-wide output gain: the smoothed rig volume gated by the smoothed mute. Mute `0` → gain 1
|
||||
/// (audible), mute `1` → gain 0 (silent). Both lagged to avoid clicks.
|
||||
private func rigOutputGainStage() -> any ValidGeneratorInput {
|
||||
let rigVol: Lag.Control = Lag.Control(input: $rigVolume, time: bypassLagTime)
|
||||
let muteLagged: Lag.Control = Lag.Control(input: $rigMute, time: bypassLagTime)
|
||||
// (mute − 1) × −1 ⇒ 0→1, 1→0, using only generator−scalar and generator×scalar.
|
||||
let muteGain: any ValidGeneratorInput = (muteLagged - 1.0) * -1.0
|
||||
return rigVol * muteGain
|
||||
}
|
||||
|
||||
/// Routes `wet` to `dry` when either the per-board or rig-wide bypass is engaged. Two cascaded
|
||||
/// equal-power crossfades (each lagged to prevent clicks) give an independent "OR" of the two
|
||||
/// bypass sources: rig bypass overrides even a board that is otherwise engaged.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -41,6 +41,8 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
||||
/// so boolean actions latch in software; `boardSolo` is exclusive (radio).
|
||||
public enum Action: Codable, Equatable, Sendable {
|
||||
case rigBypass
|
||||
/// Mutes/unmutes the rig output (a hard silence, not a bypass).
|
||||
case rigMute
|
||||
/// Cancels any solo and makes every board audible again (the "All" button).
|
||||
case allBoards
|
||||
case boardSolo(boardIndex: Int)
|
||||
@@ -106,6 +108,9 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
||||
/// A board's master output level (the board fader).
|
||||
case boardLevel(boardIndex: Int, boardLabelHint: String?)
|
||||
|
||||
/// The rig-wide output volume (applies to the whole rig).
|
||||
case rigVolume
|
||||
|
||||
/// Whether two targets address the same control, ignoring the display-name hints (used to
|
||||
/// find and replace a binding regardless of the name captured at learn time).
|
||||
public func addresses(_ other: CCTarget) -> Bool {
|
||||
@@ -114,6 +119,8 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
||||
return b1 == b2 && p1 == p2 && c1 == c2
|
||||
case let (.boardLevel(b1, _), .boardLevel(b2, _)):
|
||||
return b1 == b2
|
||||
case (.rigVolume, .rigVolume):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -113,6 +113,14 @@ public final class PedalBoard {
|
||||
/// driven across every board by `ShoeGaze.setRigBypassed(_:)`. `nil` until `finalizeBoard(_:)`.
|
||||
public internal(set) var rigBypassNode: UIParamNode?
|
||||
|
||||
/// The live rig-wide output-volume `UIParamNode` ([0, 1]), driven across every board by
|
||||
/// `ShoeGaze.setRigVolume(_:)`. `nil` until `finalizeBoard(_:)`.
|
||||
public internal(set) var rigVolumeNode: UIParamNode?
|
||||
|
||||
/// The live rig-wide output-mute `UIParamNode` (`0` = audible, `1` = silenced), driven across
|
||||
/// every board by `ShoeGaze.setRigMuted(_:)`. `nil` until `finalizeBoard(_:)`.
|
||||
public internal(set) var rigMuteNode: UIParamNode?
|
||||
|
||||
/// The output master synth for this board. Set by `ShoeGaze.finalizeBoard(_:)`;
|
||||
/// used by `ShoeGaze.removeBoard(_:)` to tear down just this board's master.
|
||||
internal var outputMaster: BoardOutputMaster?
|
||||
|
||||
@@ -270,6 +270,8 @@ public final class ShoeGaze {
|
||||
board.crossfadeTimeNode = master.crossfadeTimeNode
|
||||
board.boardBypassNode = master.boardBypassNode
|
||||
board.rigBypassNode = master.rigBypassNode
|
||||
board.rigVolumeNode = master.rigVolumeNode
|
||||
board.rigMuteNode = master.rigMuteNode
|
||||
|
||||
// If a board is currently soloed, a newly-finalized board must come up silent
|
||||
// (select-gain 0) so it doesn't leak audio past the active solo.
|
||||
@@ -284,6 +286,9 @@ public final class ShoeGaze {
|
||||
if rigBypassed {
|
||||
master.rigBypassNode.update(1.0)
|
||||
}
|
||||
// Bring a newly-finalized board up at the current rig volume / mute.
|
||||
master.rigVolumeNode.update(rigVolume)
|
||||
master.rigMuteNode.update(rigMuted ? 1.0 : 0.0)
|
||||
}
|
||||
|
||||
// MARK: - Board selection / crossfade
|
||||
@@ -296,6 +301,13 @@ public final class ShoeGaze {
|
||||
/// A live performance toggle (not persisted); cleared on input-source / engine rebuild.
|
||||
public private(set) var rigBypassed: Bool = false
|
||||
|
||||
/// Rig-wide output volume in [0, 1], applied to every board's output. Survives an input-source
|
||||
/// rebuild (re-applied to each rebuilt board in `finalizeBoard`).
|
||||
public private(set) var rigVolume: Double = 1.0
|
||||
|
||||
/// `true` when the rig output is muted (hard-silenced, not bypassed). Survives a rebuild.
|
||||
public private(set) var rigMuted: Bool = false
|
||||
|
||||
/// Identities of boards currently in per-board full bypass. Observable so UI toggles refresh;
|
||||
/// authoritative bypass value lives on each board's `boardBypassNode`. Transient (not persisted).
|
||||
public private(set) var bypassedBoards: Set<ObjectIdentifier> = []
|
||||
@@ -420,6 +432,34 @@ public final class ShoeGaze {
|
||||
setRigBypassed(!rigBypassed)
|
||||
}
|
||||
|
||||
/// Sets the rig-wide output volume (clamped to [0, 1]), applied to every board. Smoothed per
|
||||
/// board to avoid clicks.
|
||||
///
|
||||
/// - Parameter volume: Output volume in [0, 1].
|
||||
public func setRigVolume(_ volume: Double) {
|
||||
let clamped: Double = min(max(volume, 0.0), 1.0)
|
||||
for managed: PedalBoard in boards {
|
||||
managed.rigVolumeNode?.update(clamped)
|
||||
}
|
||||
rigVolume = clamped
|
||||
}
|
||||
|
||||
/// Mutes or un-mutes the rig output — a hard gate to silence, distinct from the dry-passthrough
|
||||
/// ``setRigBypassed(_:)``. Applied to every board, smoothed to avoid clicks.
|
||||
///
|
||||
/// - Parameter muted: `true` to silence the output, `false` to restore it.
|
||||
public func setRigMuted(_ muted: Bool) {
|
||||
for managed: PedalBoard in boards {
|
||||
managed.rigMuteNode?.update(muted ? 1.0 : 0.0)
|
||||
}
|
||||
rigMuted = muted
|
||||
}
|
||||
|
||||
/// Toggles the rig output mute. See ``setRigMuted(_:)``.
|
||||
public func toggleRigMuted() {
|
||||
setRigMuted(!rigMuted)
|
||||
}
|
||||
|
||||
/// Removes a single board and its associated input source and output master from
|
||||
/// the engine, then releases the board's buses. The other boards are unaffected.
|
||||
///
|
||||
|
||||
@@ -151,10 +151,38 @@ public struct BoardBarView: View {
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||
}
|
||||
|
||||
rigVolumeRow
|
||||
}
|
||||
.frame(width: BoardBarView.controlColumnWidth)
|
||||
}
|
||||
|
||||
/// Rig-wide output volume + mute (applies to the whole rig, after every board).
|
||||
private var rigVolumeRow: some View {
|
||||
HStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||
Text("Vol")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||
Slider(
|
||||
value: Binding(
|
||||
get: { shoeGaze.rigVolume },
|
||||
set: { shoeGaze.setRigVolume($0) }
|
||||
),
|
||||
in: 0.0 ... 1.0
|
||||
)
|
||||
.frame(minWidth: BoardBarView.crossfadeSliderMinWidth)
|
||||
.disabled(shoeGaze.rigMuted)
|
||||
Button {
|
||||
shoeGaze.toggleRigMuted()
|
||||
} label: {
|
||||
Image(systemName: shoeGaze.rigMuted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(shoeGaze.rigMuted ? .red : .orange)
|
||||
.help(shoeGaze.rigMuted ? "Unmute the rig output" : "Mute the rig output")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Board cell
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
@@ -99,6 +99,7 @@ public struct MIDIMappingSheet: View {
|
||||
private var switchRowModels: [SwitchRowModel] {
|
||||
var rows: [SwitchRowModel] = [
|
||||
SwitchRowModel(id: "sw-rig", action: .rigBypass, label: "Rig Bypass"),
|
||||
SwitchRowModel(id: "sw-mute", action: .rigMute, label: "Rig Mute"),
|
||||
SwitchRowModel(id: "sw-all", action: .allBoards, label: "All Boards On"),
|
||||
]
|
||||
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
|
||||
@@ -124,7 +125,9 @@ public struct MIDIMappingSheet: View {
|
||||
}
|
||||
|
||||
private var ccRowModels: [CCRowModel] {
|
||||
var rows: [CCRowModel] = []
|
||||
var rows: [CCRowModel] = [
|
||||
CCRowModel(id: "cc-rigvol", target: .rigVolume, label: "Rig · Volume"),
|
||||
]
|
||||
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
|
||||
let boardIndex: Int = boardPair.offset
|
||||
let board: PedalBoard = boardPair.element
|
||||
|
||||
Reference in New Issue
Block a user