iOS 0.3.0: card editors like Android's for every plugin (knobs, switches, tabs, drawings)
Layouts exported from Android's DeviceLayouts (DeviceLayouts.json), iOS layouts for the devices with hand-built Android editors, SwiftUI editor shared by the extension and the app, Mac snapshot tool for the editors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
47588990ce
commit
b6589ee792
@@ -0,0 +1,86 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
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).
|
||||
struct ParamInfo {
|
||||
let param: AUParameter
|
||||
let key: String
|
||||
let label: String
|
||||
let min: Float
|
||||
let max: Float
|
||||
let def: Float
|
||||
let isInt: Bool
|
||||
let choices: [String]
|
||||
var isEnum: Bool { !choices.isEmpty }
|
||||
/// On/off switches stored as 0..1 numbers (the Tape Delay's "Head N On").
|
||||
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.
|
||||
@MainActor
|
||||
final class DeviceModel: ObservableObject {
|
||||
let au: SizzleDeviceAU
|
||||
let params: [String: ParamInfo]
|
||||
let order: [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
|
||||
self.values = values
|
||||
presetName = au.currentPreset?.name
|
||||
token = au.parameterTree?.token(byAddingParameterObserver: { [weak self] address, value in
|
||||
DispatchQueue.main.async { self?.observed(address: address, value: 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
|
||||
}
|
||||
|
||||
func value(_ key: String) -> Float { values[key] ?? params[key]?.def ?? 0 }
|
||||
|
||||
func set(_ key: String, _ v: Float) {
|
||||
guard let info = params[key] else { return }
|
||||
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)
|
||||
}
|
||||
|
||||
func choice(_ key: String) -> String {
|
||||
guard let info = params[key], info.isEnum else { return "" }
|
||||
let i = Int(value(key).rounded())
|
||||
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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user