// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import Foundation /// A device editor's tabs and cards, as Android's DeviceLayouts describes them /// (exported to DeviceLayouts.json by IosGoldenExport) or, for devices whose /// Android editor is hand-built, as BespokeLayouts.swift lays them out. struct LayoutPage: Decodable, Identifiable { let title: String let panels: [LayoutPanel] var id: String { title } } struct LayoutPanel: Decodable, Identifiable { enum Tone: String, Decodable { case SOURCE, FILTER, ENV, MOD, OUT } struct Viz: Decodable { let kind: String // envelope | filter | lfo | wavetable var a: String? = nil, d: String? = nil, s: String? = nil, r: String? = nil var type: String? = nil, cutoff: String? = nil, reso: String? = nil var wave: String? = nil var osc: Int? = nil } let title: String let tone: Tone let keys: [String] var viz: Viz? = nil var labels: [String: String]? = nil var faders: [String]? = nil var faderScale: Float? = nil var action: String? = nil var id: String { title } } struct DeviceLayoutsFile: Decodable { let devices: [String: [LayoutPage]] let timeDivisions: [String] let delayDivisions: [String] } enum Layouts { /// Bundled with both the extension and the app (each finds its own copy). static let file: DeviceLayoutsFile? = { let bundle = Bundle(for: SizzleDeviceAU.self) guard let url = bundle.url(forResource: "DeviceLayouts", withExtension: "json"), let data = try? Data(contentsOf: url) else { return nil } return try? JSONDecoder().decode(DeviceLayoutsFile.self, from: data) }() static func pages(for type: String, allKeys: [String]) -> [LayoutPage] { if let bespoke = BespokeLayouts.pages[type] { return bespoke } if let pages = file?.devices[type], !pages.isEmpty { return pages } return [LayoutPage(title: type, panels: [LayoutPanel(title: type, tone: .SOURCE, keys: allKeys)])] } }