b6fdee8bfc
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>
78 lines
2.9 KiB
Swift
78 lines
2.9 KiB
Swift
// main.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Runnable Linux live-coding scratchpad:
|
|
//
|
|
// swift run LyrebirdScratchLinuxDemo
|
|
//
|
|
// Opens a GTK4 window with a code editor + Run/Clear + a live scope + a console.
|
|
// Type Swift, press Run: the snippet is compiled to a .so, dlopen'd, and run
|
|
// against the shared libLyrebirdDynamic, playing into the running engine. Needs
|
|
// libgtk-4-dev to build and (for sound) a live ALSA device; without ALSA the
|
|
// editor still compiles + runs snippets, just silently.
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
import LyrebirdLiveCompile
|
|
import LyrebirdLiveCompileUI
|
|
import LyrebirdUI // GTK4Backend / App / WindowGroup, via @_exported re-exports
|
|
|
|
private let scratchBlockSize: Int = 512
|
|
private let scratchSampleRate: Double = 44_100.0
|
|
private let scratchOutputChannels: Int = 2
|
|
private let scratchInputChannels: Int = 0
|
|
|
|
let scratchDriver: any AudioDriver = makeDefaultAudioDriver()
|
|
let scratchEngine: SynthesisEngine = SynthesisEngine(
|
|
blockSize: scratchBlockSize,
|
|
sampleRate: scratchSampleRate,
|
|
numOutputChannels: scratchOutputChannels,
|
|
numInputChannels: scratchInputChannels,
|
|
driver: scratchDriver
|
|
)
|
|
|
|
// Construct the session BEFORE start() so it can install its scope tap (the RT
|
|
// thread caches the tap at start()).
|
|
let scratchSession: LiveSession = LiveSession(engine: scratchEngine)
|
|
|
|
do {
|
|
try scratchEngine.start()
|
|
} catch {
|
|
print("[Lyrebird] scratch engine start failed: \(error)")
|
|
}
|
|
|
|
if !isLiveAudioAvailable {
|
|
print("[Lyrebird] no live audio backend — snippets still compile + run, but there is no sound.")
|
|
}
|
|
|
|
// Register the GTK pointer sink so a snippet's `Mouse.X.Control()` /
|
|
// `Mouse.Y.Control()` / `Mouse.Click.Control()` read live values. Without this
|
|
// the shared `MouseInput` bridge is never installed and `Mouse.X` sits at its
|
|
// default, so e.g. `OscSin.Audio(freq: Mouse.X.Control() * 100)` never
|
|
// modulates. Install timing is not sensitive on Linux (SwiftOpenUI attaches the
|
|
// pointer controllers to every window it opens); the snippet reads the same
|
|
// process-global singleton in the shared libLyrebird.
|
|
MouseTracker.installShared()
|
|
|
|
// The app owns the model so the File menu commands (New / Open… / Save /
|
|
// Save As…, with Ctrl+N/O/S accelerators) can bind to the same instance the
|
|
// view renders — SwiftOpenUI declares `.commands` on the Scene, not the View.
|
|
let scratchModel: LinuxScratchModel = LinuxScratchModel(session: scratchSession)
|
|
|
|
// `LiveSession` / `LinuxScratchModel` are `@unchecked Sendable`, so they cross
|
|
// into SwiftOpenUI's nonisolated scene closure directly.
|
|
struct LyrebirdScratchApp: App {
|
|
var body: some Scene {
|
|
WindowGroup("Lyrebird Scratch") {
|
|
LyrebirdScratchLinuxView(model: scratchModel)
|
|
}
|
|
.commands {
|
|
lyrebirdScratchFileCommands(model: scratchModel)
|
|
}
|
|
}
|
|
}
|
|
|
|
GTK4Backend().run(LyrebirdScratchApp.self)
|