// VolumePedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Foot-controlled volume pedal — a single smoothed gain sweep from silence to unity. /// /// The `position` knob is the expression-pedal position: `0` = heel down (silent), `1` = toe /// down (unity gain). It is smoothed with a short `Lag` so sweeping the position (by hand or from /// a MIDI expression pedal) is click-free. /// /// ## Knobs /// - `position`: Volume sweep in `[0, 1]`. `0` = silent, `1` = unity. public final class VolumePedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Foot-controlled volume — sweep from silence to unity gain." } // MARK: - Parameters /// Expression-pedal position in `[0, 1]`. `0` = heel (silent), `1` = toe (unity gain). @UIParam public var position: Double = 1.0 // MARK: - Constants private static let defaultMix: Double = 1.0 /// Smoothing time constant in seconds for the position sweep — prevents zipper noise when /// the position jumps (e.g. coarse 0–127 steps from a MIDI expression pedal). private let smoothingTime: Double = 0.02 // MARK: - Ranges private let positionRange: ClosedRange = 0.0 ... 1.0 // MARK: - Knobs public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Position", node: $position, range: positionRange), ] } // MARK: - Init /// Creates a volume pedal. /// /// - Parameters: /// - inputBus: Audio bus to read the dry input from. Defaults to `0`; set by the board. /// - outputBus: Audio bus to write the scaled output to. Defaults to `0`; set by the board. public init(inputBus: Int = 0, outputBus: Int = 0) { super.init( name: "Volume", inputBus: inputBus, outputBus: outputBus, initialMix: VolumePedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { // Smooth the position so hand/MIDI sweeps don't zipper, then scale the dry signal. let smoothed: Lag.Control = Lag.Control(input: $position, time: smoothingTime) return dry * smoothed } }