eafc68d283
Harmonizer: two granular PitchShift voices at fixed musical intervals (ratio 2^(semitones/12) via Exp), mixed under the dry signal with V1/V2/ Direct level knobs. Two interval "knob pickers" snap through octave, fifth, fourth, and minor/major third and sixth above and below. New reusable control: - PedalSelectorKnob (model) + PedalSelectorKnobView (rotary knob that snaps to labelled stops; drag up/down to step, shows the stop caption). - Pedal.effectSelectors hook; PedalView renders a selector row. - PedalState.selectorValues for preset round-trip (forward-compatible). Registered + PedalType.harmonizer + enclosure color + palette slot. Tests: build/non-silent, interval-change-changes-output, selector preset round-trip, registry. Full suite 213 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.5 KiB
Swift
69 lines
2.5 KiB
Swift
// PedalSelectorKnob.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdUI
|
|
|
|
/// A UI-agnostic description of a knob that snaps to a fixed set of labelled stops.
|
|
///
|
|
/// Where ``PedalKnob`` is a continuous rotary and ``PedalSwitch`` is a segmented strip, a
|
|
/// `PedalSelectorKnob` reads like a rotary knob but quantises to discrete positions — a knob picker.
|
|
/// Dragging rotates through the stops; the knob shows the current stop's caption. A `Pedal`
|
|
/// publishes an array of these via ``Pedal/effectSelectors`` so a generic pedalboard UI can render
|
|
/// a stepped knob per discrete parameter without knowing the concrete type.
|
|
///
|
|
/// Each stop pairs a short caption with the exact `Double` written to the live ``UIParamNode`` when
|
|
/// that position is selected; the lit position is the stop whose `value` is nearest the node's
|
|
/// current value.
|
|
public struct PedalSelectorKnob {
|
|
|
|
/// One labelled position of a ``PedalSelectorKnob``.
|
|
public struct Stop {
|
|
|
|
/// Short caption shown under the knob when this position is selected (e.g. "M3", "Oct").
|
|
public let title: String
|
|
|
|
/// Value written to the node when this position is selected.
|
|
public let value: Double
|
|
|
|
/// Creates a selector stop.
|
|
///
|
|
/// - Parameters:
|
|
/// - title: Short caption shown when this position is selected.
|
|
/// - value: Value written to the node when this position is selected.
|
|
public init(title: String, value: Double) {
|
|
self.title = title
|
|
self.value = value
|
|
}
|
|
}
|
|
|
|
/// Short label shown beneath the knob (e.g. "Voice 1").
|
|
public let label: String
|
|
|
|
/// The live parameter node the knob reads and writes. Pass `pedal.$paramName`.
|
|
public let node: UIParamNode
|
|
|
|
/// Ordered stops the knob snaps through, from fully counter-clockwise to fully clockwise. Must
|
|
/// contain at least two.
|
|
public let stops: [Stop]
|
|
|
|
/// Creates a selector-knob descriptor.
|
|
///
|
|
/// - Parameters:
|
|
/// - label: Short label shown beneath the knob.
|
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property (`pedal.$voice1`, …).
|
|
/// - stops: Ordered stops, CCW → CW. At least two.
|
|
public init(
|
|
label: String,
|
|
node: UIParamNode,
|
|
stops: [Stop]
|
|
) {
|
|
precondition(stops.count >= 2, "PedalSelectorKnob requires at least two stops")
|
|
self.label = label
|
|
self.node = node
|
|
self.stops = stops
|
|
}
|
|
}
|