Add Harmonizer pedal and a stepped selector-knob control
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>
This commit is contained in:
@@ -168,6 +168,15 @@ open class Pedal: SynthesizerBase {
|
||||
[]
|
||||
}
|
||||
|
||||
/// Effect-specific stepped "knob picker" controls for this pedal, rendered as a row of rotary
|
||||
/// knobs that snap to labelled stops, beneath the knob grid.
|
||||
///
|
||||
/// Override in subclasses to publish each discrete `@UIParam` parameter that reads best as a
|
||||
/// knob that snaps through fixed positions (e.g. a harmony interval selector). Defaults to empty.
|
||||
open var effectSelectors: [PedalSelectorKnob] {
|
||||
[]
|
||||
}
|
||||
|
||||
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
||||
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
||||
/// surfaced separately as a header toggle, not as a knob.
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -76,4 +76,5 @@ public extension PedalType {
|
||||
// Pitch & octave
|
||||
static let octaveSplitter = PedalType("Octave Splitter")
|
||||
static let bassOctaver = PedalType("Bass Octaver")
|
||||
static let harmonizer = PedalType("Harmonizer")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
// HarmonizerPedal.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Two-voice diatonic-interval harmonizer.
|
||||
///
|
||||
/// Adds two pitch-shifted harmony voices at fixed musical intervals above or below the input,
|
||||
/// mixed against the dry signal — an OC-2-style level layout (Voice 1 / Voice 2 / Direct) with a
|
||||
/// knob picker selecting each voice's interval.
|
||||
///
|
||||
/// Each voice is a granular `PitchShift` whose ratio is `2^(semitones/12)`, driven live from the
|
||||
/// voice's interval selector. Intervals include minor and major thirds above and below, plus
|
||||
/// fourths, fifths, and octaves.
|
||||
///
|
||||
/// ## Knobs
|
||||
/// - `voice1Level`: Voice 1 level in `[0, 1]`.
|
||||
/// - `voice2Level`: Voice 2 level in `[0, 1]`.
|
||||
/// - `direct`: Dry signal level in `[0, 1]`.
|
||||
///
|
||||
/// ## Selectors (knob pickers)
|
||||
/// - `voice1`: Voice 1 interval in semitones (snaps to musical intervals).
|
||||
/// - `voice2`: Voice 2 interval in semitones.
|
||||
public final class HarmonizerPedal: Pedal {
|
||||
|
||||
/// One-line description shown in the picker and info panel.
|
||||
public override var summary: String {
|
||||
"Two pitch-shifted harmony voices at intervals you pick, stacked under your note."
|
||||
}
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Voice 1 interval in semitones. Snaps to musical-interval stops.
|
||||
@UIParam public var voice1: Double = 4.0
|
||||
|
||||
/// Voice 2 interval in semitones. Snaps to musical-interval stops.
|
||||
@UIParam public var voice2: Double = 7.0
|
||||
|
||||
/// Voice 1 level in `[0, 1]`.
|
||||
@UIParam public var voice1Level: Double = 0.6
|
||||
|
||||
/// Voice 2 level in `[0, 1]`.
|
||||
@UIParam public var voice2Level: Double = 0.45
|
||||
|
||||
/// Dry (direct) signal level in `[0, 1]`.
|
||||
@UIParam public var direct: Double = 1.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Pedal blends internally via the level knobs, so the base wet/dry stays fully wet.
|
||||
private static let defaultMix: Double = 1.0
|
||||
|
||||
/// `semitones → ratio` exponent scale: `2^(s/12) = e^(s · ln2/12)`, fed to `Exp.Audio`.
|
||||
private let semitoneToRatioScale: Double = 0.05776226504666215 // ln(2) / 12
|
||||
|
||||
/// Granular pitch-shift window in seconds. Larger = smoother but more latency.
|
||||
private let windowSize: Double = 0.1
|
||||
|
||||
// MARK: - Ranges
|
||||
|
||||
private let levelRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||
|
||||
// MARK: - Knobs
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "V1 Level", node: $voice1Level, range: levelRange),
|
||||
PedalKnob(label: "V2 Level", node: $voice2Level, range: levelRange),
|
||||
PedalKnob(label: "Direct", node: $direct, range: levelRange),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Selectors
|
||||
|
||||
/// Musical-interval stops for the voice pickers, low to high. Values are semitones; captions are
|
||||
/// short interval names (`m3`/`M3` = minor/major third, `4`/`5` = perfect fourth/fifth,
|
||||
/// `8ve` = octave, `Uni` = unison). Minus = below the input.
|
||||
private static let intervalStops: [PedalSelectorKnob.Stop] = [
|
||||
PedalSelectorKnob.Stop(title: "-8ve", value: -12.0),
|
||||
PedalSelectorKnob.Stop(title: "-M6", value: -9.0),
|
||||
PedalSelectorKnob.Stop(title: "-m6", value: -8.0),
|
||||
PedalSelectorKnob.Stop(title: "-5", value: -7.0),
|
||||
PedalSelectorKnob.Stop(title: "-4", value: -5.0),
|
||||
PedalSelectorKnob.Stop(title: "-M3", value: -4.0),
|
||||
PedalSelectorKnob.Stop(title: "-m3", value: -3.0),
|
||||
PedalSelectorKnob.Stop(title: "Uni", value: 0.0),
|
||||
PedalSelectorKnob.Stop(title: "m3", value: 3.0),
|
||||
PedalSelectorKnob.Stop(title: "M3", value: 4.0),
|
||||
PedalSelectorKnob.Stop(title: "4", value: 5.0),
|
||||
PedalSelectorKnob.Stop(title: "5", value: 7.0),
|
||||
PedalSelectorKnob.Stop(title: "m6", value: 8.0),
|
||||
PedalSelectorKnob.Stop(title: "M6", value: 9.0),
|
||||
PedalSelectorKnob.Stop(title: "8ve", value: 12.0),
|
||||
]
|
||||
|
||||
public override var effectSelectors: [PedalSelectorKnob] {
|
||||
[
|
||||
PedalSelectorKnob(label: "Voice 1", node: $voice1, stops: HarmonizerPedal.intervalStops),
|
||||
PedalSelectorKnob(label: "Voice 2", node: $voice2, stops: HarmonizerPedal.intervalStops),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a harmonizer pedal.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||
/// - outputBus: Audio bus index to write the output to. Defaults to `0`.
|
||||
public init(
|
||||
inputBus: Int = 0,
|
||||
outputBus: Int = 0
|
||||
) {
|
||||
super.init(
|
||||
name: "Harmonizer",
|
||||
inputBus: inputBus,
|
||||
outputBus: outputBus,
|
||||
initialMix: HarmonizerPedal.defaultMix
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let voice1Signal: any ValidGeneratorInput = harmonyVoice(dry, semitones: $voice1)
|
||||
let voice2Signal: any ValidGeneratorInput = harmonyVoice(dry, semitones: $voice2)
|
||||
|
||||
let directVoice: any ValidGeneratorInput = dry * $direct
|
||||
let harmony1: any ValidGeneratorInput = voice1Signal * $voice1Level
|
||||
let harmony2: any ValidGeneratorInput = voice2Signal * $voice2Level
|
||||
return directVoice + harmony1 + harmony2
|
||||
}
|
||||
|
||||
/// One pitch-shifted voice: ratio `2^(semitones/12)` via `Exp`, fed to a granular `PitchShift`.
|
||||
private func harmonyVoice(
|
||||
_ dry: any ValidGeneratorInput,
|
||||
semitones: any ValidGeneratorInput
|
||||
) -> any ValidGeneratorInput {
|
||||
let ratio: Exp.Audio = Exp.Audio(semitones * semitoneToRatioScale)
|
||||
return PitchShift.Audio(input: dry, pitchRatio: ratio, windowSize: windowSize)
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,13 @@ extension Pedal {
|
||||
let values: [Double] = knobs.map { $0.node.value }
|
||||
let switchValues: [Double] = effectSwitches.map { $0.node.value }
|
||||
let sliderValues: [Double] = effectSliders.map { $0.node.value }
|
||||
let selectorValues: [Double] = effectSelectors.map { $0.node.value }
|
||||
return PedalState(
|
||||
type: displayName,
|
||||
knobValues: values,
|
||||
switchValues: switchValues,
|
||||
sliderValues: sliderValues,
|
||||
selectorValues: selectorValues,
|
||||
bypass: bypass
|
||||
)
|
||||
}
|
||||
@@ -51,6 +53,9 @@ extension Pedal {
|
||||
for (slider, value) in zip(effectSliders, state.sliderValues) {
|
||||
slider.node.update(value)
|
||||
}
|
||||
for (selector, value) in zip(effectSelectors, state.selectorValues) {
|
||||
selector.node.update(value)
|
||||
}
|
||||
bypass = state.bypass
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public enum PedalRegistry {
|
||||
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||
"Octave Splitter": { OctaveUpSplitterPedal() },
|
||||
"Bass Octaver": { BassOctaverPedal() },
|
||||
"Harmonizer": { HarmonizerPedal() },
|
||||
"Ping-Pong": { PingPongDelayPedal() },
|
||||
"Limiter": { LimiterPedal() },
|
||||
"Noise Gate": { NoiseGatePedal() },
|
||||
|
||||
@@ -30,6 +30,10 @@ public struct PedalState: Codable, Equatable {
|
||||
/// no sliders. Absent in presets saved before sliders existed — decodes to `[]`.
|
||||
public let sliderValues: [Double]
|
||||
|
||||
/// Selector-knob values in the same order as `Pedal.effectSelectors`. Empty for pedals with
|
||||
/// no selectors. Absent in presets saved before selectors existed — decodes to `[]`.
|
||||
public let selectorValues: [Double]
|
||||
|
||||
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
||||
public let bypass: Double
|
||||
|
||||
@@ -40,18 +44,21 @@ public struct PedalState: Codable, Equatable {
|
||||
/// - knobValues: Current knob values in `Pedal.knobs` order.
|
||||
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
|
||||
/// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty.
|
||||
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
|
||||
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
||||
public init(
|
||||
type: String,
|
||||
knobValues: [Double],
|
||||
switchValues: [Double] = [],
|
||||
sliderValues: [Double] = [],
|
||||
selectorValues: [Double] = [],
|
||||
bypass: Double
|
||||
) {
|
||||
self.type = type
|
||||
self.knobValues = knobValues
|
||||
self.switchValues = switchValues
|
||||
self.sliderValues = sliderValues
|
||||
self.selectorValues = selectorValues
|
||||
self.bypass = bypass
|
||||
}
|
||||
|
||||
@@ -60,17 +67,19 @@ public struct PedalState: Codable, Equatable {
|
||||
case knobValues
|
||||
case switchValues
|
||||
case sliderValues
|
||||
case selectorValues
|
||||
case bypass
|
||||
}
|
||||
|
||||
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues`
|
||||
/// existed by defaulting the missing keys to an empty array.
|
||||
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
|
||||
/// `selectorValues` existed by defaulting the missing keys to an empty array.
|
||||
public init(from decoder: any Decoder) throws {
|
||||
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.type = try container.decode(String.self, forKey: .type)
|
||||
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
||||
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
||||
self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? []
|
||||
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
|
||||
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user