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
|
||||
|
||||
@@ -193,3 +194,188 @@ extension LyrebirdRunningProcessesView {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Linux/GTK4 counterpart to `LyrebirdUI.LyrebirdRunningProcessesView`: one
|
||||
// ``LyrebirdProcessView`` per currently-running `LyrebirdProcess` in an event
|
||||
// list. The 10 Hz refresh moves off SwiftOpenUI's off-main `.task` onto a `Timer`
|
||||
// on `RunLoop.main` inside an `@Observable` model. The identity-stable
|
||||
// reassignment (only swap the array when the running set changes) is preserved so
|
||||
// child rows keep their own poll timers and per-row state across ticks.
|
||||
//
|
||||
// SwiftOpenUI is always present in this target (see Package.swift).
|
||||
import SwiftOpenUI
|
||||
import LyrebirdSynth
|
||||
import Observation
|
||||
import Foundation
|
||||
|
||||
/// 10 Hz — matches ``LyrebirdProcessView``.
|
||||
private let linuxRunningProcessesPollIntervalSeconds: TimeInterval = 0.1
|
||||
|
||||
/// Polls an event list's running processes on a main-thread timer and publishes
|
||||
/// an identity-stable snapshot for ``LyrebirdRunningProcessesView``. Internal.
|
||||
///
|
||||
/// `@unchecked Sendable`: main-thread-confined; the `Timer` block is `@Sendable`,
|
||||
/// same rationale as `LyrebirdScopeModel`.
|
||||
@Observable
|
||||
final class LinuxRunningProcessesModel: @unchecked Sendable {
|
||||
|
||||
var running: [LyrebirdProcess] = []
|
||||
|
||||
@ObservationIgnored private var timer: Timer?
|
||||
@ObservationIgnored private let eventList: LyrebirdEventList
|
||||
|
||||
init(eventList: LyrebirdEventList) {
|
||||
self.eventList = eventList
|
||||
}
|
||||
|
||||
deinit {
|
||||
timer?.invalidate()
|
||||
}
|
||||
|
||||
func start() {
|
||||
guard timer == nil else { return }
|
||||
refresh()
|
||||
let t: Timer = Timer.scheduledTimer(
|
||||
withTimeInterval: linuxRunningProcessesPollIntervalSeconds,
|
||||
repeats: true
|
||||
) { [weak self] _ in
|
||||
self?.refresh()
|
||||
}
|
||||
timer = t
|
||||
}
|
||||
|
||||
func stop() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
}
|
||||
|
||||
func refresh() {
|
||||
let snapshot: [LyrebirdProcess] = eventList.allProcesses.filter { $0.isRunning }
|
||||
if !LinuxRunningProcessesModel.sameIdentities(snapshot, running) {
|
||||
running = snapshot
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` when two arrays contain the same `LyrebirdProcess` instances in the
|
||||
/// same order. Identity-only — does not inspect process state.
|
||||
private static func sameIdentities(
|
||||
_ a: [LyrebirdProcess],
|
||||
_ b: [LyrebirdProcess]
|
||||
) -> Bool {
|
||||
guard a.count == b.count else { return false }
|
||||
for i: Int in 0..<a.count where a[i] !== b[i] { return false }
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/// A panel of the currently-running processes in an event list for the Linux/GTK4
|
||||
/// UI. Mirrors `LyrebirdUI.LyrebirdRunningProcessesView`; same public API/init.
|
||||
public struct LyrebirdRunningProcessesView: View {
|
||||
|
||||
public let eventList: LyrebirdEventList
|
||||
public let engine: SynthesisEngine
|
||||
|
||||
@State private var model: LinuxRunningProcessesModel
|
||||
|
||||
/// Creates a running-processes panel bound to the given event list.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - eventList: The `LyrebirdEventList` whose running processes are shown.
|
||||
/// - engine: The `SynthesisEngine` forwarded to each child
|
||||
/// ``LyrebirdProcessView`` for its **Start** button.
|
||||
public init(
|
||||
eventList: LyrebirdEventList,
|
||||
engine: SynthesisEngine
|
||||
) {
|
||||
self.eventList = eventList
|
||||
self.engine = engine
|
||||
_model = State(wrappedValue: LinuxRunningProcessesModel(eventList: eventList))
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
header
|
||||
Divider()
|
||||
if model.running.isEmpty {
|
||||
emptyRow
|
||||
} else {
|
||||
ForEach(model.running, id: \.lyrebirdObjectID) { proc in
|
||||
LyrebirdProcessView(process: proc, engine: engine)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
.background(Color.lyrebirdControlBackground)
|
||||
.frame(minWidth: 320)
|
||||
.onAppear { model.start() }
|
||||
.onDisappear { model.stop() }
|
||||
}
|
||||
|
||||
// MARK: - Sub-rows
|
||||
|
||||
private var header: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text("Running")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text("\(model.running.count)")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyRow: some View {
|
||||
Text("No running processes")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ObjectIdentifier helper
|
||||
|
||||
private extension LyrebirdProcess {
|
||||
/// Stable identity for `ForEach`. `LyrebirdProcess` is a class, so
|
||||
/// `ObjectIdentifier` is the natural identity; not added to the core module
|
||||
/// because `ObjectIdentifier` conformance is a UI concern.
|
||||
var lyrebirdObjectID: ObjectIdentifier { ObjectIdentifier(self) }
|
||||
}
|
||||
|
||||
// MARK: - Standalone window (Linux)
|
||||
|
||||
extension LyrebirdRunningProcessesView {
|
||||
|
||||
/// Opens a ``LyrebirdWindow`` hosting a running-processes panel. Requires a
|
||||
/// running `GtkApplication` loop.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - eventList: The `LyrebirdEventList` to track.
|
||||
/// - engine: The `SynthesisEngine` forwarded to each child
|
||||
/// ``LyrebirdProcessView``.
|
||||
/// - title: Window title-bar text. Defaults to `"<eventList.id> — Running"`.
|
||||
/// - width: Initial window width in points. Defaults to `360`.
|
||||
/// - height: Initial window height in points. Defaults to `420`.
|
||||
/// - Returns: The ``LyrebirdWindow`` hosting the view.
|
||||
@discardableResult
|
||||
public static func presentInWindow(
|
||||
eventList: LyrebirdEventList,
|
||||
engine: SynthesisEngine,
|
||||
title: String? = nil,
|
||||
width: Double = 360,
|
||||
height: Double = 420
|
||||
) -> LyrebirdWindow {
|
||||
let win: LyrebirdWindow = LyrebirdWindow(
|
||||
title: title ?? "\(eventList.id) — Running",
|
||||
width: width,
|
||||
height: height
|
||||
)
|
||||
win.open {
|
||||
LyrebirdRunningProcessesView(eventList: eventList, engine: engine)
|
||||
}
|
||||
return win
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user