b6fdee8bfc
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
128 lines
3.5 KiB
Swift
128 lines
3.5 KiB
Swift
// ParameterLabel.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#if canImport(SwiftUI)
|
|
import SwiftUI
|
|
import LyrebirdSynth
|
|
|
|
/// A read-only display label that shows the current value of a `UIParamNode`.
|
|
///
|
|
/// Updates automatically via `@Observable` on the backing node — no polling.
|
|
///
|
|
/// ```swift
|
|
/// ParameterLabel("Level", node: synth.$amplitude)
|
|
/// ParameterLabel("Freq (Hz)", node: synth.$frequency, decimalPlaces: 1)
|
|
/// ```
|
|
public struct ParameterLabel: View {
|
|
|
|
// MARK: - Properties
|
|
|
|
private let label: String
|
|
private let node: UIParamNode
|
|
private let decimalPlaces: Int
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a read-only parameter label.
|
|
///
|
|
/// - Parameters:
|
|
/// - label: Descriptive text displayed before the value.
|
|
/// - node: The `UIParamNode` to monitor (pass `synth.$paramName`).
|
|
/// - decimalPlaces: Number of decimal places shown. Default 3.
|
|
public init(
|
|
_ label: String,
|
|
node: UIParamNode,
|
|
decimalPlaces: Int = 3
|
|
) {
|
|
self.label = label
|
|
self.node = node
|
|
self.decimalPlaces = decimalPlaces
|
|
}
|
|
|
|
// MARK: - Body
|
|
|
|
public var body: some View {
|
|
HStack {
|
|
Text(label)
|
|
.frame(minWidth: 80, alignment: .leading)
|
|
Text(formattedValue)
|
|
.monospacedDigit()
|
|
.frame(minWidth: 60, alignment: .trailing)
|
|
}
|
|
}
|
|
|
|
// MARK: - Formatting
|
|
|
|
private var formattedValue: String {
|
|
String(format: "%.\(decimalPlaces)f", node.value)
|
|
}
|
|
}
|
|
|
|
#else
|
|
// Linux/GTK4 counterpart to `LyrebirdUI.ParameterLabel`: a read-only display of
|
|
// a core `UIParamNode`'s current value, updated automatically via `@Observable`
|
|
// (no polling). Uses only the core View DSL; no BackendGTK4 import.
|
|
//
|
|
// SwiftOpenUI is always present in this target (see Package.swift), so no
|
|
// `canImport` guard is needed.
|
|
import SwiftOpenUI
|
|
import LyrebirdSynth
|
|
import Foundation // String(format:) for the value readout
|
|
|
|
/// A read-only label for the Linux/GTK4 UI that shows a ``UIParamNode``'s
|
|
/// current value. Mirrors `LyrebirdUI.ParameterLabel`: a leading descriptive
|
|
/// label and a trailing monospaced value. Refreshes automatically because
|
|
/// `UIParamNode` is `@Observable`.
|
|
public struct ParameterLabel: View {
|
|
|
|
// MARK: - Properties
|
|
|
|
private let label: String
|
|
private let node: UIParamNode
|
|
private let decimalPlaces: Int
|
|
|
|
// Layout constants (points), matching the macOS label.
|
|
private let labelMinWidth: Double = 80
|
|
private let valueMinWidth: Double = 60
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a read-only parameter label.
|
|
///
|
|
/// - Parameters:
|
|
/// - label: Descriptive text displayed before the value.
|
|
/// - node: The `UIParamNode` to monitor (pass `synth.$paramName`).
|
|
/// - decimalPlaces: Number of decimal places shown. Default 3.
|
|
public init(
|
|
_ label: String,
|
|
node: UIParamNode,
|
|
decimalPlaces: Int = 3
|
|
) {
|
|
self.label = label
|
|
self.node = node
|
|
self.decimalPlaces = decimalPlaces
|
|
}
|
|
|
|
// MARK: - Body
|
|
|
|
public var body: some View {
|
|
HStack {
|
|
Text(label)
|
|
.frame(minWidth: labelMinWidth, alignment: .leading)
|
|
Text(formattedValue)
|
|
.monospacedDigit()
|
|
.frame(minWidth: valueMinWidth, alignment: .trailing)
|
|
}
|
|
}
|
|
|
|
// MARK: - Formatting
|
|
|
|
private var formattedValue: String {
|
|
String(format: "%.\(decimalPlaces)f", node.value)
|
|
}
|
|
}
|
|
#endif
|