- 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>
160 lines
7.4 KiB
Swift
160 lines
7.4 KiB
Swift
// 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
|
|
/// The device name and preset menu row; off where the host draws its own
|
|
/// (the app's slot editor has a preset bar of its own).
|
|
var showsHeader = true
|
|
|
|
var body: some View {
|
|
let pages = Layouts.pages(for: model.toolboxType, allKeys: model.order)
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
if showsHeader {
|
|
HStack {
|
|
Text(model.displayName.uppercased()).font(Theme.mono(15)).foregroundColor(Theme.accent)
|
|
Spacer()
|
|
if !model.presetNames.isEmpty {
|
|
Menu {
|
|
ForEach(model.presetNames, id: \.self) { name in Button(name) { model.applyPreset(named: name) } }
|
|
} label: {
|
|
Text("PRESET: \(model.presetName ?? "—") ▾").font(Theme.mono(12)).foregroundColor(Theme.accent)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if let h = BespokeEditors.header(model) { h }
|
|
if let b = BespokeEditors.body(model) {
|
|
SnapScroll { b }
|
|
} else {
|
|
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)
|
|
}
|
|
}
|
|
SnapScroll { 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)
|
|
Spacer(minLength: 0)
|
|
if let a = panel.action, let v = BespokeEditors.action(a, tone: tone, model: model) { v }
|
|
}
|
|
if let viz = panel.viz {
|
|
if let v = BespokeEditors.viz(viz, tone: tone, model: model) { v }
|
|
else if 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(Theme.background)
|
|
return vc
|
|
}
|
|
}
|
|
#endif
|