Looper: multitrack redesign with smart Loop footswitch
Replace the one-at-a-time slot model with a synchronized multitrack looper: four track players summed to one output, track A's first take defining the master loop length, and tracks B–D recorded as phase-locked overdub layers on the same grid (overdub recorders run continuously while playing, reset to the top at play-start, gated per-track by recLevel so only the selected track layers new input — instant, drift-free overdub toggles). A single smart Loop footswitch drives the whole transport by state: record A → set end (quantized) → auto-overdub on wrap → toggle overdub/play; B–D toggle overdub aligned to A's play-head. Selecting a track ends the prior overdub. Stop / Cue Stop pause; Loop resumes. Reset returns to clear. UI: transport row is now Loop / Stop / Cue Stop / Reverse / Reset; the old action row is replaced by a one-line state indicator; the A/B/C/D timeline dots are tappable to select a track; every stomp button shows a live caption of what its next press does (Record → Set End → Overdub → Play, etc.). Overdub-undo dropped. All transport routines keep the transportGeneration guard on deferred beat/stop callbacks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
import SwiftUI
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
/// The looper's loop timeline: a transport-state label, a loop-length read-out, and a track
|
||||
/// with a sweeping play-head. Rendered inside the double-width ``PedalView`` for a `LooperPedal`.
|
||||
/// The looper's loop timeline: a transport-state badge, tappable A–D track dots, a loop-length
|
||||
/// read-out, a sweeping play-head track, and a one-line state indicator describing what the
|
||||
/// pedal is doing. Rendered inside the double-width ``PedalView`` for a `LooperPedal`.
|
||||
///
|
||||
/// `LooperPedal`'s transport state is plain (non-`@Observable`) RT-adjacent data, so this view
|
||||
/// polls it on a `.task` loop — the same convention as `TempoView`'s clock read-out — rather
|
||||
/// than relying on SwiftUI change tracking.
|
||||
/// polls it on a `.task` loop — the same convention as `TempoView`'s clock read-out.
|
||||
struct LooperTimelineView: View {
|
||||
|
||||
// MARK: - Constants
|
||||
@@ -29,28 +29,32 @@ struct LooperTimelineView: View {
|
||||
private static let ledDiameter: CGFloat = 9
|
||||
private static let badgeInnerSpacing: CGFloat = 4
|
||||
private static let lengthLabelOpacity: Double = 0.75
|
||||
private static let emptyLedBrightness: Double = 0.3
|
||||
private static let borderLineWidth: CGFloat = 1
|
||||
private static let slotDotSpacing: CGFloat = 4
|
||||
private static let slotDotDiameter: CGFloat = 18
|
||||
private static let slotLabelFontSize: CGFloat = 10
|
||||
private static let slotDotBrightness: Double = 0.16
|
||||
private static let slotFilledOpacity: Double = 0.55
|
||||
private static let slotEmptyOpacity: Double = 0.45
|
||||
private static let slotActiveRingWidth: CGFloat = 1.5
|
||||
private static let slotLabels: [String] = ["A", "B", "C", "D", "E", "F", "G", "H"]
|
||||
private static let dotSpacing: CGFloat = 4
|
||||
private static let dotDiameter: CGFloat = 18
|
||||
private static let dotLabelFontSize: CGFloat = 10
|
||||
private static let dotBrightness: Double = 0.16
|
||||
private static let dotFilledOpacity: Double = 0.55
|
||||
private static let dotEmptyOpacity: Double = 0.45
|
||||
private static let activeRingWidth: CGFloat = 1.5
|
||||
private static let indicatorFontSize: CGFloat = 11
|
||||
private static let indicatorOpacity: Double = 0.85
|
||||
private static let overdubRingColor: Color = Color.red
|
||||
private static let dotLabels: [String] = ["A", "B", "C", "D", "E", "F", "G", "H"]
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let pedal: LooperPedal
|
||||
|
||||
@State private var position: Double?
|
||||
@State private var state: LooperTransportState = .empty
|
||||
@State private var state: LooperTransportState = .clear
|
||||
@State private var lengthSeconds: Double = 0.0
|
||||
@State private var lengthBeats: Double = 0.0
|
||||
@State private var activeSlot: Int = 0
|
||||
@State private var slotContent: [Bool] = Array(repeating: false, count: LooperPedal.slotCount)
|
||||
@State private var selectedTrack: Int = 0
|
||||
@State private var overdubbingTrack: Int?
|
||||
@State private var trackContent: [Bool] = Array(repeating: false, count: LooperPedal.trackCount)
|
||||
@State private var stopArmed: Bool = false
|
||||
@State private var stateDescription: String = ""
|
||||
|
||||
init(pedal: LooperPedal) {
|
||||
self.pedal = pedal
|
||||
@@ -63,22 +67,24 @@ struct LooperTimelineView: View {
|
||||
HStack(spacing: LooperTimelineView.sectionSpacing) {
|
||||
stateBadge
|
||||
Spacer(minLength: 0)
|
||||
slotDots
|
||||
trackDots
|
||||
Spacer(minLength: 0)
|
||||
lengthLabel
|
||||
}
|
||||
track
|
||||
stateIndicator
|
||||
}
|
||||
.task {
|
||||
// Poll the pedal's transport read-outs; it isn't @Observable (RT-adjacent state).
|
||||
while !Task.isCancelled {
|
||||
position = pedal.playbackPosition01()
|
||||
state = pedal.transportState
|
||||
lengthSeconds = pedal.loopLengthSeconds
|
||||
lengthBeats = pedal.loopLengthBeats
|
||||
activeSlot = pedal.activeSlotIndex
|
||||
slotContent = (0 ..< LooperPedal.slotCount).map { pedal.slotHasContent($0) }
|
||||
selectedTrack = pedal.selectedTrackIndex
|
||||
overdubbingTrack = pedal.overdubbingTrackIndex
|
||||
trackContent = (0 ..< LooperPedal.trackCount).map { pedal.trackHasContent($0) }
|
||||
stopArmed = pedal.isStopAtLoopEndArmed
|
||||
stateDescription = pedal.stateDescription
|
||||
try? await Task.sleep(nanoseconds: LooperTimelineView.pollIntervalNanoseconds)
|
||||
}
|
||||
}
|
||||
@@ -86,25 +92,32 @@ struct LooperTimelineView: View {
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
/// One labelled dot per slot: filled when it holds a loop, ringed when it is the active slot.
|
||||
private var slotDots: some View {
|
||||
HStack(spacing: LooperTimelineView.slotDotSpacing) {
|
||||
ForEach(0 ..< LooperPedal.slotCount, id: \.self) { index in
|
||||
let isActive: Bool = index == activeSlot
|
||||
let hasContent: Bool = index < slotContent.count && slotContent[index]
|
||||
Text(LooperTimelineView.slotLabels[index])
|
||||
.font(.system(size: LooperTimelineView.slotLabelFontSize,
|
||||
weight: .bold, design: .monospaced))
|
||||
.foregroundStyle(hasContent ? Color.white : Color.white.opacity(LooperTimelineView.slotEmptyOpacity))
|
||||
.frame(width: LooperTimelineView.slotDotDiameter, height: LooperTimelineView.slotDotDiameter)
|
||||
.background(
|
||||
Circle().fill(hasContent ? Color.green.opacity(LooperTimelineView.slotFilledOpacity)
|
||||
: Color(white: LooperTimelineView.slotDotBrightness))
|
||||
)
|
||||
.overlay(
|
||||
Circle().stroke(isActive ? Color.white : Color.clear,
|
||||
lineWidth: LooperTimelineView.slotActiveRingWidth)
|
||||
)
|
||||
/// One tappable labelled dot per track: filled when it holds a loop, white-ringed when
|
||||
/// selected, red-ringed while overdubbing. Tapping selects the track.
|
||||
private var trackDots: some View {
|
||||
HStack(spacing: LooperTimelineView.dotSpacing) {
|
||||
ForEach(0 ..< LooperPedal.trackCount, id: \.self) { index in
|
||||
let isSelected: Bool = index == selectedTrack
|
||||
let isOverdub: Bool = index == overdubbingTrack
|
||||
let hasContent: Bool = index < trackContent.count && trackContent[index]
|
||||
Button {
|
||||
pedal.selectTrack(index)
|
||||
} label: {
|
||||
Text(LooperTimelineView.dotLabels[index])
|
||||
.font(.system(size: LooperTimelineView.dotLabelFontSize, weight: .bold, design: .monospaced))
|
||||
.foregroundStyle(hasContent ? Color.white : Color.white.opacity(LooperTimelineView.dotEmptyOpacity))
|
||||
.frame(width: LooperTimelineView.dotDiameter, height: LooperTimelineView.dotDiameter)
|
||||
.background(
|
||||
Circle().fill(hasContent ? Color.green.opacity(LooperTimelineView.dotFilledOpacity)
|
||||
: Color(white: LooperTimelineView.dotBrightness))
|
||||
)
|
||||
.overlay(
|
||||
Circle().stroke(isOverdub ? LooperTimelineView.overdubRingColor
|
||||
: (isSelected ? Color.white : Color.clear),
|
||||
lineWidth: LooperTimelineView.activeRingWidth)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +144,14 @@ struct LooperTimelineView: View {
|
||||
.foregroundStyle(Color.white.opacity(LooperTimelineView.lengthLabelOpacity))
|
||||
}
|
||||
|
||||
/// One-line description of what the pedal is doing now — replaces the old action-button row.
|
||||
private var stateIndicator: some View {
|
||||
Text(stateDescription)
|
||||
.font(.system(size: LooperTimelineView.indicatorFontSize, weight: .medium))
|
||||
.foregroundStyle(Color.white.opacity(LooperTimelineView.indicatorOpacity))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
private var track: some View {
|
||||
GeometryReader { geometry in
|
||||
let width: CGFloat = geometry.size.width
|
||||
@@ -143,7 +164,6 @@ struct LooperTimelineView: View {
|
||||
.stroke(Color.white.opacity(LooperTimelineView.trackBorderOpacity),
|
||||
lineWidth: LooperTimelineView.borderLineWidth)
|
||||
)
|
||||
// Filled region up to the play-head, only while playing.
|
||||
if position != nil {
|
||||
RoundedRectangle(cornerRadius: LooperTimelineView.trackCornerRadius)
|
||||
.fill(Color.white.opacity(LooperTimelineView.filledOpacity))
|
||||
@@ -162,22 +182,22 @@ struct LooperTimelineView: View {
|
||||
|
||||
private var stateColor: Color {
|
||||
switch state {
|
||||
case .empty: return Color(white: LooperTimelineView.emptyLedBrightness)
|
||||
case .armedRecord, .armedStop: return Color.orange
|
||||
case .recording: return Color.red
|
||||
case .playing: return Color.green
|
||||
case .stopped: return Color.orange
|
||||
case .clear: return Color(white: 0.3)
|
||||
case .armedRecord, .armedClose: return Color.orange
|
||||
case .recordingMaster: return Color.red
|
||||
case .playing: return Color.green
|
||||
case .stopped: return Color.orange
|
||||
}
|
||||
}
|
||||
|
||||
private var stateText: String {
|
||||
switch state {
|
||||
case .empty: return "EMPTY"
|
||||
case .armedRecord: return "ARM"
|
||||
case .recording: return "REC"
|
||||
case .armedStop: return "END"
|
||||
case .playing: return "PLAY"
|
||||
case .stopped: return "STOP"
|
||||
case .clear: return "CLEAR"
|
||||
case .armedRecord: return "ARM"
|
||||
case .recordingMaster: return "REC"
|
||||
case .armedClose: return "END"
|
||||
case .playing: return "PLAY"
|
||||
case .stopped: return "STOP"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user