Lyrebird 2.0.0 — Linux support
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>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
import LyrebirdSynth
|
||||
|
||||
@@ -24,7 +25,7 @@ public struct ParameterKnob: View {
|
||||
private let range: ClosedRange<Double>
|
||||
|
||||
/// Pixels of vertical drag that span the full parameter range. Default 200.
|
||||
public var dragSensitivity: CGFloat = 200
|
||||
public var dragSensitivity: Double = 200
|
||||
|
||||
// MARK: - Private drag state
|
||||
|
||||
@@ -110,7 +111,7 @@ public struct ParameterKnob: View {
|
||||
}
|
||||
let delta: CGFloat = dragStartPosition - gesture.location.y // up = positive
|
||||
let span: Double = range.upperBound - range.lowerBound
|
||||
let change: Double = Double(delta / dragSensitivity) * span
|
||||
let change: Double = (Double(delta) / dragSensitivity) * span
|
||||
let clamped: Double = min(max(dragStartValue + change, range.lowerBound), range.upperBound)
|
||||
node.update(clamped)
|
||||
}
|
||||
@@ -134,3 +135,119 @@ public struct ParameterKnob: View {
|
||||
formattedParameterValue(node.value)
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// Experimental Linux GUI, built only under `LYREBIRD_ENABLE_LINUX_UI=1`
|
||||
// (see Package.swift). This is the first control ported from `LyrebirdUI`'s
|
||||
// SwiftUI `ParameterKnob` to SwiftOpenUI's GTK4 surface: a rotary knob drawn
|
||||
// with the Cairo-backed `DrawingContext` (SwiftOpenUI's stand-in for SwiftUI's
|
||||
// `GraphicsContext`) and a `.onDrag` vertical drag-to-set.
|
||||
//
|
||||
// It binds to the same core `UIParamNode` the macOS `ParameterKnob` binds to,
|
||||
// so a synthesizer's `@UIParam` drives both platforms from one model. Because
|
||||
// `UIParamNode` is `@Observable`, a drag-driven `node.update(_:)` takes the
|
||||
// GTK4 backend's narrow mutation (redraw-in-place) path carried by the pinned
|
||||
// SwiftOpenUI fork, so the in-flight drag gesture survives and the knob tracks
|
||||
// continuously.
|
||||
//
|
||||
// SwiftOpenUI + BackendGTK4 are always present in this target (see Package.swift),
|
||||
// so no `canImport` guard is needed; `BackendGTK4` carries the Cairo-backed
|
||||
// `DrawingContext` drawing methods (setColor/arc/moveTo/…), which are extensions
|
||||
// not present in SwiftOpenUI's core.
|
||||
import SwiftOpenUI
|
||||
import BackendGTK4
|
||||
import LyrebirdSynth
|
||||
import Foundation
|
||||
|
||||
/// A rotary knob for the Linux/GTK4 UI, drawn on a `Canvas` and set by a
|
||||
/// vertical drag. Binds to a core ``UIParamNode`` (via a synthesizer's
|
||||
/// `@UIParam` projected value, `synth.$paramName`) — the same model the macOS
|
||||
/// `ParameterKnob` uses. Mirrors that control's behaviour: −135°…+135° sweep,
|
||||
/// drag-up increases.
|
||||
public struct ParameterKnob: View {
|
||||
private let label: String
|
||||
private let node: UIParamNode
|
||||
private let range: ClosedRange<Double>
|
||||
|
||||
/// Pixels of vertical drag spanning the full parameter range. Matches the
|
||||
/// macOS knob's default.
|
||||
public var dragSensitivity: Double = 200
|
||||
|
||||
// Drag origin, captured on the first `onChanged` of each gesture. An
|
||||
// explicit flag avoids a sentinel collision when the value is genuinely at
|
||||
// the range's lower bound.
|
||||
@State private var dragStartValue: Double = 0
|
||||
@State private var dragInProgress: Bool = false
|
||||
|
||||
/// Creates a knob bound to a `UIParamNode`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - label: Text displayed below the knob.
|
||||
/// - node: The `UIParamNode` to bind to (pass `synth.$paramName`).
|
||||
/// - range: The minimum and maximum parameter values.
|
||||
public init(
|
||||
_ label: String,
|
||||
node: UIParamNode,
|
||||
range: ClosedRange<Double>
|
||||
) {
|
||||
self.label = label
|
||||
self.node = node
|
||||
self.range = range
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
Canvas(renderer: { (ctx: DrawingContext, size: CGSize) in
|
||||
let cx: Double = Double(size.width) / 2
|
||||
let cy: Double = Double(size.height) / 2
|
||||
let radius: Double = min(cx, cy) - 4
|
||||
|
||||
// Dial face ring.
|
||||
ctx.setColor(r: 0.20, g: 0.20, b: 0.20)
|
||||
ctx.setLineWidth(3)
|
||||
ctx.arc(centerX: cx, centerY: cy, radius: radius,
|
||||
startAngle: 0, endAngle: 2 * Double.pi)
|
||||
ctx.stroke()
|
||||
|
||||
// Indicator: −135°…+135° sweep (270° total), like the macOS knob.
|
||||
let startAngleRadians: Double = 0.75 * Double.pi
|
||||
let sweepRadians: Double = 1.5 * Double.pi
|
||||
let angle: Double = startAngleRadians + normalise(node.value) * sweepRadians
|
||||
ctx.setColor(r: 0.30, g: 0.80, b: 1.0)
|
||||
ctx.setLineWidth(3)
|
||||
ctx.moveTo(x: cx, y: cy)
|
||||
ctx.lineTo(x: cx + radius * cos(angle), y: cy + radius * sin(angle))
|
||||
ctx.stroke()
|
||||
})
|
||||
.frame(width: 50, height: 50)
|
||||
.onDrag(
|
||||
minimumDistance: 0,
|
||||
onChanged: { (drag: DragGestureValue) in
|
||||
if !dragInProgress {
|
||||
dragInProgress = true
|
||||
dragStartValue = node.value
|
||||
}
|
||||
// Up (negative height) increases, matching the macOS knob.
|
||||
let span: Double = range.upperBound - range.lowerBound
|
||||
let change: Double = (-drag.height / dragSensitivity) * span
|
||||
let target: Double = min(range.upperBound,
|
||||
max(range.lowerBound, dragStartValue + change))
|
||||
node.update(target)
|
||||
},
|
||||
onEnded: { (_: DragGestureValue) in
|
||||
dragInProgress = false
|
||||
}
|
||||
)
|
||||
Text(label)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func normalise(_ value: Double) -> Double {
|
||||
let lo: Double = range.lowerBound
|
||||
let hi: Double = range.upperBound
|
||||
guard hi > lo else { return 0 }
|
||||
return min(max((value - lo) / (hi - lo), 0), 1)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user