Files
sizzletracker-android/ios/app/Host/ContentView.swift
T
ReactorcoremeltdownandClaude Opus 5.5 7f231c8f79 iOS 0.2.0: instruments as AUv3, in-app host with keyboard, MIDI in and benchmark
Shared SizzleDeviceAU base for effects and instruments; sizzle::Instrument voice
pools; Android's factory presets generated into the specs header; the app hosts
every device in-process (no dependence on the system plugin registry).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:17:47 +01:00

113 lines
4.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
import UniformTypeIdentifiers
/// The app for now: play any Sizzle instrument through any Sizzle effect from the
/// keyboard or a MIDI controller, edit them, load samples, and measure each device
/// on this iPad. The tracker and the rest of Sizzle come in later milestones.
struct ContentView: View {
@StateObject private var model = HostModel()
@StateObject private var check = PluginCheck()
@State private var importing = false
@State private var pad = 0
@State private var showReport = false
var body: some View {
VStack(alignment: .leading, spacing: 10) {
header
controls
editor
HStack {
Button("−") { model.octave = max(0, model.octave - 1) }.buttonStyle(.bordered)
Text("C\(model.octave)").font(.system(.body, design: .monospaced)).frame(width: 40)
Button("+") { model.octave = min(7, model.octave + 1) }.buttonStyle(.bordered)
Spacer()
Text(model.host.midiSources.isEmpty ? "No MIDI input" : "MIDI: " + model.host.midiSources.joined(separator: ", "))
.font(.system(.caption, design: .monospaced)).foregroundColor(.gray).lineLimit(1)
}
KeyboardView(octave: model.octave,
noteOn: { model.host.note(on: Int32($0), velocity: 100) },
noteOff: { model.host.noteOff(Int32($0)) })
.frame(height: 150)
}
.padding()
.preferredColorScheme(.dark)
.fileImporter(isPresented: $importing, allowedContentTypes: [.audio, .data]) { result in
if case .success(let url) = result { model.loadSample(url, pad: pad) }
}
.sheet(isPresented: $showReport) { reportSheet }
.alert(model.message ?? "", isPresented: Binding(get: { model.message != nil }, set: { if !$0 { model.message = nil } })) {
Button("OK") { model.message = nil }
}
}
private var header: some View {
HStack(alignment: .firstTextBaseline) {
Text("Sizzle").font(.system(.largeTitle, design: .monospaced)).foregroundColor(.orange)
Text(versionLine).font(.system(.caption, design: .monospaced)).foregroundColor(.gray)
Spacer()
Button("Benchmark") { model.benchmark(); showReport = true }.disabled(model.busy)
Button("Check plugins") { showReport = true; Task { await check.run() } }
}
}
private var controls: some View {
HStack {
Menu {
ForEach(model.instruments, id: \.subtype) { d in Button(d.name) { model.select(d) } }
} label: { Label(model.instrument?.name ?? "Instrument", systemImage: "pianokeys") }
Image(systemName: "arrow.right").foregroundColor(.gray)
Menu {
Button("No effect") { model.selectEffect(nil) }
ForEach(model.effects, id: \.subtype) { d in Button(d.name) { model.selectEffect(d) } }
} label: { Label(model.effect?.name ?? "No effect", systemImage: "slider.horizontal.3") }
Spacer()
if model.effect != nil {
Picker("Edit", selection: $model.editingEffect) {
Text("Instrument").tag(false)
Text("Effect").tag(true)
}.pickerStyle(.segmented).frame(width: 220)
}
if model.canLoadSample {
if model.instrument?.toolboxType == "SAMPLER" {
Stepper("Pad \(pad + 1)", value: $pad, in: 0...15).frame(width: 150)
}
Button("Load sample…") { importing = true }
}
}
}
@ViewBuilder private var editor: some View {
if let unit = model.editedUnit {
DeviceEditorView(unit: unit)
.id(ObjectIdentifier(unit))
.frame(maxHeight: .infinity)
} else {
Spacer()
}
}
private var reportSheet: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Benchmark and plugin check").font(.headline)
ScrollView {
Text((model.report + [""] + check.lines).joined(separator: "\n"))
.font(.system(.footnote, design: .monospaced))
.frame(maxWidth: .infinity, alignment: .leading)
.textSelection(.enabled)
}
if model.busy { ProgressView() }
}
.padding()
.preferredColorScheme(.dark)
}
private var versionLine: String {
let v = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?"
let b = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "?"
return "\(v) (\(b))"
}
}