iOS 0.5.0: hand-built editors (Tape Delay, Tape Engine, Mix Tightener, Granular scope, Wavetable tables, Grain Cloud source)

Effect visualisation through the C++ effect, engine and AU; custom wavetables and
grain sources load and persist with the song; the app's slot editor hosts the
file picker for bespoke views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 10:01:14 +01:00
co-authored by Claude Opus 5.5
parent 3b035d6a7d
commit 435305e42a
34 changed files with 1514 additions and 38 deletions
+93 -2
View File
@@ -3,8 +3,99 @@
import SwiftUI
/// The Delay's hand-built editor parts (stub: card layout until ported).
/// 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? { nil }
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 let band = Color(red: 0x7C / 255.0, green: 0xFC / 255.0, blue: 0x9A / 255.0)
}
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..<DelayBespoke.heads, id: \.self) { h in
DelayHeadView(model: model, head: h)
}
}
CardView(panel: LayoutPanel(title: "Loop", tone: .OUT, keys: ["feedback", "drywet", "tape"],
labels: ["drywet": "Mix", "tape": "Tape"]),
model: model)
}
}
}
/// One tape head: the head number as an on/off toggle, the hard-snapping division
/// fader, and the division's name.
private struct DelayHeadView: View {
@ObservedObject var model: DeviceModel
let head: Int
var body: some View {
let onKey = "head\(head)On", divKey = "head\(head)Div"
let names = DelayBespoke.divisions
let steps = model.params[divKey].map { Int($0.max) + 1 } ?? names.count
let on = model.value(onKey) >= 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..<steps {
let y = CGFloat(s) * stepH
lines.move(to: CGPoint(x: 0, y: y)); lines.addLine(to: CGPoint(x: size.width, y: y))
}
ctx.stroke(lines, with: .color(Theme.grid.opacity(0.4)), lineWidth: 0.5)
// The selected step's band.
ctx.fill(Path(CGRect(x: 0, y: top, width: size.width, height: stepH)),
with: .color((on ? DelayBespoke.band : Theme.dim).opacity(0.5)))
}
.background(Theme.surface)
.overlay(Rectangle().stroke(border, lineWidth: 1))
.contentShape(Rectangle())
.gesture(DragGesture(minimumDistance: 0).onChanged { d in
// Tap or drag: snap to the step under the finger.
let i = Int(d.location.y / Swift.max(1, g.size.height) * CGFloat(steps))
let snapped = Swift.min(steps - 1, Swift.max(0, i))
if snapped != Int(model.value(divKey)) { model.set(divKey, Float(snapped)) }
})
}
.frame(height: 150)
Text(names[Swift.min(names.count - 1, idx)]).font(Theme.mono(10))
.foregroundColor(on ? Theme.text : Theme.dim)
}
.frame(maxWidth: .infinity)
}
}