Looper: per-track mute via the A/B/C/D dots
Each track player now runs through a smoothed per-track mute gate. Tapping a track dot selects it (as before); tapping the already-selected, recorded track toggles its mute (tapTrack). Muted dots dim and show a slash. Mutes clear on reset and don't survive a rebuild. Covered by tapTrackSelectsThenMutesRecordedTrack. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -123,6 +123,13 @@ public final class LooperPedal: Pedal {
|
||||
private var overdubRecorders: [RecordBuffer.Audio] = []
|
||||
private var overdubGates: [ParameterNode] = []
|
||||
|
||||
/// Per-track playback mute gate (`1` = audible, `0` = muted), smoothed by `crossfadeTime` and
|
||||
/// multiplied into each track's player so a recorded track can be silenced.
|
||||
private var muteGates: [ParameterNode] = []
|
||||
|
||||
/// Per-track mute state (`true` = muted).
|
||||
private var trackMuted: [Bool] = []
|
||||
|
||||
/// Non-looping recorder for track A's length-defining first take.
|
||||
private var masterRecorder: RecordBuffer.Audio?
|
||||
|
||||
@@ -350,6 +357,9 @@ public final class LooperPedal: Pedal {
|
||||
let gate: ParameterNode = ParameterNode(0.0)
|
||||
overdubGates.append(gate)
|
||||
|
||||
let muteGate: ParameterNode = ParameterNode(1.0) // 1 = audible
|
||||
muteGates.append(muteGate)
|
||||
|
||||
let overdub: RecordBuffer.Audio = RecordBuffer.Audio(
|
||||
input: dry,
|
||||
buffer: buffer,
|
||||
@@ -385,17 +395,19 @@ public final class LooperPedal: Pedal {
|
||||
masterRecorder = master
|
||||
|
||||
trackHasContent = [Bool](repeating: false, count: LooperPedal.trackCount)
|
||||
trackMuted = [Bool](repeating: false, count: LooperPedal.trackCount)
|
||||
|
||||
// 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)
|
||||
|
||||
// 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]
|
||||
// Sum all track players, each scaled by its smoothed per-track mute gate. 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] * Lag.Control(input: muteGates[0], time: $crossfadeTime)
|
||||
for i: Int in 1 ..< players.count {
|
||||
loopSum = loopSum + players[i]
|
||||
loopSum = loopSum + players[i] * Lag.Control(input: muteGates[i], time: $crossfadeTime)
|
||||
}
|
||||
|
||||
// The clean (dry) signal always passes through at full level; the loop bank is added on
|
||||
@@ -417,9 +429,33 @@ public final class LooperPedal: Pedal {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selects the active track (the one Loop records / overdubs into). Tapping a timeline dot
|
||||
/// calls this. Only track A is selectable while clear. Selecting a new track ends any overdub
|
||||
/// on the previous one (it drops to playback); the new track records nothing until Loop.
|
||||
/// Handles a tap on a track dot: selects the track, or — when it is already the selected track
|
||||
/// and holds recorded material — toggles its mute. So a first tap focuses a track (to overdub
|
||||
/// or record it), and a second tap on that same recorded track mutes/unmutes it.
|
||||
public func tapTrack(_ index: Int) {
|
||||
guard index >= 0, index < LooperPedal.trackCount, !buffers.isEmpty else { return }
|
||||
if index == selectedTrack, trackHasContent(index) {
|
||||
toggleTrackMute(index)
|
||||
} else {
|
||||
selectTrack(index)
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` if track `index` is currently muted.
|
||||
public func isTrackMuted(_ index: Int) -> Bool {
|
||||
index >= 0 && index < trackMuted.count && trackMuted[index]
|
||||
}
|
||||
|
||||
/// Toggles a recorded track's playback mute (smoothed via `crossfadeTime`).
|
||||
private func toggleTrackMute(_ index: Int) {
|
||||
guard trackMuted.indices.contains(index), muteGates.indices.contains(index) else { return }
|
||||
trackMuted[index].toggle()
|
||||
muteGates[index].value = trackMuted[index] ? 0.0 : 1.0
|
||||
}
|
||||
|
||||
/// Selects the active track (the one Loop records / overdubs into). Only track A is selectable
|
||||
/// while clear. Selecting a new track ends any overdub on the previous one (it drops to
|
||||
/// playback); the new track records nothing until Loop.
|
||||
public func selectTrack(_ index: Int) {
|
||||
guard index >= 0, index < LooperPedal.trackCount, index != selectedTrack, !buffers.isEmpty else { return }
|
||||
switch phase {
|
||||
@@ -566,6 +602,12 @@ public final class LooperPedal: Pedal {
|
||||
for i: Int in trackHasContent.indices {
|
||||
trackHasContent[i] = false
|
||||
}
|
||||
for i: Int in trackMuted.indices {
|
||||
trackMuted[i] = false
|
||||
}
|
||||
for gate: ParameterNode in muteGates {
|
||||
gate.value = 1.0
|
||||
}
|
||||
selectedTrack = 0
|
||||
overdubbingTrack = nil
|
||||
masterLength = 0
|
||||
@@ -596,8 +638,10 @@ public final class LooperPedal: Pedal {
|
||||
players.removeAll()
|
||||
overdubRecorders.removeAll()
|
||||
overdubGates.removeAll()
|
||||
muteGates.removeAll()
|
||||
masterRecorder = nil
|
||||
trackHasContent = []
|
||||
trackMuted = []
|
||||
selectedTrack = 0
|
||||
overdubbingTrack = nil
|
||||
masterLength = 0
|
||||
|
||||
Reference in New Issue
Block a user