// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import SwiftUI /// A labelled switch (Android's ToggleRow). struct SetupToggle: View { let title: String let detail: String let isOn: Bool let onChange: (Bool) -> Void var body: some View { Toggle(isOn: Binding(get: { isOn }, set: onChange)) { VStack(alignment: .leading, spacing: 2) { Text(title).font(.system(size: 15, weight: .medium)).foregroundColor(Theme.text) Text(detail).font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true) } } .tint(Theme.accent) } } /// Audio Devices: iOS picks the route; this shows it and offers the system picker. struct AudioDevicesCard: View { var body: some View { SetupCard(title: "Audio Devices", subtitle: "Playback and recording go where iOS routes audio") { AudioRouteView() SetupNote("Plug in an audio interface or headphones, or pick AirPlay / Bluetooth with the route button. " + "The sample recorder records from the current input.") } } } /// Recording: where master takes go and the FX tail (the ARM button is on Mix). struct RecordingCard: View { @ObservedObject var settings = AppSettings.shared var body: some View { SetupCard(title: "Recording", subtitle: "Record the master bus to WAV files") { HStack(spacing: 8) { Text("FX tail after stop").font(.system(size: 15)).foregroundColor(Theme.text) Spacer() ForEach(0..<5, id: \.self) { n in SetupButton(title: "\(n)", kind: settings.recordTailBars == n ? .filled : .outlined) { settings.recordTailBars = n SizzleSession.shared.recordTailBars = n } } } SetupNote("Arm with ● ARM on the Mix tab; the take starts on Play (or an external MIDI clock Start) and " + "ends this many bars after the stop. Takes are in Files › On My iPad › Sizzle › Recordings.") } } } /// Interface: the mixer meters (Android's InterfaceCard). struct InterfaceCard: View { @ObservedObject var settings = AppSettings.shared var body: some View { SetupCard(title: "Interface", subtitle: "On-screen display options") { SetupToggle(title: "Mixer VU meters", detail: "Show live level meters inside the mixer volume faders.", isOn: settings.vuMeters) { settings.vuMeters = $0 } } } } /// Color Theme: pick, import, export or delete (Android's ThemeCard). struct ThemeCard: View { @ObservedObject var library = ThemeLibrary.shared let onImport: () -> Void let onDelete: (String) -> Void let onError: (String) -> Void var body: some View { let current = Theme.current.name SetupCard(title: "Color Theme", subtitle: "Pick, import, export or delete a palette") { HStack(spacing: 8) { Menu { ForEach(library.names, id: \.self) { name in Button(name + (library.isStock(name) ? " (stock)" : "")) { library.select(name) } } } label: { HStack(spacing: 6) { Text(current).font(.system(size: 15, weight: .medium)).lineLimit(1) Image(systemName: "chevron.down").font(.system(size: 12)) } .foregroundColor(Theme.text) .padding(.horizontal, 14).frame(minHeight: 38) .overlay(Capsule().stroke(Theme.grid, lineWidth: 1)) } if !library.isStock(current) { SetupButton(title: "Delete", kind: .danger) { onDelete(current) } } } SetupDivider() HStack(spacing: 8) { SetupButton(title: "Export .szt", icon: "square.and.arrow.up") { do { ShareSheet.present(try library.exportFile()) } catch { onError(error.localizedDescription) } } SetupButton(title: "Import .szt", icon: "square.and.arrow.down.on.square", action: onImport) } SetupNote("Stock themes can't be deleted; imported .szt themes appear in the list.") } } } /// MIDI Sync: clock out / in, sound-module mode and the MIDI sources (Android's /// MidiSyncCard + MidiInputsList). struct MidiSyncCard: View { @ObservedObject var settings = AppSettings.shared @ObservedObject var midi = MidiSources.shared var body: some View { SetupCard(title: "MIDI Sync", subtitle: "MIDI clock and notes over USB, Bluetooth, network and other apps") { SetupToggle(title: "Send MIDI clock", detail: "Send clock, start/stop and the tracks' notes to MIDI devices and apps, so Sizzle drives them.", isOn: settings.sendMidiClock) { settings.sendMidiClock = $0; SizzleMidi.shared.sendClock = $0 } SetupDivider() SetupToggle(title: "Receive MIDI clock", detail: "Follow an external clock's tempo, and start/stop Sizzle's own song with it " + "(tempo only while Sizzle runs as a MIDI sound module).", isOn: settings.receiveMidiClock) { settings.receiveMidiClock = $0; SizzleMidi.shared.receiveClock = $0 } SetupDivider() SetupToggle(title: "Keep running as MIDI sound module", detail: "Keep playing incoming MIDI with Sizzle in the background (another app can use it as its synth). " + "Sizzle's own song doesn't start from the other app's clock meanwhile.", isOn: settings.soundModule) { settings.soundModule = $0; SizzleMidi.shared.soundModule = $0 } SetupDivider() HStack { VStack(alignment: .leading, spacing: 2) { Text("MIDI inputs").font(.system(size: 15, weight: .medium)).foregroundColor(Theme.text) Text("Sources Sizzle listens to. Each mixer track plays the notes on its MIDI channel. " + "Other apps can also send to the \"Sizzle\" MIDI destination.") .font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true) } Spacer() SetupButton(title: "Reconnect") { SizzleMidi.shared.reconnect() } } if midi.sources.isEmpty { SetupNote("No MIDI sources found.") } ForEach(midi.sources, id: \.key) { src in SetupToggle(title: src.name, detail: !src.enabled ? "Off" : src.connected ? "Listening" : "Not connected (tap Reconnect)", isOn: src.enabled) { on in if on { settings.midiSourcesOff.remove(src.key) } else { settings.midiSourcesOff.insert(src.key) } SizzleMidi.shared.setSourceKey(src.key, enabled: on) } } SetupDivider() BluetoothMidiSection() } } } /// SizzleMidi's source list as an observable (refreshed on its change callback). @MainActor final class MidiSources: ObservableObject { static let shared = MidiSources() @Published private(set) var sources: [SizzleMidiSource] = [] private init() { sources = SizzleMidi.shared.sources SizzleMidi.shared.onSourcesChanged = { [weak self] in self?.sources = SizzleMidi.shared.sources } } } /// The three binding editors (Android's Gamepad Bindings / Keyboard Hotkeys / MIDI Bindings). struct BindingsCard: View { let open: (InputSource) -> Void var body: some View { SetupCard(title: "Controls", subtitle: "Hardware keyboard, gamepad and MIDI controller bindings") { SetupRow(title: "Gamepad Bindings", detail: "Rebind buttons, sticks and combos", icon: "gamecontroller") { open(.gamepad) } SetupDivider() SetupRow(title: "Keyboard Hotkeys", detail: "Rebind keys; Z…M and Q…U play notes", icon: "keyboard") { open(.keyboard) } SetupDivider() SetupRow(title: "MIDI Bindings", detail: "MIDI-learn controls for transport and editing", icon: "pianokeys") { open(.midi) } } } } /// Backup & Restore (Android's BackupCard). struct BackupCard: View { let onBackup: () -> Void let onRestore: () -> Void var body: some View { SetupCard(title: "Backup & Restore", subtitle: "Save or restore all songs, presets, themes & settings") { HStack(spacing: 8) { SetupButton(title: "Back up", icon: "externaldrive", kind: .filled, action: onBackup) SetupButton(title: "Restore", icon: "arrow.counterclockwise", action: onRestore) } SetupNote("A backup is one .zip with every saved song, preset, theme, sample, the open song and the settings. " + "Restoring replaces all of them.") } } } /// Bluetooth LE MIDI controllers (the Android app's Bluetooth MIDI list): the /// system panel finds and connects them; connected ones join the MIDI inputs /// above and are remembered, to reconnect at every launch until forgotten. struct BluetoothMidiSection: View { @ObservedObject var ble = BluetoothMidi.shared var body: some View { HStack { VStack(alignment: .leading, spacing: 2) { Text("Bluetooth MIDI").font(.system(size: 15, weight: .medium)).foregroundColor(Theme.text) Text("Find Bluetooth LE MIDI controllers and connect them. Connected ones are listed with the " + "MIDI inputs and reconnect at every launch.") .font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true) } Spacer() SetupButton(title: "Find controllers", icon: "antenna.radiowaves.left.and.right") { BluetoothMidiPanel.present { ble.panelClosed() } } } ForEach(ble.remembered.sorted { $0.value < $1.value }, id: \.key) { id, name in HStack { VStack(alignment: .leading, spacing: 2) { Text(name).font(.system(size: 15)).foregroundColor(Theme.text) Text("Remembered — reconnects at launch").font(.system(size: 12)).foregroundColor(Theme.dim) } Spacer() SetupButton(title: "Forget") { ble.forget(id) } } } } }