Files
Lyrebird/Demos/LyrebirdiOSDemo/LyrebirdiOSDemo/UI/NoteController.swift
T

59 lines
1.4 KiB
Swift

// NoteController.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Observation
import LyrebirdSynth
@MainActor
@Observable
final class NoteController {
let engine: SynthesisEngine
let synth: SineToneUI
let scopeCapture: ScopeCapture
private(set) var engineRunning: Bool = false
private(set) var isPlaying: Bool = false
init(engine: SynthesisEngine, synth: SineToneUI, scopeCapture: ScopeCapture) {
self.engine = engine
self.synth = synth
self.scopeCapture = scopeCapture
}
func toggleEngine() {
if engineRunning {
if isPlaying {
engine.remove(synth)
isPlaying = false
}
engine.stop()
engineRunning = false
} else {
do {
try engine.start()
engineRunning = true
} catch {
print("Engine failed to start: \(error)")
}
}
}
func toggle() {
if isPlaying {
engine.remove(synth)
isPlaying = false
} else {
do {
try engine.add(synth)
isPlaying = true
} catch {
print("[Lyrebird] NoteController.toggle add failed: \(error)")
}
}
}
}