1.0.0 release
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// ParameterFormatting.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Threshold above which a value renders with zero fractional digits.
|
||||
internal let parameterFormatLargeMagnitudeThreshold: Double = 1000
|
||||
|
||||
/// Threshold above which a value renders with one fractional digit.
|
||||
internal let parameterFormatMediumMagnitudeThreshold: Double = 10
|
||||
|
||||
/// Render a numeric parameter value with magnitude-adaptive precision.
|
||||
///
|
||||
/// - `|v| >= 1000`: no decimals.
|
||||
/// - `1000 > |v| >= 10`: one decimal.
|
||||
/// - `|v| < 10`: three decimals.
|
||||
///
|
||||
/// Shared by `ParameterKnob` and `ParameterXY` so the two controls agree on
|
||||
/// display formatting.
|
||||
internal func formattedParameterValue(_ v: Double) -> String {
|
||||
if abs(v) >= parameterFormatLargeMagnitudeThreshold { return String(format: "%.0f", v) }
|
||||
if abs(v) >= parameterFormatMediumMagnitudeThreshold { return String(format: "%.1f", v) }
|
||||
return String(format: "%.3f", v)
|
||||
}
|
||||
Reference in New Issue
Block a user