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:
@@ -180,6 +180,189 @@ struct FootswitchButton: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Tempo-sync knob
|
||||
|
||||
/// A knob that can be locked to a note division of the live tempo.
|
||||
///
|
||||
/// When free, it is an ordinary ``ParameterKnob``. A compact menu below the dial lets the user
|
||||
/// pick `Free` or a ``NoteDivision``; once a division is chosen the knob is driven by the tempo
|
||||
/// (its dial shows the derived value but is disabled, since the number is computed). The menu is
|
||||
/// shown only while tempo is enabled — the enclosing view gates on `shoeGazeTempoEnabled`.
|
||||
struct TempoSyncKnobView: View {
|
||||
|
||||
private static let cellSpacing: CGFloat = 4
|
||||
private static let syncedDialOpacity: Double = 0.55
|
||||
private static let menuFontSize: CGFloat = 10
|
||||
private static let labelGlyphSpacing: CGFloat = 3
|
||||
private static let warningIconSize: CGFloat = 8
|
||||
/// Height of the glyph in the collapsed menu button, and of the whole menu row, so the row is the
|
||||
/// same height whether it shows the "Free" text or a note glyph — the pedal card never grows.
|
||||
private static let labelGlyphHeight: CGFloat = 18
|
||||
private static let menuRowHeight: CGFloat = 20
|
||||
private static let freeKey: String = "free"
|
||||
|
||||
// Division-picker popover: a height-capped scroll list the system keeps on-screen (it flips
|
||||
// above the button near the bottom edge) rather than a native menu that can run off-screen.
|
||||
private static let pickerMaxHeight: CGFloat = 260
|
||||
private static let pickerGlyphHeight: CGFloat = 22
|
||||
private static let pickerRowSpacing: CGFloat = 2
|
||||
private static let pickerPadding: CGFloat = 8
|
||||
private static let pickerRowMinWidth: CGFloat = 84
|
||||
private static let checkmarkFontSize: CGFloat = 11
|
||||
|
||||
let pedal: Pedal
|
||||
let knob: PedalKnob
|
||||
let param: TempoSyncableParam
|
||||
|
||||
/// Presentation flag for the division-picker popover.
|
||||
@State private var showDivisionPicker: Bool = false
|
||||
|
||||
var body: some View {
|
||||
// Observe the pedal's sync-revision so the badge refreshes when `tempoSync` changes through
|
||||
// any path — this view's picker, a preset load, or a lightweight recall.
|
||||
let _ = pedal.tempoSyncRevision.value
|
||||
let currentKey: String = keyForCurrentSync()
|
||||
let isSynced: Bool = currentKey != TempoSyncKnobView.freeKey
|
||||
let currentBpm: Double? = pedal.clock?.bpm
|
||||
// Reading the live parameter value subscribes this view to Observation, so a tempo change
|
||||
// (which rewrites the node via `applyTempoSync`) re-renders the clamp warning without polling.
|
||||
let liveValue: Double = param.node.value
|
||||
let activeDivision: NoteDivision? = NoteDivision(rawValue: currentKey)
|
||||
let activeClamped: Bool = {
|
||||
_ = liveValue
|
||||
guard isSynced, let bpm: Double = currentBpm, let division: NoteDivision = activeDivision else {
|
||||
return false
|
||||
}
|
||||
return param.value(for: division, bpm: bpm).clamped
|
||||
}()
|
||||
|
||||
VStack(spacing: TempoSyncKnobView.cellSpacing) {
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.foregroundStyle(Color.white)
|
||||
.disabled(isSynced)
|
||||
.opacity(isSynced ? TempoSyncKnobView.syncedDialOpacity : 1.0)
|
||||
|
||||
Button {
|
||||
showDivisionPicker = true
|
||||
} label: {
|
||||
HStack(spacing: TempoSyncKnobView.labelGlyphSpacing) {
|
||||
if isSynced, let division: NoteDivision = activeDivision {
|
||||
NoteGlyphImageCache.image(for: division)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(height: TempoSyncKnobView.labelGlyphHeight)
|
||||
.accessibilityLabel(Text(labelForKey(currentKey)))
|
||||
} else {
|
||||
Text("Free")
|
||||
.font(.system(size: TempoSyncKnobView.menuFontSize, weight: .semibold, design: .rounded))
|
||||
}
|
||||
if activeClamped {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.font(.system(size: TempoSyncKnobView.warningIconSize))
|
||||
}
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.system(size: TempoSyncKnobView.warningIconSize))
|
||||
.opacity(0.6)
|
||||
}
|
||||
.frame(height: TempoSyncKnobView.menuRowHeight)
|
||||
.foregroundStyle(activeClamped ? Color.orange : Color.white.opacity(isSynced ? 1.0 : 0.65))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.fixedSize()
|
||||
.help(activeClamped
|
||||
? "This note can't be represented at the current tempo — \(knob.label) is clamped to its limit."
|
||||
: "Sync \(knob.label) to the tempo, or set it freely")
|
||||
.popover(isPresented: $showDivisionPicker) {
|
||||
divisionPicker
|
||||
.presentationCompactAdaptation(.popover)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Height-capped, scrollable list of `Free` + every note division. Presented as a popover so the
|
||||
/// system keeps it on-screen (flipping above the button near the bottom edge) and it scrolls when
|
||||
/// taller than ``pickerMaxHeight`` — unlike a native menu, which ran off the bottom on iOS.
|
||||
private var divisionPicker: some View {
|
||||
let currentBpm: Double? = pedal.clock?.bpm
|
||||
let currentKey: String = keyForCurrentSync()
|
||||
return ScrollView {
|
||||
VStack(alignment: .leading, spacing: TempoSyncKnobView.pickerRowSpacing) {
|
||||
pickerRow(
|
||||
key: TempoSyncKnobView.freeKey,
|
||||
glyph: nil,
|
||||
disabled: false,
|
||||
selected: currentKey == TempoSyncKnobView.freeKey
|
||||
)
|
||||
ForEach(NoteDivision.allCases, id: \.self) { division in
|
||||
// A division whose value clamps at the current tempo (e.g. a note longer than the
|
||||
// maximum delay time) can't be represented accurately, so it is shown but disabled.
|
||||
let unavailable: Bool = currentBpm.map { param.value(for: division, bpm: $0).clamped } ?? false
|
||||
pickerRow(
|
||||
key: division.rawValue,
|
||||
glyph: division,
|
||||
disabled: unavailable,
|
||||
selected: currentKey == division.rawValue
|
||||
)
|
||||
}
|
||||
}
|
||||
.padding(TempoSyncKnobView.pickerPadding)
|
||||
}
|
||||
.frame(maxHeight: TempoSyncKnobView.pickerMaxHeight)
|
||||
}
|
||||
|
||||
/// One selectable row in ``divisionPicker`` — a note glyph (or "Free" text), a trailing checkmark
|
||||
/// when it is the current selection, and a disabled state for divisions that clamp at this tempo.
|
||||
@ViewBuilder
|
||||
private func pickerRow(key: String, glyph: NoteDivision?, disabled: Bool, selected: Bool) -> some View {
|
||||
Button {
|
||||
select(key)
|
||||
showDivisionPicker = false
|
||||
} label: {
|
||||
HStack(spacing: TempoSyncKnobView.labelGlyphSpacing) {
|
||||
if let glyph: NoteDivision = glyph {
|
||||
NoteGlyphImageCache.image(for: glyph)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(height: TempoSyncKnobView.pickerGlyphHeight)
|
||||
} else {
|
||||
Text("Free")
|
||||
.font(.system(size: TempoSyncKnobView.menuFontSize, weight: .semibold, design: .rounded))
|
||||
}
|
||||
Spacer(minLength: TempoSyncKnobView.labelGlyphSpacing)
|
||||
if selected {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.system(size: TempoSyncKnobView.checkmarkFontSize, weight: .semibold))
|
||||
}
|
||||
}
|
||||
.frame(minWidth: TempoSyncKnobView.pickerRowMinWidth, alignment: .leading)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(disabled)
|
||||
.accessibilityLabel(Text(glyph?.label ?? "Free"))
|
||||
}
|
||||
|
||||
private func keyForCurrentSync() -> String {
|
||||
if case .division(let division) = pedal.tempoSync[param.key] ?? .free {
|
||||
return division.rawValue
|
||||
}
|
||||
return TempoSyncKnobView.freeKey
|
||||
}
|
||||
|
||||
private func labelForKey(_ key: String) -> String {
|
||||
key == TempoSyncKnobView.freeKey ? "Free" : (NoteDivision(rawValue: key)?.label ?? key)
|
||||
}
|
||||
|
||||
private func select(_ key: String) {
|
||||
// `setSync` bumps `pedal.tempoSyncRevision`, which this view observes — no local flag needed.
|
||||
if key == TempoSyncKnobView.freeKey {
|
||||
pedal.setSync(.free, for: param.key)
|
||||
} else if let division: NoteDivision = NoteDivision(rawValue: key) {
|
||||
pedal.setSync(.division(division), for: param.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PedalView
|
||||
|
||||
/// A stompbox-style enclosure view that renders all controls for a single `Pedal`.
|
||||
@@ -266,6 +449,13 @@ public struct PedalView: View {
|
||||
/// Presentation flag for the pedal info panel (description + control ranges).
|
||||
@State private var showInfo: Bool = false
|
||||
|
||||
/// The rig's control map, injected by the builder so the pedal can draw a mapping strip. `nil`
|
||||
/// when the rig has no bindings (or in contexts that don't set it) — the strip renders nothing.
|
||||
@Environment(\.controlMappingMap) private var controlMappingMap: MIDIMap?
|
||||
|
||||
/// Mirrors ``ShoeGaze/tempoEnabled`` so tempo-sync knob affordances hide when tempo is off.
|
||||
@Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a stompbox pedal view for the given pedal.
|
||||
@@ -355,6 +545,7 @@ public struct PedalView: View {
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
bottomControls
|
||||
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +580,7 @@ public struct PedalView: View {
|
||||
.id(ObjectIdentifier(pedal))
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,12 +714,12 @@ public struct PedalView: View {
|
||||
let rowItemSpacing: CGFloat = row.count >= columns
|
||||
? PedalView.knobSpacing
|
||||
: PedalView.knobRowItemSpacing
|
||||
HStack(spacing: rowItemSpacing) {
|
||||
// Top-align so every dial pins to the row's top edge — a tempo-sync cell grows taller
|
||||
// below the dial (glyph menu, warning) without dragging its neighbours' dials down.
|
||||
HStack(alignment: .top, spacing: rowItemSpacing) {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
||||
let knob: PedalKnob = knobPair.element
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.foregroundStyle(Color.white)
|
||||
knobCell(knobPair.element)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
@@ -535,6 +727,25 @@ public struct PedalView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Renders one effect knob — a tempo-sync knob when the parameter is syncable and tempo is
|
||||
/// enabled, otherwise a plain ``ParameterKnob``. Syncable knobs are matched by node identity
|
||||
/// against `pedal.tempoSyncableParams`.
|
||||
@ViewBuilder
|
||||
private func knobCell(_ knob: PedalKnob) -> some View {
|
||||
if tempoEnabled, let param: TempoSyncableParam = syncableParam(for: knob) {
|
||||
TempoSyncKnobView(pedal: pedal, knob: knob, param: param)
|
||||
} else {
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
|
||||
/// The tempo-syncable descriptor whose parameter node backs `knob`, or `nil` if the knob is
|
||||
/// not syncable. Matched by `UIParamNode` identity so it is robust to label changes.
|
||||
private func syncableParam(for knob: PedalKnob) -> TempoSyncableParam? {
|
||||
pedal.tempoSyncableParams.first { $0.node === knob.node }
|
||||
}
|
||||
|
||||
/// Row of stepped selector knobs drawn from `pedal.effectSelectors`, beneath the knob grid.
|
||||
/// Renders nothing when the pedal publishes no selectors.
|
||||
@ViewBuilder
|
||||
|
||||
Reference in New Issue
Block a user