iOS milestone 3 groundwork: SizzleSession bridge, app shell with tabs, slot-backed editors, screen snapshots

SizzleSession owns the song, engine (192-frame chunks, try-lock on the audio
thread), samples and audio output; AppModel/RootView give the four tabs;
DeviceModel now works on toolbox slots too; make screen-snapshots renders the
app's tabs on the Mac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 09:15:28 +01:00
co-authored by Claude Opus 5.5
parent 7bc54e6466
commit 29650b88d7
26 changed files with 1211 additions and 47 deletions
+15
View File
@@ -3,6 +3,21 @@
import SwiftUI
/// Rendering for the Mac snapshot tools (make editor-snapshots / screen-snapshots):
/// ImageRenderer can't draw scroll views, so content scrolls only when not snapshotting.
enum Snapshot {
static var active = false
}
/// A vertical ScrollView, or a plain stack in snapshot mode.
struct SnapScroll<Content: View>: View {
@ViewBuilder let content: () -> Content
var body: some View {
if Snapshot.active { VStack(spacing: 0) { content(); Spacer(minLength: 0) } }
else { ScrollView { content() } }
}
}
/// Sizzle's dark retro palette (Android's default theme) and the card tones.
enum Theme {
static let background = Color(red: 0.07, green: 0.08, blue: 0.09)
+5 -7
View File
@@ -13,18 +13,16 @@ import UIKit
struct DeviceEditor: View {
@StateObject var model: DeviceModel
@State var page = 0
/// Render without a ScrollView (the Mac snapshot tool; ImageRenderer can't draw one).
static var snapshot = false
var body: some View {
let pages = Layouts.pages(for: model.au.toolboxType, allKeys: model.order)
let pages = Layouts.pages(for: model.toolboxType, allKeys: model.order)
VStack(alignment: .leading, spacing: 8) {
HStack {
Text(model.au.displayName.uppercased()).font(Theme.mono(15)).foregroundColor(Theme.accent)
Text(model.displayName.uppercased()).font(Theme.mono(15)).foregroundColor(Theme.accent)
Spacer()
if let presets = model.au.factoryPresets, !presets.isEmpty {
if !model.presetNames.isEmpty {
Menu {
ForEach(presets, id: \.number) { p in Button(p.name) { model.applyPreset(p) } }
ForEach(model.presetNames, id: \.self) { name in Button(name) { model.applyPreset(named: name) } }
} label: {
Text("PRESET: \(model.presetName ?? "—") ▾").font(Theme.mono(12)).foregroundColor(Theme.accent)
}
@@ -51,7 +49,7 @@ struct DeviceEditor: View {
CardView(panel: panel, model: model)
}
}
if DeviceEditor.snapshot { cards; Spacer(minLength: 0) } else { ScrollView { cards } }
SnapScroll { cards }
}
.padding(10)
.background(Theme.background)
+54 -37
View File
@@ -4,10 +4,8 @@
import AudioToolbox
import Foundation
/// One parameter as the editor sees it: the AU parameter plus what Sizzle's spec
/// says about it (default, whole numbers, label).
/// One parameter as the editor sees it: what Sizzle's spec says about it.
struct ParamInfo {
let param: AUParameter
let key: String
let label: String
let min: Float
@@ -20,46 +18,65 @@ struct ParamInfo {
var isToggle: Bool { !isEnum && key.hasSuffix("On") && min == 0 && max == 1 }
}
/// The editor's view of a SizzleDeviceAU: every parameter's value, kept in step
/// with the AU (host automation, presets) through a parameter observer.
/// The editor's view of one device, whichever backs it: an AUv3 (the plugin
/// extension, the device lab) or a toolbox slot of the open song (the app's
/// Toolbox tab). Values are numbers; choice lists by index.
@MainActor
final class DeviceModel: ObservableObject {
let au: SizzleDeviceAU
let toolboxType: String
let displayName: String
let params: [String: ParamInfo]
let order: [String]
let presetNames: [String]
@Published private(set) var values: [String: Float] = [:]
@Published var presetName: String?
private var token: AUParameterObserverToken?
init(au: SizzleDeviceAU) {
self.au = au
var params: [String: ParamInfo] = [:]
var order: [String] = []
var values: [String: Float] = [:]
for p in au.parameterTree?.allParameters ?? [] {
let info = ParamInfo(param: p, key: p.identifier, label: au.specLabel(for: p),
min: p.minValue, max: p.maxValue, def: au.defaultValue(for: p),
isInt: au.isIntegerParameter(p), choices: p.valueStrings ?? [])
params[p.identifier] = info
order.append(p.identifier)
values[p.identifier] = p.value
}
self.params = params
self.order = order
private let write: (String, Float) -> Void
private let applyPresetNamed: (String) -> Void
private let reread: () -> [String: Float]
private var cleanup: () -> Void = {}
/// The designated initializer; the app adds a slot-backed one (Host/SlotDeviceModel.swift).
init(toolboxType: String, displayName: String, infos: [ParamInfo], values: [String: Float],
presetNames: [String], write: @escaping (String, Float) -> Void,
applyPreset: @escaping (String) -> Void, reread: @escaping () -> [String: Float]) {
self.toolboxType = toolboxType
self.displayName = displayName
self.params = Dictionary(uniqueKeysWithValues: infos.map { ($0.key, $0) })
self.order = infos.map { $0.key }
self.values = values
self.presetNames = presetNames
self.write = write
self.applyPresetNamed = applyPreset
self.reread = reread
}
deinit { cleanup() }
/// Backed by an AUv3: its parameter tree, presets and host automation.
convenience init(au: SizzleDeviceAU) {
let all = au.parameterTree?.allParameters ?? []
let infos = all.map { p in
ParamInfo(key: p.identifier, label: au.specLabel(for: p), min: p.minValue, max: p.maxValue,
def: au.defaultValue(for: p), isInt: au.isIntegerParameter(p), choices: p.valueStrings ?? [])
}
let byKey = Dictionary(uniqueKeysWithValues: all.map { ($0.identifier, $0) })
let presets = au.factoryPresets ?? []
var token: AUParameterObserverToken?
self.init(toolboxType: au.toolboxType, displayName: au.displayName, infos: infos,
values: Dictionary(uniqueKeysWithValues: all.map { ($0.identifier, $0.value) }),
presetNames: presets.map { $0.name },
write: { key, v in byKey[key]?.setValue(v, originator: token) },
applyPreset: { name in if let p = presets.first(where: { $0.name == name }) { au.currentPreset = p } },
reread: { Dictionary(uniqueKeysWithValues: all.map { ($0.identifier, $0.value) }) })
presetName = au.currentPreset?.name
token = au.parameterTree?.token(byAddingParameterObserver: { [weak self] address, value in
DispatchQueue.main.async { self?.observed(address: address, value: value) }
DispatchQueue.main.async {
guard let self = self, let p = all.first(where: { $0.address == address }) else { return }
self.values[p.identifier] = value
}
})
}
deinit {
if let token = token { au.parameterTree?.removeParameterObserver(token) }
}
private func observed(address: AUParameterAddress, value: AUValue) {
guard let p = au.parameterTree?.parameter(withAddress: address) else { return }
values[p.identifier] = value
if let tree = au.parameterTree, let t = token { cleanup = { tree.removeParameterObserver(t) } }
}
func value(_ key: String) -> Float { values[key] ?? params[key]?.def ?? 0 }
@@ -69,7 +86,7 @@ final class DeviceModel: ObservableObject {
var x = Swift.min(Swift.max(v, info.min), info.max)
if info.isInt { x = x.rounded() }
values[key] = x
info.param.setValue(x, originator: token)
write(key, x)
}
func choice(_ key: String) -> String {
@@ -78,9 +95,9 @@ final class DeviceModel: ObservableObject {
return info.choices[Swift.max(0, Swift.min(info.choices.count - 1, i))]
}
func applyPreset(_ preset: AUAudioUnitPreset) {
au.currentPreset = preset
presetName = preset.name
for (key, info) in params { values[key] = info.param.value }
func applyPreset(named name: String) {
applyPresetNamed(name)
presetName = name
values = reread()
}
}