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
|
||||
|
||||
@@ -331,3 +332,359 @@ extension LyrebirdEventListView {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Linux/GTK4 counterpart to `LyrebirdUI.LyrebirdEventListView`: transport for a
|
||||
// `LyrebirdEventList` (state dot + id, now/next event rows, dB amp slider,
|
||||
// Next/Back/Skip, Set Next, Reset/Release All/Kill All). The 10 Hz poll moves off
|
||||
// SwiftOpenUI's off-main `.task` onto a `Timer` on `RunLoop.main` inside an
|
||||
// `@Observable` model, which also carries the transport-derived UI flags. The
|
||||
// text field for "Set Next" stays plain `@State` on the view. dB↔amp maths reuse
|
||||
// the cross-platform `DbSliderConversion`; the amp control is a native `Slider`.
|
||||
//
|
||||
// SwiftOpenUI is always present in this target (see Package.swift).
|
||||
import SwiftOpenUI
|
||||
import LyrebirdSynth
|
||||
import Observation
|
||||
import Foundation
|
||||
|
||||
/// 10 Hz event-list poll interval.
|
||||
private let linuxEventListPollIntervalSeconds: TimeInterval = 0.1
|
||||
|
||||
/// Polls a `LyrebirdEventList`'s transport state on a main-thread timer and
|
||||
/// publishes it for ``LyrebirdEventListView``. Internal — only the view is public.
|
||||
///
|
||||
/// `@unchecked Sendable`: main-thread-confined; the `Timer` block is `@Sendable`,
|
||||
/// same rationale as `LyrebirdScopeModel`.
|
||||
@Observable
|
||||
final class LinuxEventListModel: @unchecked Sendable {
|
||||
|
||||
var isRunning: Bool = false
|
||||
var currentEvent: Int? = nil
|
||||
var nextEvent: Int? = nil
|
||||
var playIndex: Int = 0
|
||||
var amp: Double = 1.0
|
||||
var hasBeenStopped: Bool = false
|
||||
|
||||
@ObservationIgnored let eventList: LyrebirdEventList
|
||||
@ObservationIgnored private var timer: Timer?
|
||||
|
||||
init(eventList: LyrebirdEventList) {
|
||||
self.eventList = eventList
|
||||
// `amp` is @MainActor; construction happens on the GTK main thread.
|
||||
self.amp = MainActor.assumeIsolated { eventList.amp }
|
||||
}
|
||||
|
||||
deinit {
|
||||
timer?.invalidate()
|
||||
}
|
||||
|
||||
func start() {
|
||||
guard timer == nil else { return }
|
||||
refresh()
|
||||
let t: Timer = Timer.scheduledTimer(
|
||||
withTimeInterval: linuxEventListPollIntervalSeconds,
|
||||
repeats: true
|
||||
) { [weak self] _ in
|
||||
self?.refresh()
|
||||
}
|
||||
timer = t
|
||||
}
|
||||
|
||||
func stop() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
}
|
||||
|
||||
// Runs on the GTK main thread (view init / onAppear / RunLoop.main timer), so
|
||||
// `assumeIsolated` reaches the @MainActor `amp` safely. The other members are
|
||||
// nonisolated already.
|
||||
func refresh() {
|
||||
isRunning = eventList.isRunning
|
||||
currentEvent = eventList.currentEvent
|
||||
nextEvent = eventList.nextEvent
|
||||
playIndex = eventList.index
|
||||
amp = MainActor.assumeIsolated { eventList.amp }
|
||||
if !isRunning && currentEvent != nil {
|
||||
hasBeenStopped = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A control panel for driving a `LyrebirdEventList` on the Linux/GTK4 UI.
|
||||
/// Mirrors `LyrebirdUI.LyrebirdEventListView`; same public API/init as the Apple
|
||||
/// side.
|
||||
public struct LyrebirdEventListView: View {
|
||||
|
||||
public let eventList: LyrebirdEventList
|
||||
|
||||
@State private var model: LinuxEventListModel
|
||||
@State private var setNextField: String = ""
|
||||
|
||||
// Layout constants (points).
|
||||
private let dotSize: Double = 10
|
||||
private let ampLabelWidth: Double = 36
|
||||
private let dbReadoutWidth: Double = 56
|
||||
private let setNextFieldWidth: Double = 80
|
||||
private let disabledDotOpacity: Double = 0.4
|
||||
|
||||
/// Creates an event-list control view bound to the given list.
|
||||
///
|
||||
/// - Parameter eventList: The `LyrebirdEventList` to control.
|
||||
public init(eventList: LyrebirdEventList) {
|
||||
self.eventList = eventList
|
||||
_model = State(wrappedValue: LinuxEventListModel(eventList: eventList))
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
header
|
||||
Divider()
|
||||
currentNextRows
|
||||
Divider()
|
||||
ampRow
|
||||
Divider()
|
||||
transportRow
|
||||
setNextRow
|
||||
stopRow
|
||||
}
|
||||
.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) {
|
||||
Circle()
|
||||
.fill(model.isRunning ? Color.green : Color.secondary.opacity(disabledDotOpacity))
|
||||
.frame(width: dotSize, height: dotSize)
|
||||
Text(eventList.id)
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text("\(eventList.eventCount) events")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
private var currentNextRows: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
EventRow(
|
||||
label: "Now",
|
||||
index: model.currentEvent,
|
||||
description: descriptionForEvent(at: model.currentEvent)
|
||||
)
|
||||
EventRow(
|
||||
label: "Next",
|
||||
index: model.nextEvent,
|
||||
description: descriptionForEvent(at: model.nextEvent)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private var ampRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text("Amp")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: ampLabelWidth, alignment: .leading)
|
||||
Slider(value: Binding(
|
||||
get: { dbFromAmp(model.amp) },
|
||||
set: { newDb in
|
||||
let newAmp: Double = ampFromDb(newDb)
|
||||
model.amp = newAmp
|
||||
// Bind `eventList` (Sendable) to a local so the @MainActor
|
||||
// closure captures it, not `self` (the non-Sendable View).
|
||||
let el: LyrebirdEventList = eventList
|
||||
MainActor.assumeIsolated { el.amp = newAmp }
|
||||
}
|
||||
), in: LyrebirdEventListView.minDb ... LyrebirdEventListView.maxDb)
|
||||
Text(dbDisplay(dbFromAmp(model.amp)))
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.primary)
|
||||
.frame(width: dbReadoutWidth, alignment: .trailing)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - dB <-> linear amplitude (shared via `DbSliderConversion`)
|
||||
|
||||
private static let minDb: Double = DbSliderConversion.minDb
|
||||
private static let maxDb: Double = DbSliderConversion.maxDb
|
||||
|
||||
private func ampFromDb(_ db: Double) -> Double { DbSliderConversion.ampFromDb(db) }
|
||||
private func dbFromAmp(_ amp: Double) -> Double { DbSliderConversion.dbFromAmp(amp) }
|
||||
private func dbDisplay(_ db: Double) -> String { DbSliderConversion.dbDisplay(db) }
|
||||
|
||||
private var transportRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
Button("Next") {
|
||||
let el: LyrebirdEventList = eventList
|
||||
MainActor.assumeIsolated { el.next() }
|
||||
}
|
||||
.disabled(model.nextEvent == nil)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Back") {
|
||||
let cur: Int = eventList.index
|
||||
guard cur > 0 else { return }
|
||||
eventList.index = cur - 1
|
||||
model.refresh()
|
||||
}
|
||||
.disabled(model.playIndex <= 0)
|
||||
Button("Skip") {
|
||||
let cur: Int = eventList.index
|
||||
guard cur < eventList.eventCount else { return }
|
||||
eventList.index = cur + 1
|
||||
model.refresh()
|
||||
}
|
||||
.disabled(model.nextEvent == nil)
|
||||
}
|
||||
}
|
||||
|
||||
private var setNextRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text("Set Next")
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
TextField("index", text: $setNextField)
|
||||
.frame(maxWidth: setNextFieldWidth)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
Button("Apply") {
|
||||
applySetNext()
|
||||
}
|
||||
.disabled(parsedSetNext() == nil)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
private var stopRow: some View {
|
||||
HStack(spacing: 8) {
|
||||
Button("Reset") {
|
||||
let el: LyrebirdEventList = eventList
|
||||
MainActor.assumeIsolated { el.reset() }
|
||||
model.hasBeenStopped = false
|
||||
model.refresh()
|
||||
}
|
||||
.disabled(!model.hasBeenStopped)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Release All") {
|
||||
let el: LyrebirdEventList = eventList
|
||||
MainActor.assumeIsolated { el.releaseAll() }
|
||||
model.hasBeenStopped = true
|
||||
model.refresh()
|
||||
}
|
||||
.disabled(!model.isRunning || model.hasBeenStopped)
|
||||
|
||||
Button("Kill All") {
|
||||
let el: LyrebirdEventList = eventList
|
||||
MainActor.assumeIsolated { el.killAll() }
|
||||
model.hasBeenStopped = true
|
||||
model.refresh()
|
||||
}
|
||||
.disabled(!model.isRunning || model.hasBeenStopped)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func descriptionForEvent(at index: Int?) -> String {
|
||||
guard let i: Int = index, i >= 0, i < eventList.eventCount else { return "—" }
|
||||
let event: LyrebirdEvent = eventList.events[i]
|
||||
let startIDs: [String] = event.starts.map(\.id)
|
||||
let releaseIDs: [String] = event.releases.map(\.id)
|
||||
|
||||
var parts: [String] = []
|
||||
if !startIDs.isEmpty { parts.append("▶ " + startIDs.joined(separator: ", ")) }
|
||||
if !releaseIDs.isEmpty { parts.append("⏹ " + releaseIDs.joined(separator: ", ")) }
|
||||
return parts.isEmpty ? "(empty event)" : parts.joined(separator: " ")
|
||||
}
|
||||
|
||||
private func parsedSetNext() -> Int? {
|
||||
guard let i: Int = Int(setNextField.trimmingCharacters(in: .whitespaces)) else { return nil }
|
||||
guard i >= 0, i < eventList.eventCount else { return nil }
|
||||
return i
|
||||
}
|
||||
|
||||
private func applySetNext() {
|
||||
guard let i: Int = parsedSetNext() else { return }
|
||||
eventList.index = i
|
||||
setNextField = ""
|
||||
model.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Sub-views
|
||||
|
||||
private struct EventRow: View {
|
||||
let label: String
|
||||
let index: Int?
|
||||
let description: String
|
||||
|
||||
private let labelWidth: Double = 36
|
||||
private let indexWidth: Double = 32
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text(label)
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: labelWidth, alignment: .leading)
|
||||
Text(indexText)
|
||||
.font(.caption)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.primary)
|
||||
.frame(width: indexWidth, alignment: .leading)
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.primary)
|
||||
.lineLimit(2)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
private var indexText: String {
|
||||
if let i: Int = index { return "#\(i)" }
|
||||
return "—"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Standalone window (Linux)
|
||||
|
||||
extension LyrebirdEventListView {
|
||||
|
||||
/// Opens a `LyrebirdWindow` hosting an event-list control view. Requires a
|
||||
/// running `GtkApplication` loop.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - eventList: The `LyrebirdEventList` to control.
|
||||
/// - title: Window title-bar text. Defaults to `"Event List"`.
|
||||
/// - width: Initial window width in points. Defaults to `360`.
|
||||
/// - height: Initial window height in points. Defaults to `260`.
|
||||
/// - Returns: The `LyrebirdWindow` hosting the view.
|
||||
@discardableResult
|
||||
public static func presentInWindow(
|
||||
eventList: LyrebirdEventList,
|
||||
title: String = "Event List",
|
||||
width: Double = 360,
|
||||
height: Double = 260
|
||||
) -> LyrebirdWindow {
|
||||
let win: LyrebirdWindow = LyrebirdWindow(title: title, width: width, height: height)
|
||||
win.open {
|
||||
LyrebirdEventListView(eventList: eventList)
|
||||
}
|
||||
return win
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user