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
|
||||
|
||||
@@ -163,3 +164,148 @@ public struct ParameterXY: View {
|
||||
formattedParameterValue(v)
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// Linux/GTK4 counterpart to `LyrebirdUI.ParameterXY`: a two-dimensional pad that
|
||||
// drives two core `UIParamNode`s at once. Drawn on a single `Canvas` (background,
|
||||
// centre grid, cursor) with an absolute-position `.onDrag` — the touch point maps
|
||||
// straight to the cursor, X left→right, Y bottom→top.
|
||||
//
|
||||
// Same gesture path as `ParameterKnob`: the drag calls `node.update(_:)`,
|
||||
// and because `UIParamNode` is `@Observable` the Canvas redraw takes the GTK4
|
||||
// backend's narrow `.canvasContent` mutation path (the pinned fork's fix), so the
|
||||
// cursor tracks continuously without the gesture being torn down by a rebuild.
|
||||
//
|
||||
// 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.
|
||||
import SwiftOpenUI
|
||||
import BackendGTK4
|
||||
import LyrebirdSynth
|
||||
import Foundation // CGSize (Canvas renderer size)
|
||||
|
||||
/// A two-axis control pad for the Linux/GTK4 UI, bound to two ``UIParamNode``s.
|
||||
/// Mirrors `LyrebirdUI.ParameterXY`: drag within the pad to set X (horizontal,
|
||||
/// left→right) and Y (vertical, bottom→top) independently.
|
||||
public struct ParameterXY: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let xLabel: String
|
||||
private let xNode: UIParamNode
|
||||
private let xRange: ClosedRange<Double>
|
||||
|
||||
private let yLabel: String
|
||||
private let yNode: UIParamNode
|
||||
private let yRange: ClosedRange<Double>
|
||||
|
||||
// Presentation constants (points).
|
||||
private let padSize: Double = 160
|
||||
private let cursorRadius: Double = 6
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates an XY pad bound to two `UIParamNode` values.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - xLabel: Label for the X axis.
|
||||
/// - xNode: The `UIParamNode` controlled by horizontal position.
|
||||
/// - xRange: Value range for the X axis.
|
||||
/// - yLabel: Label for the Y axis.
|
||||
/// - yNode: The `UIParamNode` controlled by vertical position.
|
||||
/// - yRange: Value range for the Y axis.
|
||||
public init(
|
||||
xLabel: String,
|
||||
xNode: UIParamNode,
|
||||
xRange: ClosedRange<Double>,
|
||||
yLabel: String,
|
||||
yNode: UIParamNode,
|
||||
yRange: ClosedRange<Double>
|
||||
) {
|
||||
self.xLabel = xLabel
|
||||
self.xNode = xNode
|
||||
self.xRange = xRange
|
||||
self.yLabel = yLabel
|
||||
self.yNode = yNode
|
||||
self.yRange = yRange
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
Canvas(renderer: { (ctx: DrawingContext, size: CGSize) in
|
||||
let w: Double = Double(size.width)
|
||||
let h: Double = Double(size.height)
|
||||
|
||||
// Background fill.
|
||||
ctx.setColor(r: 0.15, g: 0.15, b: 0.15)
|
||||
ctx.rectangle(x: 0, y: 0, width: w, height: h)
|
||||
ctx.fill()
|
||||
|
||||
// Border.
|
||||
ctx.setColor(r: 0.40, g: 0.40, b: 0.40)
|
||||
ctx.setLineWidth(1)
|
||||
ctx.rectangle(x: 0, y: 0, width: w, height: h)
|
||||
ctx.stroke()
|
||||
|
||||
// Centre grid lines (faint).
|
||||
let midX: Double = w / 2
|
||||
let midY: Double = h / 2
|
||||
ctx.setColor(r: 0.40, g: 0.40, b: 0.40, a: 0.4)
|
||||
ctx.setLineWidth(0.5)
|
||||
ctx.moveTo(x: midX, y: 0)
|
||||
ctx.lineTo(x: midX, y: h)
|
||||
ctx.moveTo(x: 0, y: midY)
|
||||
ctx.lineTo(x: w, y: midY)
|
||||
ctx.stroke()
|
||||
|
||||
// Cursor: X left→right, Y bottom→top (flip vertical).
|
||||
let nx: Double = normalise(xNode.value, range: xRange)
|
||||
let ny: Double = 1.0 - normalise(yNode.value, range: yRange)
|
||||
let cx: Double = nx * w
|
||||
let cy: Double = ny * h
|
||||
ctx.setColor(r: 0.30, g: 0.80, b: 1.0)
|
||||
ctx.arc(centerX: cx, centerY: cy, radius: cursorRadius,
|
||||
startAngle: 0, endAngle: 2 * Double.pi)
|
||||
ctx.fill()
|
||||
})
|
||||
.frame(width: padSize, height: padSize)
|
||||
.onDrag(
|
||||
minimumDistance: 0,
|
||||
onChanged: { (drag: DragGestureValue) in
|
||||
// Absolute position: the touch point is the cursor.
|
||||
let nx: Double = min(max(drag.location.x / padSize, 0), 1)
|
||||
let ny: Double = min(max(drag.location.y / padSize, 0), 1)
|
||||
xNode.update(denormalise(nx, range: xRange))
|
||||
yNode.update(denormalise(1.0 - ny, range: yRange)) // flip Y
|
||||
}
|
||||
)
|
||||
Text("\(xLabel): \(formattedParameterValue(xNode.value))")
|
||||
.monospacedDigit()
|
||||
Text("\(yLabel): \(formattedParameterValue(yNode.value))")
|
||||
.monospacedDigit()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func normalise(
|
||||
_ value: Double,
|
||||
range: ClosedRange<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)
|
||||
}
|
||||
|
||||
private func denormalise(
|
||||
_ position: Double,
|
||||
range: ClosedRange<Double>
|
||||
) -> Double {
|
||||
range.lowerBound + position * (range.upperBound - range.lowerBound)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user