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:
co-authored by
Claude Opus 5.5
parent
435305e42a
commit
64e21e0bcc
@@ -0,0 +1,103 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// One device kind's bindings (Android's binding sections and BindingRow): each
|
||||
/// action with its current control, LEARN (then press the key / combo or move the
|
||||
/// MIDI control) and ✕ to unbind.
|
||||
struct BindingsSheet: View {
|
||||
let source: InputSource
|
||||
@ObservedObject private var bindings = InputBindings.shared
|
||||
@ObservedObject private var input = InputController.shared
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
private struct Group { let title: String; let actions: [(id: String, label: String)] }
|
||||
|
||||
private var groups: [Group] {
|
||||
var g = [
|
||||
Group(title: "Transport", actions: [("playPause", "Play / Pause"), ("stop", "Stop"), ("loop", "Toggle Loop")]),
|
||||
Group(title: "Navigation", actions: [("up", "Cursor Up"), ("down", "Cursor Down"), ("left", "Cursor Left"), ("right", "Cursor Right")]),
|
||||
Group(title: "Editing", actions: [("increment", "Value +"), ("decrement", "Value -"), ("clear", "Clear Cell")]
|
||||
+ (source == .keyboard ? [("noteOff", "Note Off")] : [])),
|
||||
]
|
||||
if source == .keyboard {
|
||||
g.append(Group(title: "Columns", actions: [("nextColumn", "Next Column"), ("prevColumn", "Prev Column")]))
|
||||
g.append(Group(title: "Octave", actions: [("octaveDown", "Octave Down"), ("octaveUp", "Octave Up")]))
|
||||
}
|
||||
g.append(Group(title: "Tabs", actions: [("nextTab", "Next Tab"), ("prevTab", "Prev Tab")]))
|
||||
return g
|
||||
}
|
||||
|
||||
private var title: String {
|
||||
switch source {
|
||||
case .gamepad: return "Gamepad Bindings"
|
||||
case .keyboard: return "Keyboard Hotkeys"
|
||||
default: return "MIDI Bindings"
|
||||
}
|
||||
}
|
||||
|
||||
private var hint: String {
|
||||
switch source {
|
||||
case .gamepad: return "LEARN, then press a button, D-pad direction or stick direction — or hold one and press another for a combo."
|
||||
case .keyboard: return "LEARN, then press a key. Unbound letter keys play the tracker piano (Z…M, Q…U)."
|
||||
default: return "LEARN, then press a pad or move a control on your MIDI controller (CC)."
|
||||
}
|
||||
}
|
||||
|
||||
private func label(_ id: String) -> String? {
|
||||
switch source {
|
||||
case .gamepad: return bindings.chordFor(id).map(InputBindings.chordLabel)
|
||||
case .keyboard: return bindings.keyFor(id).map(InputBindings.keyLabel)
|
||||
default: return bindings.ccFor(id).map { "CC \($0)" }
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack {
|
||||
Text(title).font(.system(size: 19, weight: .semibold)).foregroundColor(Theme.accent)
|
||||
Spacer()
|
||||
SetupButton(title: "Defaults") { bindings.resetDefaults(source) }
|
||||
SetupButton(title: "Done", kind: .filled) { dismiss() }
|
||||
}
|
||||
Text(hint).font(.system(size: 12)).foregroundColor(Theme.dim)
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
ForEach(groups, id: \.title) { group in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(group.title.uppercased()).font(.system(size: 11, weight: .semibold)).foregroundColor(Theme.dim)
|
||||
ForEach(group.actions, id: \.id) { a in row(a.id, a.label) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
.background(Theme.surface.ignoresSafeArea())
|
||||
.preferredColorScheme(.dark)
|
||||
.onDisappear { input.cancelLearn() }
|
||||
}
|
||||
|
||||
private func row(_ id: String, _ text: String) -> some View {
|
||||
let listening = input.learnTarget == id
|
||||
let bound = label(id)
|
||||
return HStack(spacing: 10) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(text).font(.system(size: 15)).foregroundColor(Theme.text)
|
||||
Text(bound ?? "unbound").font(.system(size: 12, design: .monospaced)).foregroundColor(bound == nil ? Theme.dim : Theme.accent)
|
||||
}
|
||||
Spacer()
|
||||
SetupButton(title: listening ? "Listening…" : "Learn", kind: listening ? .filled : .outlined) {
|
||||
if listening { input.cancelLearn() } else { input.beginLearn(id, source: source) }
|
||||
}
|
||||
if bound != nil {
|
||||
Button { bindings.clear(id, source: source) } label: {
|
||||
Image(systemName: "xmark").foregroundColor(Theme.dim).frame(width: 36, height: 36)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import SwiftUI
|
||||
/// buttons, link rows, rows for sections still to come, and the modal dialog.
|
||||
/// SwiftUI only (the Mac snapshot tool renders them).
|
||||
enum SetupStyle {
|
||||
static let danger = Color(red: 0.86, green: 0.27, blue: 0.27)
|
||||
static var danger: Color { Theme.danger }
|
||||
static let corner: CGFloat = 10
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ enum SetupDialog: Identifiable {
|
||||
case save
|
||||
case confirmNew
|
||||
case confirmDelete(String)
|
||||
case confirmDeleteTheme(String)
|
||||
case confirmRestore
|
||||
case message(title: String, text: String)
|
||||
|
||||
var id: String {
|
||||
@@ -152,6 +154,8 @@ enum SetupDialog: Identifiable {
|
||||
case .save: return "save"
|
||||
case .confirmNew: return "new"
|
||||
case .confirmDelete(let n): return "delete:" + n
|
||||
case .confirmDeleteTheme(let n): return "theme:" + n
|
||||
case .confirmRestore: return "restore"
|
||||
case .message(let t, let m): return "msg:" + t + m
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,28 @@ enum SetupFiles {
|
||||
return url
|
||||
}
|
||||
|
||||
/// Writes [data] to a fresh temporary folder as "<name>.<ext>".
|
||||
static func export(_ data: Data, name: 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(name).appendingPathExtension(ext)
|
||||
try data.write(to: url)
|
||||
return url
|
||||
}
|
||||
|
||||
/// Reads a picked file (security-scoped), refusing anything over [limit] bytes.
|
||||
static func readData(_ url: URL, limit: Int) throws -> Data {
|
||||
let scoped = url.startAccessingSecurityScopedResource()
|
||||
defer { if scoped { url.stopAccessingSecurityScopedResource() } }
|
||||
let size = (try? url.resourceValues(forKeys: [.fileSizeKey]).fileSize) ?? 0
|
||||
guard size <= limit else { throw SetupFileError.tooLarge }
|
||||
let data = try Data(contentsOf: url)
|
||||
guard data.count <= limit else { throw SetupFileError.tooLarge }
|
||||
return data
|
||||
}
|
||||
|
||||
/// The song name as a file name: path separators replaced, blank → "untitled".
|
||||
static func fileStem(_ name: String) -> String {
|
||||
let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
@@ -42,7 +64,7 @@ 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 .tooLarge: return "The file is too large for Sizzle."
|
||||
case .notText: return "Couldn't read the selected file."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,9 @@ final class SetupModel: ObservableObject {
|
||||
|
||||
// MARK: Export / import
|
||||
|
||||
/// What a picked file is for.
|
||||
enum Format {
|
||||
case sng, project
|
||||
case sng, project, theme, backup
|
||||
var ext: String { self == .sng ? "sng" : "szg" }
|
||||
}
|
||||
|
||||
@@ -77,11 +78,47 @@ final class SetupModel: ObservableObject {
|
||||
/// Imports a picked file: a .sng into the open song (notes, blocks,
|
||||
/// arrangement), or a project replacing it.
|
||||
func importFile(_ url: URL, as format: Format) throws {
|
||||
if format == .project {
|
||||
// A bundle (.szgz, a ZIP) or a plain project (.szg).
|
||||
let data = try SetupFiles.readData(url, limit: 64 << 20)
|
||||
if SizzleSession.isZip(data) { try session.importProjectBundleData(data) }
|
||||
else if let text = String(data: data, encoding: .utf8) { try session.importProjectText(text) }
|
||||
else { throw SetupFileError.notText }
|
||||
refresh()
|
||||
return
|
||||
}
|
||||
let text = try SetupFiles.readText(url)
|
||||
switch format {
|
||||
case .sng: try session.importSngText(text)
|
||||
case .project: try session.importProjectText(text)
|
||||
default: try session.importProjectText(text)
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
|
||||
/// The open song as a bundle, "<song>.szgz" in a temporary folder.
|
||||
func exportBundle() throws -> URL {
|
||||
guard let data = session.projectBundleData() else { throw SetupFileError.notText }
|
||||
return try SetupFiles.export(data, name: SetupFiles.fileStem(songName), ext: "szgz")
|
||||
}
|
||||
|
||||
/// Everything as "sizzle-backup-yyyyMMdd-HHmm.zip" (Android names it the same way).
|
||||
func backupFile() throws -> URL {
|
||||
guard let data = session.backupData(withSettings: AppSettings.shared.exportText()) else { throw SetupFileError.notText }
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "en_US_POSIX")
|
||||
f.dateFormat = "yyyyMMdd-HHmm"
|
||||
return try SetupFiles.export(data, name: "sizzle-backup-" + f.string(from: Date()), ext: "zip")
|
||||
}
|
||||
|
||||
/// Restore a backup, then apply its settings, bindings and theme.
|
||||
func restoreBackup(_ url: URL) throws {
|
||||
let data = try SetupFiles.readData(url, limit: 1 << 30)
|
||||
let settings = try session.restoreBackupData(data)
|
||||
if !settings.isEmpty { AppSettings.shared.importText(settings) }
|
||||
InputBindings.shared.reload()
|
||||
ThemeLibrary.shared.refresh()
|
||||
ThemeLibrary.shared.select(AppSettings.shared.paletteName)
|
||||
session.recordTailBars = AppSettings.shared.recordTailBars
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import SwiftUI
|
||||
// DeviceLabView / PluginCheck), so there they are no-ops.
|
||||
|
||||
#if canImport(UIKit)
|
||||
import AVKit
|
||||
import UIKit
|
||||
|
||||
enum ShareSheet {
|
||||
@@ -79,8 +80,53 @@ private struct PluginCheckSheet: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The system's audio route picker (AirPlay, Bluetooth, an interface) and the
|
||||
/// current route's names (Android's audio device rows; iOS chooses the route).
|
||||
struct AudioRouteView: View {
|
||||
@State private var output = AudioRouteView.names(\.outputs)
|
||||
@State private var input = AudioRouteView.names(\.inputs)
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack(spacing: 10) {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text("Output: " + output).font(.system(size: 14)).foregroundColor(Theme.text)
|
||||
Text("Input: " + input).font(.system(size: 14)).foregroundColor(Theme.text)
|
||||
}
|
||||
Spacer()
|
||||
RoutePicker().frame(width: 44, height: 44)
|
||||
}
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: AVAudioSession.routeChangeNotification).receive(on: RunLoop.main)) { _ in
|
||||
output = Self.names(\.outputs)
|
||||
input = Self.names(\.inputs)
|
||||
}
|
||||
}
|
||||
|
||||
static func names(_ kp: KeyPath<AVAudioSessionRouteDescription, [AVAudioSessionPortDescription]>) -> String {
|
||||
let ports = AVAudioSession.sharedInstance().currentRoute[keyPath: kp].map(\.portName)
|
||||
return ports.isEmpty ? "—" : ports.joined(separator: ", ")
|
||||
}
|
||||
|
||||
private struct RoutePicker: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> AVRoutePickerView {
|
||||
let v = AVRoutePickerView()
|
||||
v.tintColor = UIColor(Theme.accent)
|
||||
v.activeTintColor = UIColor(Theme.accent)
|
||||
return v
|
||||
}
|
||||
func updateUIView(_ v: AVRoutePickerView, context: Context) {}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
struct AudioRouteView: View {
|
||||
var body: some View {
|
||||
Text("Output: Speaker\nInput: Microphone").font(.system(size: 14)).foregroundColor(Theme.text)
|
||||
}
|
||||
}
|
||||
|
||||
enum ShareSheet {
|
||||
@MainActor static func present(_ url: URL, done: @escaping () -> Void = {}) { done() }
|
||||
}
|
||||
|
||||
@@ -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).")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user