- 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>
248 lines
10 KiB
Swift
248 lines
10 KiB
Swift
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import SwiftUI
|
|
|
|
/// Rendering for the Mac snapshot tools (make editor-snapshots / screen-snapshots):
|
|
/// ImageRenderer can't draw scroll views, so content scrolls only when not snapshotting.
|
|
enum Snapshot {
|
|
static var active = false
|
|
}
|
|
|
|
/// A vertical ScrollView, or a plain stack in snapshot mode.
|
|
struct SnapScroll<Content: View>: View {
|
|
@ViewBuilder let content: () -> Content
|
|
var body: some View {
|
|
if Snapshot.active { VStack(spacing: 0) { content(); Spacer(minLength: 0) } }
|
|
else { ScrollView { content() } }
|
|
}
|
|
}
|
|
|
|
/// A colour theme (Android's RetroPalette), colours as 0xRRGGBB.
|
|
struct Palette: Equatable {
|
|
var name: String
|
|
var background, surface, grid, text, textDim, accent, beat, bar, playhead, danger: UInt32
|
|
|
|
static let amber = Palette(name: "Amber CRT", background: 0x0B0D0E, surface: 0x15181A, grid: 0x23282B,
|
|
text: 0xCFE8D8, textDim: 0x6E7C74, accent: 0xF2C14E, beat: 0x141C1A, bar: 0x1E2A20,
|
|
playhead: 0x7CFC9A, danger: 0xE05A4B)
|
|
static let ice = Palette(name: "Ice Terminal", background: 0x07090F, surface: 0x10151F, grid: 0x1E2633,
|
|
text: 0xCFE0FF, textDim: 0x63708A, accent: 0x62B6FF, beat: 0x121A26, bar: 0x1B2740,
|
|
playhead: 0x8AF0FF, danger: 0xE05A7A)
|
|
static let stock = [amber, ice]
|
|
|
|
static func color(_ rgb: UInt32) -> Color {
|
|
Color(red: Double((rgb >> 16) & 0xFF) / 255, green: Double((rgb >> 8) & 0xFF) / 255, blue: Double(rgb & 0xFF) / 255)
|
|
}
|
|
}
|
|
|
|
/// Sizzle's retro palette (the current theme; the plugins always use the default)
|
|
/// and the card tones. The app redraws everything when the theme changes.
|
|
enum Theme {
|
|
static var current = Palette.amber
|
|
static var background: Color { Palette.color(current.background) }
|
|
static var surface: Color { Palette.color(current.surface) }
|
|
static var grid: Color { Palette.color(current.grid) }
|
|
static var text: Color { Palette.color(current.text) }
|
|
static var dim: Color { Palette.color(current.textDim) }
|
|
static var accent: Color { Palette.color(current.accent) }
|
|
static var beat: Color { Palette.color(current.beat) }
|
|
static var bar: Color { Palette.color(current.bar) }
|
|
static var playhead: Color { Palette.color(current.playhead) }
|
|
static var danger: Color { Palette.color(current.danger) }
|
|
|
|
static func tone(_ t: LayoutPanel.Tone) -> Color {
|
|
switch t {
|
|
case .SOURCE: return accent
|
|
case .FILTER: return Color(red: 0.45, green: 0.85, blue: 0.55)
|
|
case .ENV: return Color(red: 0.96, green: 0.56, blue: 0.69)
|
|
case .MOD: return Color(red: 0.70, green: 0.62, blue: 1.0)
|
|
case .OUT: return text
|
|
}
|
|
}
|
|
|
|
static func mono(_ size: CGFloat) -> Font { .system(size: size, design: .monospaced) }
|
|
}
|
|
|
|
/// A rotary knob like Android's: slide up/down to turn (a full sweep takes 280 pt,
|
|
/// independent of the knob's size, so fine moves are easy), double-tap to reset.
|
|
/// Bipolar ranges fill from the centre.
|
|
struct KnobView: View {
|
|
let label: String
|
|
let valueText: String
|
|
let value: Float
|
|
let min: Float
|
|
let max: Float
|
|
let def: Float
|
|
let tone: Color
|
|
let onChange: (Float) -> Void
|
|
|
|
@State private var dragStart: Float?
|
|
private let travel: Float = 280
|
|
|
|
var body: some View {
|
|
let span = max > min ? max - min : 1
|
|
let frac = CGFloat(Swift.min(1, Swift.max(0, (value - min) / span)))
|
|
let zero = CGFloat(Swift.min(1, Swift.max(0, (0 - min) / span)))
|
|
let bipolar = min < 0 && max > 0
|
|
VStack(spacing: 3) {
|
|
Text(valueText).font(Theme.mono(10)).foregroundColor(Theme.text).lineLimit(1).minimumScaleFactor(0.7)
|
|
ZStack {
|
|
Arc(from: 0, to: 1).stroke(Theme.grid, style: StrokeStyle(lineWidth: 4, lineCap: .round))
|
|
Arc(from: bipolar ? Swift.min(zero, frac) : 0, to: bipolar ? Swift.max(zero, frac) : frac)
|
|
.stroke(tone, style: StrokeStyle(lineWidth: 4, lineCap: .round))
|
|
Pointer(frac: frac).stroke(Theme.text, style: StrokeStyle(lineWidth: 2, lineCap: .round))
|
|
}
|
|
.frame(width: 46, height: 46)
|
|
.contentShape(Rectangle())
|
|
.gesture(DragGesture(minimumDistance: 1)
|
|
.onChanged { g in
|
|
if dragStart == nil { dragStart = value }
|
|
let v = (dragStart ?? value) - Float(g.translation.height) / travel * span
|
|
onChange(Swift.min(max, Swift.max(min, v)))
|
|
}
|
|
.onEnded { _ in dragStart = nil })
|
|
.onTapGesture(count: 2) { onChange(def) }
|
|
Text(label.uppercased()).font(Theme.mono(9)).foregroundColor(Theme.dim).lineLimit(1).minimumScaleFactor(0.7)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
|
|
/// 270° arc from bottom-left (135°) clockwise, between fractions [from]..[to].
|
|
private struct Arc: Shape {
|
|
let from: CGFloat, to: CGFloat
|
|
func path(in r: CGRect) -> Path {
|
|
var p = Path()
|
|
let c = CGPoint(x: r.midX, y: r.midY), rad = Swift.min(r.width, r.height) / 2 - 2
|
|
p.addArc(center: c, radius: rad, startAngle: .degrees(135 + 270 * from),
|
|
endAngle: .degrees(135 + 270 * to), clockwise: false)
|
|
return p
|
|
}
|
|
}
|
|
|
|
private struct Pointer: Shape {
|
|
let frac: CGFloat
|
|
func path(in r: CGRect) -> Path {
|
|
let c = CGPoint(x: r.midX, y: r.midY), rad = Swift.min(r.width, r.height) / 2 * 0.8
|
|
let a = (135 + 270 * frac) * .pi / 180
|
|
var p = Path()
|
|
p.move(to: c)
|
|
p.addLine(to: CGPoint(x: c.x + rad * cos(a), y: c.y + rad * sin(a)))
|
|
return p
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A short choice list as a row of buttons.
|
|
struct SegmentedView: View {
|
|
let label: String
|
|
let choices: [String]
|
|
let selected: Int
|
|
let tone: Color
|
|
let onSelect: (Int) -> Void
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
Text(label.uppercased()).font(Theme.mono(9)).foregroundColor(Theme.dim)
|
|
HStack(spacing: 0) {
|
|
ForEach(choices.indices, id: \.self) { i in
|
|
let on = i == selected
|
|
Text(choices[i]).font(Theme.mono(11)).lineLimit(1).minimumScaleFactor(0.6)
|
|
.foregroundColor(on ? tone : Theme.dim)
|
|
.frame(maxWidth: .infinity, minHeight: 30)
|
|
.background(on ? tone.opacity(0.22) : Color.clear)
|
|
.overlay(Rectangle().stroke(on ? tone : Theme.grid.opacity(0.6), lineWidth: 0.5))
|
|
.contentShape(Rectangle())
|
|
.onTapGesture { onSelect(i) }
|
|
}
|
|
}
|
|
.overlay(Rectangle().stroke(Theme.grid, lineWidth: 1))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A long choice list as a menu.
|
|
struct ChoiceMenu: View {
|
|
let label: String
|
|
let choices: [String]
|
|
let selected: Int
|
|
let tone: Color
|
|
let onSelect: (Int) -> Void
|
|
|
|
var body: some View {
|
|
Menu {
|
|
ForEach(choices.indices, id: \.self) { i in Button(choices[i]) { onSelect(i) } }
|
|
} label: {
|
|
HStack {
|
|
Text(label.uppercased() + ":").foregroundColor(Theme.dim)
|
|
Text(choices.indices.contains(selected) ? choices[selected] : "").foregroundColor(Theme.text)
|
|
Spacer(minLength: 4)
|
|
Text("▾").foregroundColor(tone)
|
|
}
|
|
.font(Theme.mono(11))
|
|
.padding(.horizontal, 8).frame(minHeight: 30)
|
|
.overlay(Rectangle().stroke(Theme.grid, lineWidth: 1))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// An on/off switch (stored as 0 / 1).
|
|
struct ToggleChip: View {
|
|
let label: String
|
|
let on: Bool
|
|
let tone: Color
|
|
let onToggle: () -> Void
|
|
|
|
var body: some View {
|
|
Text(label.uppercased()).font(Theme.mono(10)).lineLimit(1)
|
|
.foregroundColor(on ? tone : Theme.dim)
|
|
.frame(maxWidth: .infinity, minHeight: 30)
|
|
.background(on ? tone.opacity(0.22) : Color.clear)
|
|
.overlay(Rectangle().stroke(on ? tone : Theme.grid, lineWidth: 1))
|
|
.contentShape(Rectangle())
|
|
.onTapGesture(perform: onToggle)
|
|
}
|
|
}
|
|
|
|
/// Vertical bipolar faders (the graphic EQ): drag or tap to set, double-tap to zero.
|
|
struct FaderBank: View {
|
|
let infos: [ParamInfo]
|
|
let captions: [String]
|
|
let scale: Float
|
|
let tone: Color
|
|
@ObservedObject var model: DeviceModel
|
|
|
|
var body: some View {
|
|
HStack(spacing: 3) {
|
|
ForEach(infos.indices, id: \.self) { i in
|
|
let p = infos[i]
|
|
let v = model.value(p.key)
|
|
VStack(spacing: 2) {
|
|
let shown = v * scale
|
|
Text((shown > 0.05 ? "+" : "") + String(format: "%.0f", shown)).font(Theme.mono(9)).foregroundColor(Theme.text)
|
|
GeometryReader { g in
|
|
let span = p.max - p.min
|
|
let zeroY = g.size.height * CGFloat(1 - (0 - p.min) / span)
|
|
let y = g.size.height * CGFloat(1 - (v - p.min) / span)
|
|
ZStack(alignment: .topLeading) {
|
|
Rectangle().fill(Theme.background)
|
|
Rectangle().fill(tone.opacity(0.45))
|
|
.frame(height: abs(zeroY - y)).offset(y: Swift.min(y, zeroY))
|
|
Rectangle().fill(tone).frame(height: 4).offset(y: y - 2)
|
|
}
|
|
.overlay(Rectangle().stroke(Theme.grid, lineWidth: 1))
|
|
.contentShape(Rectangle())
|
|
.gesture(DragGesture(minimumDistance: 0).onChanged { d in
|
|
let f = Float(1 - Swift.min(1, Swift.max(0, d.location.y / g.size.height)))
|
|
model.set(p.key, p.min + f * span)
|
|
})
|
|
.onTapGesture(count: 2) { model.set(p.key, p.def) }
|
|
}
|
|
.frame(height: 140)
|
|
Text(i < captions.count ? captions[i] : "").font(Theme.mono(9)).foregroundColor(Theme.dim)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|