Files
ReactorcoremeltdownandClaude Opus 5.5 3b035d6a7d iOS milestone 4 groundwork: bespoke editor registry and data sources
Device editors ask BespokeEditors for headers, whole bodies, drawings and card
actions; DeviceDataSource gives them DSP data and hidden settings, backed by app
slots (SlotDataSource) or AUs (AUDataSource, hidden values in SizzleDeviceAU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:47:25 +01:00

38 lines
1.7 KiB
Swift

// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation
extension DeviceModel {
/// Backed by toolbox slot [slot] of the open song.
convenience init(session: SizzleSession, slot: Int) {
let type = session.type(ofSlot: slot)
let specs = SizzleSession.paramSpecs(forType: type)
let infos = specs.map { s in
ParamInfo(key: s.key, label: s.label, min: s.minValue, max: s.maxValue, def: s.defaultValue,
isInt: s.isInt, choices: s.choices)
}
func read() -> [String: Float] {
var v: [String: Float] = [:]
for s in specs {
let text = session.value(ofSlot: slot, key: s.key)
if s.choices.isEmpty { v[s.key] = Float(text) ?? s.defaultValue }
else { v[s.key] = Float(s.choices.firstIndex(of: text) ?? Int(s.defaultValue)) }
}
return v
}
let byKey = Dictionary(uniqueKeysWithValues: specs.map { ($0.key, $0) })
self.init(toolboxType: type, displayName: session.name(ofSlot: slot), infos: infos, values: read(),
presetNames: session.factoryPresets(forType: type),
write: { key, v in
guard let s = byKey[key] else { return }
if s.choices.isEmpty { session.setNumber(v, ofSlot: slot, key: key) }
else { session.setValue(s.choices[max(0, min(s.choices.count - 1, Int(v.rounded())))], ofSlot: slot, key: key) }
},
applyPreset: { name in session.applyFactoryPreset(name, toSlot: slot) },
reread: read)
data = SlotDataSource(session: session, slot: slot)
}
}