Release 2.1.0: tempo-synced pedal parameters, editable BPM, control mapping badges

Tempo sync
- Lock a delay time or modulation LFO rate to a note division (whole..sixteenth,
  dotted, triplet) of the shared clock. Value is derived from the tempo and follows
  tap tempo, the stepper, the editable BPM field, and MIDI.
- Delay time: Delay, FeedbackDelay, PingPong, ReverseDelay, MultiTap (per tap).
  LFO rate (inverse mapping): Tremolo, Vibrato, Chorus, Flanger, Phaser, Modulation.
- Core types NoteDivision / TempoSync / TempoSyncableParam; Pedal.tempoSyncableParams /
  tempoSync / applyTempoSync / setSync; ShoeGaze.setBpm broadcast recomputes all pedals;
  tempoSync persisted in PedalState (lenient decode) and recomputed on load + recall.
- Observable TempoSyncRevision so the sync badge refreshes on any state-change path.

UI
- Division picker with drawn music-notation glyphs (NoteGlyphView + rasterized cache):
  noteheads, stems, flags, augmentation dot, bracketed 3 for triplets. Presented as a
  height-capped popover so it stays on-screen on iOS.
- Editable BPM text field: integer-only, live-filtered, clamped 30-300, commit on
  return / Done / blur.
- Divisions that clamp at the current tempo are disabled in the picker; an active
  clamped sync shows a warning marker.
- In-context control mapping badges (PC / CC / KEY) per pedal control, with a legend.

Delays
- Maximum delay time raised to 5 s across the delay pedals (was 1-2 s).

Docs: CHANGELOG.md, RELEASES.md, docs/plans/2.2-tempo-synced-parameters.md.
All 454 tests pass; passed lyrebird_external_review (RT-safe, main-thread param writes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 08:47:22 -07:00
parent a33d5488c9
commit 2772abdc56
32 changed files with 1812 additions and 33 deletions
+80 -8
View File
@@ -22,6 +22,11 @@ public struct TempoView: View {
private static let minBpm: Double = 30.0
private static let maxBpm: Double = 300.0
private static let bpmStep: Double = 1.0
/// Width of the editable BPM text field — fits three digits at the readout font.
private static let bpmFieldWidth: CGFloat = 44
private static let bpmFontSize: CGFloat = 18
/// Maximum digits accepted in the BPM field (max 300 BPM is three digits).
private static let bpmMaxDigits: Int = 3
private static let rowSpacing: CGFloat = 10
// Metronome track: a dot swings wall-to-wall once per beat, pausing at each wall (the beat)
@@ -56,12 +61,18 @@ public struct TempoView: View {
/// Continuous beat position, polled from the clock; drives the metronome dot.
@State private var beat: Double = 0.0
/// The editable BPM text. Kept in sync with `displayedBpm` while the field isn't focused; on
/// commit it is validated (integer only), clamped to `[minBpm, maxBpm]`, and applied.
@State private var bpmText: String
@FocusState private var bpmFieldFocused: Bool
// MARK: - Init
/// - Parameter shoeGaze: The session whose ``ShoeGaze/clock`` this view displays and drives.
public init(shoeGaze: ShoeGaze) {
self.shoeGaze = shoeGaze
self._displayedBpm = State(initialValue: shoeGaze.clock.bpm)
self._bpmText = State(initialValue: String(Int(shoeGaze.clock.bpm.rounded())))
}
// MARK: - Body
@@ -78,18 +89,12 @@ public struct TempoView: View {
if shoeGaze.tempoEnabled {
metronome
Text("\(Int(displayedBpm.rounded())) BPM")
.font(.system(size: 18, weight: .semibold, design: .rounded))
.foregroundStyle(Color.white)
bpmField
Stepper(
"",
value: Binding(
get: { displayedBpm },
set: { newValue in
let clamped: Double = min(max(newValue, TempoView.minBpm), TempoView.maxBpm)
shoeGaze.clock.bpm = clamped
displayedBpm = clamped
}
set: { newValue in applyBpm(newValue) }
),
in: TempoView.minBpm ... TempoView.maxBpm,
step: TempoView.bpmStep
@@ -106,11 +111,78 @@ public struct TempoView: View {
while shoeGaze.tempoEnabled && !Task.isCancelled {
beat = shoeGaze.clock.currentBeat
displayedBpm = shoeGaze.clock.bpm
// Don't overwrite the field mid-edit — only reflect external tempo changes when the
// field isn't focused (tap tempo, stepper, MIDI, rig load).
if !bpmFieldFocused {
bpmText = String(Int(displayedBpm.rounded()))
}
try? await Task.sleep(nanoseconds: TempoView.pollIntervalNanoseconds)
}
}
}
// MARK: - BPM field
/// Editable BPM readout. Accepts integer input, validated and clamped on commit (Return, or the
/// keyboard's Done, or focus loss). Non-numeric or empty input reverts to the current tempo.
private var bpmField: some View {
HStack(spacing: TempoView.rowSpacing / 2) {
TextField("", text: $bpmText)
.textFieldStyle(.plain)
.multilineTextAlignment(.trailing)
.font(.system(size: TempoView.bpmFontSize, weight: .semibold, design: .rounded))
.foregroundStyle(Color.white)
.frame(width: TempoView.bpmFieldWidth)
.fixedSize()
.focused($bpmFieldFocused)
.onSubmit { commitBpm() }
#if os(iOS)
.keyboardType(.numberPad)
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") { bpmFieldFocused = false }
}
}
#endif
Text("BPM")
.font(.system(size: TempoView.bpmFontSize, weight: .semibold, design: .rounded))
.foregroundStyle(Color.white)
}
.onChange(of: bpmText) { _, newValue in
// Reject non-numeric input as it is typed, and cap at three digits (max 300 BPM).
let filtered: String = String(newValue.filter { $0.isNumber }.prefix(TempoView.bpmMaxDigits))
if filtered != newValue {
bpmText = filtered
}
}
.onChange(of: bpmFieldFocused) { _, focused in
// Commit when focus leaves the field (tap away / Done), the counterpart to onSubmit.
if !focused {
commitBpm()
}
}
}
/// Validates and applies the typed BPM: integers only, clamped to `[minBpm, maxBpm]`. Non-numeric
/// or empty input reverts the field to the current tempo without changing it.
private func commitBpm() {
let digits: String = bpmText.filter { $0.isNumber }
if let value: Int = Int(digits) {
applyBpm(Double(value))
} else {
bpmText = String(Int(displayedBpm.rounded()))
}
}
/// Clamps `bpm` to the allowed range, applies it to the session, and syncs the field text.
private func applyBpm(_ bpm: Double) {
let clamped: Double = min(max(bpm, TempoView.minBpm), TempoView.maxBpm)
shoeGaze.setBpm(clamped)
displayedBpm = clamped
bpmText = String(Int(clamped.rounded()))
}
// MARK: - Subviews
/// Horizontal pendulum: the dot maps `beat` through a cosine so it eases to a stop at each