Shared SizzleDeviceAU base for effects and instruments; sizzle::Instrument voice pools; Android's factory presets generated into the specs header; the app hosts every device in-process (no dependence on the system plugin registry). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.2 KiB
Swift
65 lines
2.2 KiB
Swift
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import SwiftUI
|
|
|
|
/// The app's state around SizzleHost: which devices play, which editor shows,
|
|
/// and the results of the benchmark / plugin check.
|
|
@MainActor
|
|
final class HostModel: ObservableObject {
|
|
let host = SizzleHost()
|
|
let devices = SizzleHost.devices
|
|
var instruments: [SizzleHostDevice] { devices.filter { $0.isInstrument } }
|
|
var effects: [SizzleHostDevice] { devices.filter { !$0.isInstrument } }
|
|
|
|
@Published var instrument: SizzleHostDevice?
|
|
@Published var effect: SizzleHostDevice?
|
|
/// Which device's editor is shown: false = the instrument, true = the effect.
|
|
@Published var editingEffect = false
|
|
@Published var octave = 4
|
|
@Published var report: [String] = []
|
|
@Published var busy = false
|
|
@Published var message: String?
|
|
|
|
init() {
|
|
if let first = instruments.first { select(first) }
|
|
}
|
|
|
|
func select(_ device: SizzleHostDevice) {
|
|
host.selectInstrument(device) { [weak self] error in
|
|
guard let self = self else { return }
|
|
if let error = error { self.message = error.localizedDescription; return }
|
|
self.instrument = device
|
|
self.editingEffect = false
|
|
}
|
|
}
|
|
|
|
func selectEffect(_ device: SizzleHostDevice?) {
|
|
host.selectEffect(device) { [weak self] error in
|
|
guard let self = self else { return }
|
|
if let error = error { self.message = error.localizedDescription; return }
|
|
self.effect = device
|
|
self.editingEffect = device != nil
|
|
}
|
|
}
|
|
|
|
var editedUnit: SizzleDeviceAU? { editingEffect ? host.effect : host.instrument }
|
|
|
|
var canLoadSample: Bool {
|
|
let t = instrument?.toolboxType
|
|
return t == "SAMPLER" || t == "SOUNDFONT"
|
|
}
|
|
|
|
func loadSample(_ url: URL, pad: Int) {
|
|
do { try host.loadSample(from: url, pad: Int32(pad)) }
|
|
catch { message = error.localizedDescription }
|
|
}
|
|
|
|
func benchmark() {
|
|
busy = true
|
|
report = []
|
|
host.benchmark({ [weak self] line in self?.report.append(line) },
|
|
done: { [weak self] in self?.busy = false })
|
|
}
|
|
}
|