iOS 0.3.0: card editors like Android's for every plugin (knobs, switches, tabs, drawings)
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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
47588990ce
commit
b6589ee792
@@ -0,0 +1,148 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
#if canImport(UIKit)
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
/// A device's editor, like the Android app's: tabs of titled cards, each tinted by
|
||||
/// its role, with knobs for numbers, switches for short choices, menus for long
|
||||
/// ones, faders for the EQ and live drawings. Used by the plugin extension and by
|
||||
/// the app for the devices it hosts.
|
||||
struct DeviceEditor: View {
|
||||
@StateObject var model: DeviceModel
|
||||
@State var page = 0
|
||||
/// Render without a ScrollView (the Mac snapshot tool; ImageRenderer can't draw one).
|
||||
static var snapshot = false
|
||||
|
||||
var body: some View {
|
||||
let pages = Layouts.pages(for: model.au.toolboxType, allKeys: model.order)
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text(model.au.displayName.uppercased()).font(Theme.mono(15)).foregroundColor(Theme.accent)
|
||||
Spacer()
|
||||
if let presets = model.au.factoryPresets, !presets.isEmpty {
|
||||
Menu {
|
||||
ForEach(presets, id: \.number) { p in Button(p.name) { model.applyPreset(p) } }
|
||||
} label: {
|
||||
Text("PRESET: \(model.presetName ?? "—") ▾").font(Theme.mono(12)).foregroundColor(Theme.accent)
|
||||
}
|
||||
}
|
||||
}
|
||||
if pages.count > 1 {
|
||||
HStack(spacing: 4) {
|
||||
ForEach(pages.indices, id: \.self) { i in
|
||||
let on = i == page
|
||||
let tone = Theme.tone(pages[i].panels.first?.tone ?? .SOURCE)
|
||||
Text(pages[i].title.uppercased()).font(Theme.mono(pages.count > 5 ? 10 : 12))
|
||||
.lineLimit(1).minimumScaleFactor(0.7)
|
||||
.foregroundColor(on ? tone : Theme.dim)
|
||||
.frame(maxWidth: .infinity, minHeight: 30)
|
||||
.background(on ? tone.opacity(0.22) : Theme.surface)
|
||||
.overlay(Rectangle().stroke(on ? tone : Theme.grid, lineWidth: 1))
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { page = i }
|
||||
}
|
||||
}
|
||||
}
|
||||
let cards = VStack(spacing: 8) {
|
||||
ForEach(pages[Swift.min(page, pages.count - 1)].panels) { panel in
|
||||
CardView(panel: panel, model: model)
|
||||
}
|
||||
}
|
||||
if DeviceEditor.snapshot { cards; Spacer(minLength: 0) } else { ScrollView { cards } }
|
||||
}
|
||||
.padding(10)
|
||||
.background(Theme.background)
|
||||
}
|
||||
}
|
||||
|
||||
/// One card: header, optional drawing, then choices, switches and knobs (or faders).
|
||||
struct CardView: View {
|
||||
let panel: LayoutPanel
|
||||
@ObservedObject var model: DeviceModel
|
||||
|
||||
var body: some View {
|
||||
let tone = Theme.tone(panel.tone)
|
||||
let infos = panel.keys.compactMap { model.params[$0] }
|
||||
let enums = infos.filter { $0.isEnum }
|
||||
let segmented = enums.filter { $0.choices.count <= 6 && $0.choices.joined().count <= 34 }
|
||||
let menus = enums.filter { !($0.choices.count <= 6 && $0.choices.joined().count <= 34) }
|
||||
let toggles = infos.filter { $0.isToggle }
|
||||
let knobs = infos.filter { !$0.isEnum && !$0.isToggle }
|
||||
|
||||
VStack(alignment: .leading, spacing: 7) {
|
||||
HStack(spacing: 6) {
|
||||
Rectangle().fill(tone).frame(width: 8, height: 8)
|
||||
Text(panel.title.uppercased()).font(Theme.mono(11)).foregroundColor(tone)
|
||||
}
|
||||
if let viz = panel.viz, viz.kind != "wavetable" {
|
||||
VizView(viz: viz, tone: tone, model: model)
|
||||
}
|
||||
if let captions = panel.faders {
|
||||
FaderBank(infos: infos, captions: captions, scale: panel.faderScale ?? 1, tone: tone, model: model)
|
||||
} else {
|
||||
ForEach(Array(stride(from: 0, to: menus.count, by: 2)), id: \.self) { i in
|
||||
HStack(spacing: 8) {
|
||||
ForEach(menus[i..<Swift.min(i + 2, menus.count)], id: \.key) { p in
|
||||
ChoiceMenu(label: Format.shortLabel(p, labels: panel.labels), choices: p.choices,
|
||||
selected: Int(model.value(p.key).rounded()), tone: tone) { model.set(p.key, Float($0)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
ForEach(segmented, id: \.key) { p in
|
||||
SegmentedView(label: Format.shortLabel(p, labels: panel.labels), choices: p.choices,
|
||||
selected: Int(model.value(p.key).rounded()), tone: tone) { model.set(p.key, Float($0)) }
|
||||
}
|
||||
if !toggles.isEmpty {
|
||||
HStack(spacing: 6) {
|
||||
ForEach(toggles, id: \.key) { p in
|
||||
ToggleChip(label: Format.shortLabel(p, labels: panel.labels), on: model.value(p.key) >= 0.5,
|
||||
tone: tone) { model.set(p.key, model.value(p.key) >= 0.5 ? 0 : 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
knobRows(knobs, tone: tone)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 8).padding(.vertical, 7)
|
||||
.background(Theme.surface)
|
||||
.overlay(Rectangle().stroke(tone.opacity(0.35), lineWidth: 1))
|
||||
}
|
||||
|
||||
/// Up to six knobs a row, rows evenly filled, centred (Android's PanelCard).
|
||||
@ViewBuilder private func knobRows(_ knobs: [ParamInfo], tone: Color) -> some View {
|
||||
let n = knobs.count
|
||||
if n > 0 {
|
||||
let perRow = n <= 6 ? n : Int(ceil(Double(n) / ceil(Double(n) / 6)))
|
||||
let slots = Swift.max(perRow, 4)
|
||||
ForEach(Array(stride(from: 0, to: n, by: perRow)), id: \.self) { start in
|
||||
let row = Array(knobs[start..<Swift.min(start + perRow, n)])
|
||||
HStack(spacing: 4) {
|
||||
let pad = slots - row.count
|
||||
ForEach(0..<(pad / 2), id: \.self) { _ in Color.clear.frame(maxWidth: .infinity, maxHeight: 1) }
|
||||
ForEach(row, id: \.key) { p in
|
||||
KnobView(label: Format.shortLabel(p, labels: panel.labels),
|
||||
valueText: Format.value(p, model.value(p.key)),
|
||||
value: model.value(p.key), min: p.min, max: p.max, def: p.def, tone: tone) { model.set(p.key, $0) }
|
||||
}
|
||||
ForEach(0..<(pad - pad / 2), id: \.self) { _ in Color.clear.frame(maxWidth: .infinity, maxHeight: 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(UIKit)
|
||||
/// For the Objective-C view controller: the editor for [au] in a hosting controller.
|
||||
@objc(SizzleEditorFactory)
|
||||
@MainActor
|
||||
public final class SizzleEditorFactory: NSObject {
|
||||
@objc public static func makeEditor(for au: SizzleDeviceAU) -> UIViewController {
|
||||
let vc = UIHostingController(rootView: DeviceEditor(model: DeviceModel(au: au)))
|
||||
vc.view.backgroundColor = UIColor(red: 0.07, green: 0.08, blue: 0.09, alpha: 1)
|
||||
return vc
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user