Layouts exported from Android's DeviceLayouts (DeviceLayouts.json), iOS layouts for the devices with hand-built Android editors, SwiftUI editor shared by the extension and the app, Mac snapshot tool for the editors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
209 lines
8.3 KiB
Swift
209 lines
8.3 KiB
Swift
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import SwiftUI
|
|
|
|
/// Sizzle's dark retro palette (Android's default theme) and the card tones.
|
|
enum Theme {
|
|
static let background = Color(red: 0.07, green: 0.08, blue: 0.09)
|
|
static let surface = Color(red: 0.11, green: 0.12, blue: 0.14)
|
|
static let grid = Color(white: 0.24)
|
|
static let text = Color(white: 0.92)
|
|
static let dim = Color(white: 0.58)
|
|
static let accent = Color(red: 0.96, green: 0.76, blue: 0.29)
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|