// VectorOscillatorController.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Observation import LyrebirdSynth @MainActor @Observable final class VectorOscillatorController { let engine: SynthesisEngine let synth: VectorOscillatorUI let scopeCapture: ScopeCapture private(set) var engineRunning: Bool = false private(set) var isPlaying: Bool = false init( engine: SynthesisEngine, synth: VectorOscillatorUI, 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] VectorOscillatorController.toggle add failed: \(error)") } } } }