Looper: multi-slot + timeline + stop/cue-stop, quantized transport
Checkpoint before the multitrack redesign. Adds 4 loop slots (one player swapped via setBuffer), a play-head timeline with A/B/C/D dots, Loop/Stop/ Cue Stop/Reverse stomp toggles below the knobs, beat-quantized transport, overdub undo, reverse, and feedback-decay overdub — all reviewed for RT safety (transportGeneration guards on deferred beat/undo/cue callbacks). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,14 @@ struct LooperTimelineView: View {
|
||||
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"]
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -40,6 +48,9 @@ struct LooperTimelineView: View {
|
||||
@State private var state: LooperTransportState = .empty
|
||||
@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 stopArmed: Bool = false
|
||||
|
||||
init(pedal: LooperPedal) {
|
||||
self.pedal = pedal
|
||||
@@ -52,6 +63,8 @@ struct LooperTimelineView: View {
|
||||
HStack(spacing: LooperTimelineView.sectionSpacing) {
|
||||
stateBadge
|
||||
Spacer(minLength: 0)
|
||||
slotDots
|
||||
Spacer(minLength: 0)
|
||||
lengthLabel
|
||||
}
|
||||
track
|
||||
@@ -63,6 +76,9 @@ struct LooperTimelineView: View {
|
||||
state = pedal.transportState
|
||||
lengthSeconds = pedal.loopLengthSeconds
|
||||
lengthBeats = pedal.loopLengthBeats
|
||||
activeSlot = pedal.activeSlotIndex
|
||||
slotContent = (0 ..< LooperPedal.slotCount).map { pedal.slotHasContent($0) }
|
||||
stopArmed = pedal.isStopAtLoopEndArmed
|
||||
try? await Task.sleep(nanoseconds: LooperTimelineView.pollIntervalNanoseconds)
|
||||
}
|
||||
}
|
||||
@@ -70,6 +86,29 @@ 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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var stateBadge: some View {
|
||||
HStack(spacing: LooperTimelineView.badgeInnerSpacing) {
|
||||
Circle()
|
||||
@@ -78,6 +117,11 @@ struct LooperTimelineView: View {
|
||||
Text(stateText)
|
||||
.font(.system(size: LooperTimelineView.labelFontSize, weight: .semibold, design: .monospaced))
|
||||
.foregroundStyle(Color.white)
|
||||
if stopArmed {
|
||||
Text("→END")
|
||||
.font(.system(size: LooperTimelineView.labelFontSize, weight: .semibold, design: .monospaced))
|
||||
.foregroundStyle(Color.orange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +166,7 @@ struct LooperTimelineView: View {
|
||||
case .armedRecord, .armedStop: return Color.orange
|
||||
case .recording: return Color.red
|
||||
case .playing: return Color.green
|
||||
case .stopped: return Color.orange
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +177,7 @@ struct LooperTimelineView: View {
|
||||
case .recording: return "REC"
|
||||
case .armedStop: return "END"
|
||||
case .playing: return "PLAY"
|
||||
case .stopped: return "STOP"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,21 @@ public struct PedalButtonView: View {
|
||||
public var body: some View {
|
||||
switch pedalButton.style {
|
||||
case .momentary:
|
||||
ParameterButton(pedalButton.label, action: pedalButton.action ?? {})
|
||||
if let indicator: UIParamNode = pedalButton.indicator {
|
||||
// LED + footswitch, same look as a toggle, but the press runs an action and the
|
||||
// LED reflects a separate state node (e.g. Stop lit while stopped). Reading
|
||||
// `indicator.value` registers this view for @Observable re-render.
|
||||
let isOn: Bool = indicator.value >= PedalButtonView.toggleOnThreshold
|
||||
VStack(spacing: PedalButtonView.sectionSpacing) {
|
||||
LEDIndicator(isOn: isOn)
|
||||
FootswitchButton(action: pedalButton.action ?? {})
|
||||
Text(pedalButton.label)
|
||||
.font(.system(size: PedalButtonView.captionFontSize))
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
} else {
|
||||
ParameterButton(pedalButton.label, action: pedalButton.action ?? {})
|
||||
}
|
||||
case .toggle:
|
||||
if let node: UIParamNode = pedalButton.node {
|
||||
// Reading `node.value` registers this view for @Observable re-render.
|
||||
|
||||
@@ -132,9 +132,10 @@ struct LEDIndicator: View {
|
||||
|
||||
// MARK: - Footswitch
|
||||
|
||||
/// A round footswitch-style button that flips a `UIParamNode` between `0` and `1`.
|
||||
/// `internal` (not `private`) so other views in this module (e.g. `PedalButtonView`) can
|
||||
/// reuse the same stompbox footswitch look for non-bypass toggles.
|
||||
/// A round footswitch-style button. Either flips a bound `UIParamNode` between `0` and `1`
|
||||
/// (toggle) or runs an arbitrary action (momentary) — both render the identical stompbox look.
|
||||
/// `internal` (not `private`) so other views in this module (e.g. `PedalButtonView`) can reuse
|
||||
/// it for non-bypass toggles and momentary stomp actions.
|
||||
struct FootswitchButton: View {
|
||||
|
||||
private static let diameter: CGFloat = 44
|
||||
@@ -144,14 +145,23 @@ struct FootswitchButton: View {
|
||||
private static let ringBrightness: Double = 0.50
|
||||
private static let innerFillBrightness: Double = 0.25
|
||||
|
||||
let node: UIParamNode
|
||||
private let action: () -> Void
|
||||
|
||||
/// Flips `node` between `0` and `1` on each press.
|
||||
init(node: UIParamNode) {
|
||||
self.action = {
|
||||
let engaged: Bool = node.value < 0.5
|
||||
node.update(engaged ? 1.0 : 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs `action` on each press (momentary).
|
||||
init(action: @escaping () -> Void) {
|
||||
self.action = action
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
let engaged: Bool = node.value < 0.5
|
||||
// Toggle: engaged (0) → bypassed (1) and vice-versa.
|
||||
node.update(engaged ? 1.0 : 0.0)
|
||||
}) {
|
||||
Button(action: action) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(white: FootswitchButton.outerFillBrightness))
|
||||
@@ -207,6 +217,8 @@ public struct PedalView: View {
|
||||
private static let enclosurePadding: CGFloat = 14
|
||||
private static let screwInset: CGFloat = 6
|
||||
private static let knobColumnCount: Int = 3
|
||||
/// Knob columns for a double-width pedal card (fits a four-knob effect bank on one row).
|
||||
private static let wideKnobColumnCount: Int = 4
|
||||
private static let knobSpacing: CGFloat = 10
|
||||
/// Horizontal gap between knobs within a row. Wider than `knobSpacing` so centred
|
||||
/// rows keep a comfortable, touch-friendly gap between adjacent knobs.
|
||||
@@ -297,6 +309,7 @@ public struct PedalView: View {
|
||||
knobGrid
|
||||
selectorRow
|
||||
switchRow
|
||||
transportButtonRow
|
||||
buttonRow
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
@@ -367,24 +380,25 @@ public struct PedalView: View {
|
||||
/// `Level` on the left, `Mix` on the right — leaving more room for the effect controls
|
||||
/// at the top and giving every pedal a symmetric footer.
|
||||
private var knobGrid: some View {
|
||||
// Wide (double-width) pedals fit four knobs across, so a four-knob effect bank (e.g.
|
||||
// the looper's Crossfade / Playback / Overdub / Feedback) sits on one row.
|
||||
let columns: Int = pedal.widthUnits >= 2 ? PedalView.wideKnobColumnCount : PedalView.knobColumnCount
|
||||
let knobs: [PedalKnob] = Array(pedal.knobs.dropLast(2))
|
||||
let rows: [[PedalKnob]] = stride(
|
||||
from: 0,
|
||||
to: knobs.count,
|
||||
by: PedalView.knobColumnCount
|
||||
by: columns
|
||||
).map { startIndex in
|
||||
Array(knobs[startIndex ..< min(startIndex + PedalView.knobColumnCount, knobs.count)])
|
||||
Array(knobs[startIndex ..< min(startIndex + columns, knobs.count)])
|
||||
}
|
||||
|
||||
return VStack(spacing: PedalView.knobSpacing) {
|
||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||
let row: [PedalKnob] = rowPair.element
|
||||
// Centre each row: a short row (one or two knobs) sits centred in the
|
||||
// enclosure rather than left-aligned. Symmetric spacers also centre a full
|
||||
// three-knob row, so every row stays horizontally centred.
|
||||
// A full three-knob row keeps the tight spacing so it fits the enclosure;
|
||||
// Centre each row: a short row sits centred in the enclosure rather than
|
||||
// left-aligned. A full row keeps the tight spacing so it fits the enclosure;
|
||||
// shorter centred rows use a wider, touch-friendly gap.
|
||||
let rowItemSpacing: CGFloat = row.count >= PedalView.knobColumnCount
|
||||
let rowItemSpacing: CGFloat = row.count >= columns
|
||||
? PedalView.knobSpacing
|
||||
: PedalView.knobRowItemSpacing
|
||||
HStack(spacing: rowItemSpacing) {
|
||||
@@ -430,8 +444,26 @@ public struct PedalView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Row of stomp-style action buttons drawn from `pedal.effectButtons`, beneath the
|
||||
/// switch row. Renders nothing when the pedal publishes no buttons.
|
||||
/// Transport-control row drawn from `pedal.effectTransportButtons`, placed directly below
|
||||
/// the knobs so persistent state toggles and transport stops (e.g. the looper's Loop /
|
||||
/// Stop / Cue Stop / Reverse) sit apart from the momentary actions. Renders nothing when
|
||||
/// the pedal publishes no transport buttons.
|
||||
@ViewBuilder
|
||||
private var transportButtonRow: some View {
|
||||
let buttons: [PedalButton] = pedal.effectTransportButtons
|
||||
if !buttons.isEmpty {
|
||||
HStack(alignment: .top, spacing: PedalView.knobRowItemSpacing) {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(buttons.enumerated()), id: \.offset) { pair in
|
||||
PedalButtonView(pair.element)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Row of momentary stomp-style action buttons drawn from `pedal.effectButtons`, beneath
|
||||
/// the transport row. Renders nothing when the pedal publishes no buttons.
|
||||
@ViewBuilder
|
||||
private var buttonRow: some View {
|
||||
let buttons: [PedalButton] = pedal.effectButtons
|
||||
|
||||
Reference in New Issue
Block a user