// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import SwiftUI /// The Tape Delay's hand-built editor (Android's DelayEditor): four tape heads side /// by side, each an on/off toggle above a vertical division fader that snaps hard to /// the DelayDivisions steps (1/1 at the top … 1/16T at the bottom; a longer division /// fills taller), then the Loop card (Feedback / Mix / Tape). Feedback's maximum is /// the DSP's ceiling (0.9), so the loop can't run away. @MainActor enum DelayBespoke { static func body(_ model: DeviceModel) -> AnyView? { AnyView(DelayEditorView(model: model)) } static let heads = 4 /// Android's DelayDivisions labels, longest first (used when DeviceLayouts.json is missing). static let fallbackDivisions = ["1/1", "1/2.", "1/2", "1/4.", "1/2T", "1/4", "1/8.", "1/4T", "1/8", "1/16.", "1/8T", "1/16", "1/16T"] static var divisions: [String] { Layouts.file?.delayDivisions ?? fallbackDivisions } /// Android's default theme's playhead green (the selected-step band). static var band: Color { Theme.playhead } } private struct DelayEditorView: View { @ObservedObject var model: DeviceModel var body: some View { VStack(alignment: .leading, spacing: 10) { Text("Tape heads — drag a fader to set its time; tap the number to switch it off/on:") .font(Theme.mono(11)).foregroundColor(Theme.dim) .fixedSize(horizontal: false, vertical: true) HStack(alignment: .top, spacing: 8) { ForEach(0..= 0.5 let idx = Swift.min(steps - 1, Swift.max(0, Int(model.value(divKey)))) let border = on ? Theme.accent : Theme.grid VStack(spacing: 4) { Text("\(head + 1)").font(Theme.mono(13)) .foregroundColor(on ? Theme.accent : Theme.dim) .frame(maxWidth: .infinity, minHeight: 26, maxHeight: 26) .background(on ? Theme.accent.opacity(0.22) : Theme.surface) .overlay(Rectangle().stroke(border, lineWidth: 1)) .contentShape(Rectangle()) .onTapGesture { model.set(onKey, on ? 0 : 1) } GeometryReader { g in Canvas { ctx, size in let stepH = size.height / CGFloat(steps) let top = CGFloat(idx) * stepH // Fill from the bottom up to the selected step: longer = taller. ctx.fill(Path(CGRect(x: 0, y: top, width: size.width, height: size.height - top)), with: .color((on ? Theme.accent : Theme.grid).opacity(0.45))) var lines = Path() for s in 1..