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
+208
View File
@@ -0,0 +1,208 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The Mix and Toolbox screens' building blocks, ported from Android's
/// components/Widgets.kt (RetroButton, RepeatButton, RetroDropdown, SectionLabel).
/// Namespaced so they can't clash with the other screens' own.
enum MixKit {
/// Android palette colours the shared Theme doesn't carry.
static let playhead = Color(red: 0x7C / 255, green: 0xFC / 255, blue: 0x9A / 255)
static let danger = Color(red: 0xE0 / 255, green: 0x5A / 255, blue: 0x4B / 255)
/// Pitch.name: 60 -> "C-4", 61 -> "C#4".
static func pitchName(_ midi: Int) -> String {
guard (0...127).contains(midi) else { return "..." }
let names = ["C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"]
return names[midi % 12] + String(midi / 12 - 1)
}
/// RetroButtonSurface: square corners, 1 pt border, accent when active, red for danger.
struct Face: View {
let label: String
var active = false
var danger = false
var width: CGFloat? = nil
var fill = false
var body: some View {
let hue: Color? = danger ? MixKit.danger : (active ? Theme.accent : nil)
Text(label).font(Theme.mono(12)).lineLimit(1).truncationMode(.tail)
.foregroundColor(hue ?? Theme.text)
.padding(.horizontal, 10).padding(.vertical, 6)
.frame(width: width)
.frame(maxWidth: fill ? .infinity : nil)
.background(hue?.opacity(0.18) ?? Theme.surface)
.overlay(Rectangle().stroke(hue ?? Theme.grid, lineWidth: 1))
.contentShape(Rectangle())
}
}
/// RetroButton: tap to act.
struct Button: View {
let label: String
var active = false
var danger = false
var width: CGFloat? = nil
var fill = false
let action: () -> Void
var body: some View {
Face(label: label, active: active, danger: danger, width: width, fill: fill)
.onTapGesture(perform: action)
}
}
/// RepeatButton: steps once on press, then repeats while held, faster and faster
/// (320 ms, ×0.8 each time, down to 24 ms). Dragging off stops it.
struct RepeatButton: View {
let label: String
var width: CGFloat? = nil
let onStep: () -> Void
@StateObject private var repeater = Repeater()
var body: some View {
Face(label: label, width: width)
.gesture(DragGesture(minimumDistance: 0)
.onChanged { g in
if abs(g.translation.width) > 24 || abs(g.translation.height) > 24 { repeater.stop() }
else if !repeater.pressed { repeater.start(onStep) }
}
.onEnded { _ in repeater.stop(); repeater.pressed = false })
}
}
@MainActor final class Repeater: ObservableObject {
var pressed = false
private var timer: Timer?
private var delay = 0.32
private var step: (() -> Void)?
func start(_ step: @escaping () -> Void) {
pressed = true
self.step = step
delay = 0.32
step()
schedule()
}
private func schedule() {
timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { [weak self] _ in
Task { @MainActor in self?.fire() }
}
}
private func fire() {
guard timer != nil, let step = step else { return }
step()
delay = max(0.024, delay * 0.8)
schedule()
}
func stop() {
timer?.invalidate()
timer = nil
step = nil
}
}
/// SectionLabel: a dim upper-case header.
struct SectionLabel: View {
let text: String
var body: some View {
Text(text.uppercased()).font(Theme.mono(11)).foregroundColor(Theme.dim).padding(.vertical, 4)
}
}
/// RetroDropdown: `LABEL:value ▾`, as wide as its longest option so it never
/// jumps. Tap opens the list (in balanced columns past 12 rows, like Android's);
/// an optional long press does something else (the mixer opens the device).
struct Dropdown<T: Hashable>: View {
let label: String
let options: [T]
let selected: T
var fill = false
let optionLabel: (T) -> String
var onLongPress: (() -> Void)? = nil
let onSelect: (T) -> Void
@State private var open = false
var body: some View {
let prefix = label.isEmpty ? "" : label + ":"
let longest = options.map(optionLabel).max { $0.count < $1.count } ?? ""
ZStack(alignment: .leading) {
Text(prefix + longest + " ▾").foregroundColor(.clear)
Text(prefix + optionLabel(selected) + " ▾").foregroundColor(Theme.text).truncationMode(.tail)
}
.font(Theme.mono(12)).lineLimit(1)
.padding(.horizontal, 8).padding(.vertical, 6)
.frame(maxWidth: fill ? .infinity : nil, alignment: .leading)
.background(Theme.surface)
.overlay(Rectangle().stroke(Theme.grid, lineWidth: 1))
.contentShape(Rectangle())
.onTapGesture { open = true }
.onLongPressGesture { onLongPress?() }
.popover(isPresented: $open) { menu }
}
private static var maxRows: Int { 12 }
@ViewBuilder private var menu: some View {
let n = options.count
let cols = n <= Self.maxRows ? 1 : (n + Self.maxRows - 1) / Self.maxRows
if cols <= 4 {
let perCol = (n + cols - 1) / Swift.max(cols, 1)
HStack(alignment: .top, spacing: 0) {
ForEach(0..<cols, id: \.self) { c in
VStack(alignment: .leading, spacing: 0) {
ForEach(Array(options[Swift.min(n, c * perCol)..<Swift.min(n, (c + 1) * perCol)]), id: \.self) { opt in row(opt) }
}
}
}
.padding(4)
.background(Theme.surface.ignoresSafeArea())
} else {
// Very long lists (the LFO's targets) scroll in one column instead.
SnapScroll {
VStack(alignment: .leading, spacing: 0) { ForEach(options, id: \.self) { row($0) } }.padding(4)
}
.frame(minWidth: 320, minHeight: 420)
.background(Theme.surface.ignoresSafeArea())
}
}
private func row(_ opt: T) -> some View {
Text(optionLabel(opt)).font(Theme.mono(13)).lineLimit(1)
.foregroundColor(opt == selected ? Theme.accent : Theme.text)
.padding(.horizontal, 12).padding(.vertical, 8)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
.onTapGesture { onSelect(opt); open = false }
}
}
/// A horizontal ScrollView, or a plain row while snapshotting.
struct HScroll<Content: View>: View {
@ViewBuilder let content: () -> Content
var body: some View {
if Snapshot.active { content() }
else { ScrollView(.horizontal, showsIndicators: false) { content() } }
}
}
}
/// Re-renders the Mix and Toolbox screens when the song changes, without the
/// AppModel's transport polling (which would redraw them on every tracker line).
@MainActor
final class MixSongWatch: ObservableObject {
static let shared = MixSongWatch()
@Published private(set) var revision = 0
private var observer: NSObjectProtocol?
private init() {
observer = NotificationCenter.default.addObserver(forName: .SizzleSessionDidChange, object: nil, queue: .main) { [weak self] _ in
Task { @MainActor in self?.revision += 1 }
}
}
}