iOS 0.6.0: milestone 5 (recording, MIDI, input bindings, themes, bundles, backups)

- Master recording (MasterSink ring + writer thread) and the sample recorder
- CoreMIDI in/out: sound module, clock send/follow, virtual "Sizzle" ports;
  platform-free parser/module/clock in core (midi_test)
- Hardware keyboard and gamepads via GameController; rebindable keyboard,
  gamepad and MIDI CC actions; per-parameter MIDI learn
- Colour themes (.szt), project bundles (.szgz), backup & restore;
  ZIP in core with zlib (zip_test against jar and unzip)
- Persistent app settings; audio pauses in the background unless sound module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 14:26:01 +01:00
co-authored by Claude Opus 5.5
parent 435305e42a
commit 64e21e0bcc
54 changed files with 3303 additions and 97 deletions
+81 -37
View File
@@ -5,10 +5,9 @@ import SwiftUI
import UniformTypeIdentifiers
/// The fourth tab, after Android's SettingsScreen: MIDI panic, the project
/// browser (save / load / new / delete, export and import of projects and .sng),
/// help and about, and the device lab. Android's other sections (audio devices,
/// recording, interface, themes, MIDI sync, bindings, backup) keep their places
/// as greyed-out cards until they're ported.
/// browser (save / load / new / delete, project bundles and .sng), audio route,
/// recording, interface, colour themes, MIDI sync, control bindings, backup and
/// restore, help and about, and the device lab.
struct SetupScreen: View {
@EnvironmentObject var app: AppModel
// SetupContent doesn't observe AppModel, so it isn't redrawn at the transport's rate.
@@ -27,6 +26,8 @@ private struct SetupContent: View {
@State private var importFormat = SetupModel.Format.sng
@State private var showDeviceLab = false
@State private var showPluginCheck = false
@State private var bindingSource: BindingKind?
@State private var confirmTheme: String?
var body: some View {
GeometryReader { geo in
@@ -37,13 +38,19 @@ private struct SetupContent: View {
panicButton
if wide {
HStack(alignment: .top, spacing: 14) {
VStack(spacing: 14) { projectCard; helpCard }
VStack(spacing: 14) { comingLater; diagnosticsCard }
VStack(spacing: 14) { projectCard; AudioDevicesCard(); RecordingCard(); backupCard; helpCard }
VStack(spacing: 14) { midiCard; BindingsCard { bindingSource = BindingKind($0) }; InterfaceCard(); themeCard; diagnosticsCard }
}
} else {
projectCard
AudioDevicesCard()
RecordingCard()
midiCard
BindingsCard { bindingSource = BindingKind($0) }
InterfaceCard()
themeCard
backupCard
helpCard
comingLater
diagnosticsCard
}
}
@@ -62,6 +69,28 @@ private struct SetupContent: View {
}
.deviceLab(isPresented: $showDeviceLab)
.pluginCheck(isPresented: $showPluginCheck)
.sheet(item: $bindingSource) { BindingsSheet(source: $0.source) }
}
/// Identifiable wrapper for the bindings sheet.
struct BindingKind: Identifiable {
let source: InputSource
init(_ s: InputSource) { source = s }
var id: String { "\(source)" }
}
// MARK: Cards with dialogs
/// The MIDI card isn't built in the Mac snapshots before MIDI starts; it lists nothing then.
private var midiCard: some View { MidiSyncCard() }
private var themeCard: some View {
ThemeCard(onImport: { pick(.theme) }, onDelete: { present(.confirmDeleteTheme($0)) },
onError: { show("Export failed", $0) })
}
private var backupCard: some View {
BackupCard(onBackup: backup, onRestore: { present(.confirmRestore) })
}
// MARK: Panic
@@ -96,11 +125,11 @@ private struct SetupContent: View {
SetupDivider()
HStack(spacing: 8) {
SetupButton(title: "Export project", icon: "square.and.arrow.up") { export(.project) }
SetupButton(title: "Export project", icon: "square.and.arrow.up") { exportBundle() }
SetupButton(title: "Import project", icon: "square.and.arrow.down.on.square") { pick(.project) }
}
SetupNote("A project file (.szg) carries patterns, mixer, FX and instruments, so it opens " +
"complete on another device (samples aren't included yet). Import replaces the current project.")
SetupNote("A bundle (.szgz) carries everything — patterns, mixer, FX, instruments and samples — so it opens " +
"complete on another device, Android too. Import takes a bundle or a .szg and replaces the current project.")
SetupDivider()
HStack(spacing: 8) {
@@ -178,29 +207,6 @@ private struct SetupContent: View {
return "\(name) v\(v)" + (build.map { " (\($0))" } ?? "")
}
// MARK: Sections still to come
private static let later: [(String, String, String)] = [
("Audio Devices", "Route playback / recording to USB or built-in", "hifispeaker"),
("Recording", "Record the master bus to WAV files", "record.circle"),
("Interface", "On-screen display options", "rectangle.on.rectangle"),
("Color Theme", "Pick, import, export or delete a palette", "paintpalette"),
("MIDI Sync", "MIDI clock in and out, sources, sound module", "metronome"),
("Gamepad Bindings", "Rebind buttons & combos", "gamecontroller"),
("Keyboard Hotkeys", "Rebind keyboard keys", "keyboard"),
("MIDI Bindings", "MIDI-learn controls", "pianokeys"),
("Backup & Restore", "Save or restore all songs, presets, themes & settings", "externaldrive"),
]
private var comingLater: some View {
SetupCard(title: "More settings", subtitle: "Coming in a later version", enabled: false) {
ForEach(Array(Self.later.enumerated()), id: \.offset) { i, s in
if i > 0 { SetupDivider() }
ComingLaterRow(title: s.0, subtitle: s.1, icon: s.2)
}
}
}
// MARK: Diagnostics
private var diagnosticsCard: some View {
@@ -247,6 +253,15 @@ private struct SetupContent: View {
confirm: "Delete", destructive: true, field: { EmptyView() },
onConfirm: { dismiss(); attempt("Delete failed") { try model.delete(name) } },
onCancel: dismiss)
case .confirmDeleteTheme(let name):
SetupDialogView(title: "Delete theme", message: "Delete \"\(name)\"? This cannot be undone.",
confirm: "Delete", destructive: true, field: { EmptyView() },
onConfirm: { dismiss(); ThemeLibrary.shared.delete(name) }, onCancel: dismiss)
case .confirmRestore:
SetupDialogView(title: "Restore backup",
message: "Replace every saved song, preset, theme, sample, the open song and the settings with a backup's?",
confirm: "Choose backup", destructive: true, field: { EmptyView() },
onConfirm: { dismiss(); pick(.backup) }, onCancel: dismiss)
case .message(let title, let text):
SetupDialogView(title: title, message: text, confirm: "OK", cancel: nil, field: { EmptyView() },
onConfirm: dismiss, onCancel: dismiss)
@@ -279,6 +294,20 @@ private struct SetupContent: View {
resetCursor()
}
private func exportBundle() {
attempt("Export failed") {
let url = try model.exportBundle()
ShareSheet.present(url) { try? FileManager.default.removeItem(at: url.deletingLastPathComponent()) }
}
}
private func backup() {
attempt("Backup failed") {
let url = try model.backupFile()
ShareSheet.present(url) { try? FileManager.default.removeItem(at: url.deletingLastPathComponent()) }
}
}
private func export(_ format: SetupModel.Format) {
attempt("Export failed") {
let url = try model.exportFile(format)
@@ -293,16 +322,31 @@ private struct SetupContent: View {
private func runImport(_ url: URL) {
do {
try model.importFile(url, as: importFormat)
switch importFormat {
case .theme:
guard ThemeLibrary.shared.importText(try SetupFiles.readText(url)) != nil else {
show("Import failed", "Couldn't import this file. It doesn't look like a valid .szt theme.")
return
}
return
case .backup:
try model.restoreBackup(url)
show("Backup restored", "Songs, presets, themes, samples and settings are back.")
default:
try model.importFile(url, as: importFormat)
}
resetCursor()
} catch let e as SetupFileError {
show("Import failed", e.localizedDescription)
} catch is CocoaError {
show("Import failed", "Couldn't read the selected file.")
} catch {
show("Import failed", importFormat == .sng
? "Couldn't import this file. It doesn't look like a valid .sng song."
: "Couldn't import this file. It doesn't look like a Sizzle project (.szg).")
switch importFormat {
case .sng: show("Import failed", "Couldn't import this file. It doesn't look like a valid .sng song.")
case .backup: show("Restore failed", error.localizedDescription)
default: show("Import failed", (error as NSError).domain == "Sizzle" ? error.localizedDescription
: "Couldn't import this file. It doesn't look like a Sizzle project (.szgz or .szg).")
}
}
}