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
|
||||
|
||||
/// A Canvas-based scatter plot for an array of `Double` values.
|
||||
@@ -117,3 +118,128 @@ public struct LyrebirdScatterView: View {
|
||||
return height * (1.0 - CGFloat(t))
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// Linux/GTK4 counterpart to `LyrebirdUI.LyrebirdScatterView`: a Canvas scatter
|
||||
// plot of an array of `Double`s, one filled dot per sample. The SwiftUI
|
||||
// `GraphicsContext`/`Path` drawing is rewritten to imperative `DrawingContext`
|
||||
// (Cairo) calls: a background fill, an optional zero guide line, and one
|
||||
// `arc`+`fill` per dot. Y-bounds reuse the shared `_linuxEnvelopeYBounds`.
|
||||
//
|
||||
// No axis text is drawn (`DrawingContext` has no text primitive) — the Apple
|
||||
// side draws none either, so there is no feature loss here.
|
||||
//
|
||||
// SwiftOpenUI + BackendGTK4 are always present in this target (see Package.swift).
|
||||
import SwiftOpenUI
|
||||
import BackendGTK4
|
||||
import Foundation // CGSize / CGFloat
|
||||
|
||||
/// A Canvas scatter plot for the Linux/GTK4 UI. Mirrors
|
||||
/// `LyrebirdUI.LyrebirdScatterView`; same public API/init as the Apple side.
|
||||
public struct LyrebirdScatterView: View {
|
||||
|
||||
private let samples: [Double]
|
||||
private let yRange: ClosedRange<Double>?
|
||||
private let pointColor: Color
|
||||
private let showZeroLine: Bool
|
||||
private let width: CGFloat
|
||||
private let height: CGFloat
|
||||
|
||||
// Background is a fixed dark panel; drawn inside the renderer since the
|
||||
// Cairo backend has no `clipShape`.
|
||||
private static let backgroundRGB: (r: Double, g: Double, b: Double) = (0.08, 0.08, 0.08)
|
||||
private static let scatterDotRadius: Double = 2.5
|
||||
private static let zeroLineOpacity: Double = 0.25
|
||||
private static let guideLineWidth: Double = 0.5
|
||||
|
||||
public init(
|
||||
_ samples: [Double],
|
||||
yRange: ClosedRange<Double>? = nil,
|
||||
pointColor: Color = .cyan,
|
||||
showZeroLine: Bool = true,
|
||||
width: CGFloat = 300,
|
||||
height: CGFloat = 120
|
||||
) {
|
||||
self.samples = samples
|
||||
self.yRange = yRange
|
||||
self.pointColor = pointColor
|
||||
self.showZeroLine = showZeroLine
|
||||
self.width = width
|
||||
self.height = height
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Canvas(renderer: { (ctx: DrawingContext, size: CGSize) in
|
||||
_draw(ctx: ctx, size: size)
|
||||
})
|
||||
.frame(width: Double(width), height: Double(height))
|
||||
}
|
||||
|
||||
// MARK: - Drawing
|
||||
|
||||
private func _draw(
|
||||
ctx: DrawingContext,
|
||||
size: CGSize
|
||||
) {
|
||||
let w: Double = Double(size.width)
|
||||
let h: Double = Double(size.height)
|
||||
|
||||
// Background panel.
|
||||
let bg: (r: Double, g: Double, b: Double) = LyrebirdScatterView.backgroundRGB
|
||||
ctx.setColor(r: bg.r, g: bg.g, b: bg.b)
|
||||
ctx.rectangle(x: 0, y: 0, width: w, height: h)
|
||||
ctx.fill()
|
||||
|
||||
guard !samples.isEmpty else { return }
|
||||
|
||||
let (yMin, yMax): (Double, Double) = _yBounds()
|
||||
|
||||
if showZeroLine && yMin <= 0 && yMax >= 0 {
|
||||
let zy: Double = _yFor(0, yMin: yMin, yMax: yMax, height: h)
|
||||
ctx.setColor(r: 1.0, g: 1.0, b: 1.0, a: LyrebirdScatterView.zeroLineOpacity)
|
||||
ctx.setLineWidth(LyrebirdScatterView.guideLineWidth)
|
||||
ctx.moveTo(x: 0, y: zy)
|
||||
ctx.lineTo(x: w, y: zy)
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
let count: Int = samples.count
|
||||
let r: Double = LyrebirdScatterView.scatterDotRadius
|
||||
let fullCircle: Double = 2.0 * Double.pi
|
||||
ctx.setColor(r: pointColor.red, g: pointColor.green, b: pointColor.blue, a: pointColor.alpha)
|
||||
|
||||
if count == 1 {
|
||||
let px: Double = w / 2
|
||||
let py: Double = h / 2
|
||||
ctx.arc(centerX: px, centerY: py, radius: r, startAngle: 0, endAngle: fullCircle)
|
||||
ctx.fill()
|
||||
return
|
||||
}
|
||||
|
||||
for i: Int in 0..<count {
|
||||
let px: Double = Double(i) / Double(count - 1) * w
|
||||
let py: Double = _yFor(samples[i], yMin: yMin, yMax: yMax, height: h)
|
||||
ctx.arc(centerX: px, centerY: py, radius: r, startAngle: 0, endAngle: fullCircle)
|
||||
ctx.fill()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func _yBounds() -> (Double, Double) {
|
||||
if let r: ClosedRange<Double> = yRange { return (r.lowerBound, r.upperBound) }
|
||||
return _linuxEnvelopeYBounds(levels: samples)
|
||||
}
|
||||
|
||||
private func _yFor(
|
||||
_ v: Double,
|
||||
yMin: Double,
|
||||
yMax: Double,
|
||||
height: Double
|
||||
) -> Double {
|
||||
guard yMax > yMin else { return height / 2 }
|
||||
let t: Double = (v - yMin) / (yMax - yMin)
|
||||
return height * (1.0 - t)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user