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
|
||||
|
||||
@@ -81,6 +82,12 @@ public struct LyrebirdMessageView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Current messages. On Apple the body is `@MainActor`, so this is a plain
|
||||
/// read (the Linux counterpart hops via `assumeIsolated`).
|
||||
private var messagesSnapshot: [LyrebirdMessage] {
|
||||
center.messages
|
||||
}
|
||||
|
||||
private var filterRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(LyrebirdMessageTier.allCases, id: \.self) { tier in
|
||||
@@ -129,17 +136,17 @@ public struct LyrebirdMessageView: View {
|
||||
// MARK: - Helpers
|
||||
|
||||
private var filteredMessages: [LyrebirdMessage] {
|
||||
center.messages.filter { enabledTiers.contains($0.tier) }
|
||||
messagesSnapshot.filter { enabledTiers.contains($0.tier) }
|
||||
}
|
||||
|
||||
private var emptyStateText: String {
|
||||
if center.messages.isEmpty { return "No messages." }
|
||||
if messagesSnapshot.isEmpty { return "No messages." }
|
||||
return "No messages match the current filter."
|
||||
}
|
||||
|
||||
private func count(of tier: LyrebirdMessageTier) -> Int {
|
||||
var n: Int = 0
|
||||
for msg: LyrebirdMessage in center.messages where msg.tier == tier {
|
||||
for msg: LyrebirdMessage in messagesSnapshot where msg.tier == tier {
|
||||
n += 1
|
||||
}
|
||||
return n
|
||||
@@ -273,3 +280,296 @@ extension LyrebirdMessageView {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Linux/GTK4 counterpart to `LyrebirdUI.LyrebirdMessageView`: a full scrollable
|
||||
// view over a `LyrebirdMessageCenter` ring — a header (title, count, Clear), a
|
||||
// per-tier filter row with live counts, and a scrolling list of rows. Live
|
||||
// updates come from `@Bindable` on the `@Observable` center (body reads are
|
||||
// observation-tracked, same as the Apple side). Text is drawn with real `Text`
|
||||
// widgets, so the readout is complete.
|
||||
//
|
||||
// Dropped vs the Apple side (document per project rule): the auto-scroll to the
|
||||
// newest row (`ScrollViewReader`/`onChange`/`withAnimation`) and per-row text
|
||||
// selection are omitted; the list simply scrolls. `presentInWindow` opens a
|
||||
// detached GTK window (needs a running `GtkApplication`).
|
||||
//
|
||||
// SwiftOpenUI is always present in this target (see Package.swift).
|
||||
import SwiftOpenUI
|
||||
import LyrebirdSynth
|
||||
import Foundation // DateFormatter for the row timestamp
|
||||
|
||||
/// Full scrollable view over a `LyrebirdMessageCenter` ring for the Linux/GTK4
|
||||
/// UI. Mirrors `LyrebirdUI.LyrebirdMessageView` (minus auto-scroll and text
|
||||
/// selection); same public API/init as the Apple side.
|
||||
public struct LyrebirdMessageView: View {
|
||||
|
||||
@Bindable private var center: LyrebirdMessageCenter
|
||||
|
||||
@State private var enabledTiers: Set<LyrebirdMessageTier> =
|
||||
Set(LyrebirdMessageTier.allCases)
|
||||
|
||||
// Presentation constants (points).
|
||||
private let minPanelWidth: Double = 360
|
||||
private let minPanelHeight: Double = 200
|
||||
private let timeColumnWidth: Double = 80
|
||||
private let stripeWidth: Double = 3
|
||||
private let stripeHeight: Double = 14
|
||||
|
||||
/// Creates a message view bound to `LyrebirdMessageCenter.shared`.
|
||||
@MainActor
|
||||
public init() {
|
||||
self.center = LyrebirdMessageCenter.shared
|
||||
}
|
||||
|
||||
/// Creates a message view bound to the given center.
|
||||
///
|
||||
/// - Parameter center: The center to observe.
|
||||
public init(center: LyrebirdMessageCenter) {
|
||||
self.center = center
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
headerRow
|
||||
filterRow
|
||||
Divider()
|
||||
listBody
|
||||
}
|
||||
.padding(12)
|
||||
.background(Color.lyrebirdControlBackground)
|
||||
.frame(minWidth: minPanelWidth, minHeight: minPanelHeight)
|
||||
}
|
||||
|
||||
// MARK: - Sub-rows
|
||||
|
||||
// `LyrebirdMessageCenter` is @MainActor; the SwiftOpenUI body / actions run on
|
||||
// the GTK main thread, so `assumeIsolated` reaches `messages` / `clear()`
|
||||
// safely. The center is bound to a local first so the `@MainActor` closure
|
||||
// captures the (Sendable) center rather than `self` (the non-Sendable View).
|
||||
private var messagesSnapshot: [LyrebirdMessage] {
|
||||
let c: LyrebirdMessageCenter = center
|
||||
return MainActor.assumeIsolated { c.messages }
|
||||
}
|
||||
|
||||
private var headerRow: some View {
|
||||
let all: [LyrebirdMessage] = messagesSnapshot
|
||||
let c: LyrebirdMessageCenter = center
|
||||
return HStack(spacing: 8) {
|
||||
Text("Messages")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text("\(all.count)")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
// action:label: form — the string-title Button's action does not
|
||||
// fire on GTK4 here (same as the EngineStatus Stop button).
|
||||
Button {
|
||||
MainActor.assumeIsolated { c.clear() }
|
||||
} label: {
|
||||
Text("Clear")
|
||||
}
|
||||
.disabled(all.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
private var filterRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(LyrebirdMessageTier.allCases, id: \.self) { tier in
|
||||
TierFilterChip(
|
||||
tier: tier,
|
||||
count: count(of: tier),
|
||||
isEnabled: enabledTiers.contains(tier),
|
||||
toggle: { toggle(tier) }
|
||||
)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
private var listBody: some View {
|
||||
let visible: [LyrebirdMessage] = filteredMessages
|
||||
return ScrollView {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
if visible.isEmpty {
|
||||
Text(emptyStateText)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
} else {
|
||||
ForEach(visible) { msg in
|
||||
MessageRow(
|
||||
message: msg,
|
||||
timeColumnWidth: timeColumnWidth,
|
||||
stripeWidth: stripeWidth,
|
||||
stripeHeight: stripeHeight
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private var filteredMessages: [LyrebirdMessage] {
|
||||
messagesSnapshot.filter { enabledTiers.contains($0.tier) }
|
||||
}
|
||||
|
||||
private var emptyStateText: String {
|
||||
if messagesSnapshot.isEmpty { return "No messages." }
|
||||
return "No messages match the current filter."
|
||||
}
|
||||
|
||||
private func count(of tier: LyrebirdMessageTier) -> Int {
|
||||
var n: Int = 0
|
||||
for msg: LyrebirdMessage in messagesSnapshot where msg.tier == tier {
|
||||
n += 1
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
private func toggle(_ tier: LyrebirdMessageTier) {
|
||||
if enabledTiers.contains(tier) {
|
||||
enabledTiers.remove(tier)
|
||||
} else {
|
||||
enabledTiers.insert(tier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Sub-views
|
||||
|
||||
private struct TierFilterChip: View {
|
||||
let tier: LyrebirdMessageTier
|
||||
let count: Int
|
||||
let isEnabled: Bool
|
||||
let toggle: () -> Void
|
||||
|
||||
private let dotSize: Double = 8
|
||||
private let cornerRadiusPoints: Double = 4
|
||||
private let disabledDotOpacity: Double = 0.35
|
||||
private let disabledChipOpacity: Double = 0.55
|
||||
|
||||
var body: some View {
|
||||
Button(action: toggle) {
|
||||
HStack(spacing: 4) {
|
||||
Circle()
|
||||
.fill(LyrebirdMessageTierStyle.color(for: tier))
|
||||
.frame(width: dotSize, height: dotSize)
|
||||
.opacity(isEnabled ? 1.0 : disabledDotOpacity)
|
||||
Text(LyrebirdMessageTierStyle.shortLabel(for: tier))
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
Text("\(count)")
|
||||
.font(.caption2)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.horizontal, 6)
|
||||
.padding(.vertical, 3)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.background(Color.lyrebirdControlBackground)
|
||||
.cornerRadius(cornerRadiusPoints)
|
||||
.opacity(isEnabled ? 1.0 : disabledChipOpacity)
|
||||
}
|
||||
}
|
||||
|
||||
private struct MessageRow: View {
|
||||
let message: LyrebirdMessage
|
||||
let timeColumnWidth: Double
|
||||
let stripeWidth: Double
|
||||
let stripeHeight: Double
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text(MessageRow.formatTime(message.timestamp))
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: timeColumnWidth, alignment: .leading)
|
||||
Capsule()
|
||||
.fill(LyrebirdMessageTierStyle.color(for: message.tier))
|
||||
.frame(width: stripeWidth, height: stripeHeight)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
if let src: String = message.source, !src.isEmpty {
|
||||
Text(src)
|
||||
.font(.caption2)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text(message.text)
|
||||
.font(.callout)
|
||||
.foregroundStyle(.primary)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private static let timeFormatter: DateFormatter = {
|
||||
let f: DateFormatter = DateFormatter()
|
||||
f.dateFormat = "HH:mm:ss.SSS"
|
||||
return f
|
||||
}()
|
||||
|
||||
private static func formatTime(_ date: Date) -> String {
|
||||
timeFormatter.string(from: date)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Standalone window (Linux)
|
||||
|
||||
extension LyrebirdMessageView {
|
||||
|
||||
/// Opens a `LyrebirdWindow` hosting a message view bound to the shared
|
||||
/// `LyrebirdMessageCenter`. Requires a running `GtkApplication` loop.
|
||||
///
|
||||
/// - Important: Call on the GTK main thread (as the "Open Window" buttons and
|
||||
/// any top-level demo/`main()` code do). It reaches the `@MainActor`
|
||||
/// `LyrebirdMessageCenter.shared` via `assumeIsolated`, which traps if
|
||||
/// invoked off the main thread — from a background/script thread, use the
|
||||
/// `presentInWindow(center:...)` overload with an explicitly-resolved center.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - title: Window title-bar text. Defaults to `"Messages"`.
|
||||
/// - width: Initial width in points. Defaults to `460`.
|
||||
/// - height: Initial height in points. Defaults to `360`.
|
||||
/// - Returns: The `LyrebirdWindow` hosting the view.
|
||||
@discardableResult
|
||||
public static func presentInWindow(
|
||||
title: String = "Messages",
|
||||
width: Double = 460,
|
||||
height: Double = 360
|
||||
) -> LyrebirdWindow {
|
||||
// `LyrebirdMessageCenter.shared` is `@MainActor`; this runs on the GTK
|
||||
// main thread, so `assumeIsolated` reaches it (no `self` captured — no
|
||||
// sending-race), same hop the messages section uses.
|
||||
let center: LyrebirdMessageCenter = MainActor.assumeIsolated {
|
||||
LyrebirdMessageCenter.shared
|
||||
}
|
||||
return presentInWindow(
|
||||
center: center,
|
||||
title: title,
|
||||
width: width,
|
||||
height: height
|
||||
)
|
||||
}
|
||||
|
||||
/// Opens a `LyrebirdWindow` hosting a message view bound to `center`.
|
||||
@discardableResult
|
||||
public static func presentInWindow(
|
||||
center: LyrebirdMessageCenter,
|
||||
title: String = "Messages",
|
||||
width: Double = 460,
|
||||
height: Double = 360
|
||||
) -> LyrebirdWindow {
|
||||
let win: LyrebirdWindow = LyrebirdWindow(title: title, width: width, height: height)
|
||||
win.open {
|
||||
LyrebirdMessageView(center: center)
|
||||
}
|
||||
return win
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user