iOS 0.4.0: Sizzle's Tracker, Mix, Toolbox and Setup tabs on the C++ engine

Ported from the Android tabs by parallel agents (each screen with its own
SizzleSession category); slot editors use the card editor with a preset
library; songs load/save in the Android project format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 09:32:30 +01:00
co-authored by Claude Opus 5.5
parent 29650b88d7
commit 962cfd1e2b
35 changed files with 4088 additions and 66 deletions
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation
/// Export and import files for the Setup tab (Foundation only).
enum SetupFiles {
/// Writes [text] to a fresh temporary folder as "<song name>.<ext>" (the name
/// the share sheet and Files show), clearing earlier exports first.
static func export(_ text: String, songName: String, ext: String) throws -> URL {
let root = FileManager.default.temporaryDirectory.appendingPathComponent("Exports", isDirectory: true)
try? FileManager.default.removeItem(at: root)
let dir = root.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
let url = dir.appendingPathComponent(fileStem(songName)).appendingPathExtension(ext)
try text.write(to: url, atomically: true, encoding: .utf8)
return url
}
/// The song name as a file name: path separators replaced, blank → "untitled".
static func fileStem(_ name: String) -> String {
let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines)
let safe = trimmed.components(separatedBy: CharacterSet(charactersIn: "/\\:")).joined(separator: "_")
return safe.isEmpty || safe.hasPrefix(".") ? "untitled" + safe : safe
}
/// Reads a picked file as text (security-scoped, as .fileImporter hands it over).
static func readText(_ url: URL) throws -> String {
let scoped = url.startAccessingSecurityScopedResource()
defer { if scoped { url.stopAccessingSecurityScopedResource() } }
let data = try Data(contentsOf: url)
// Song files are small text; refuse anything huge before decoding.
guard data.count <= 32 << 20 else { throw SetupFileError.tooLarge }
guard let text = String(data: data, encoding: .utf8) ?? String(data: data, encoding: .isoLatin1) else {
throw SetupFileError.notText
}
return text
}
}
enum SetupFileError: LocalizedError {
case tooLarge, notText
var errorDescription: String? {
switch self {
case .tooLarge: return "The file is too large to be a Sizzle song."
case .notText: return "Couldn't read the selected file."
}
}
}