Files
sizzletracker-android/ios/app/FX/Editor/Bespoke/Bespoke.swift
T
ReactorcoremeltdownandClaude Opus 5.5 3b035d6a7d iOS milestone 4 groundwork: bespoke editor registry and data sources
Device editors ask BespokeEditors for headers, whole bodies, drawings and card
actions; DeviceDataSource gives them DSP data and hidden settings, backed by app
slots (SlotDataSource) or AUs (AUDataSource, hidden values in SizzleDeviceAU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:47:25 +01:00

79 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// What a device editor needs beyond its parameters: drawings of data the DSP
/// owns (wavetable frames, sample waveforms, an effect's live scope), loading
/// files into the device, and settings that aren't AU parameters (the Mix
/// Tightener's hidden stage trims). Two backends: SlotDataSource (a toolbox slot
/// of the app's song, Host/) and AUDataSource (an AUv3, the plugin extension and
/// the device lab). Every requirement has a default here; each device's file
/// implements what it needs in extensions of those classes.
@MainActor
protocol DeviceDataSource: AnyObject {
/// Oscillator [osc]'s current table, level 0 (frames × size samples), or nil.
func wavetableFrames(osc: Int) -> (frames: Int, size: Int, data: [Float])?
/// Peak envelope (0..1, [buckets] values) of the sample the setting [key] names.
func samplePeaks(key: String, buckets: Int) -> [Float]?
/// Load a user file into the device ([kind]: "wavetable", "grainSource", …).
/// Returns an error message, or nil on success.
func loadFile(_ url: URL, kind: String) -> String?
/// The effect's live scope (oldest → newest samples) and read-head position
/// (0..1), or nil while it has none (not on a channel, no signal).
func effectScope(capacity: Int) -> (samples: [Float], playhead: Float)?
/// A setting that isn't a parameter (text, as stored), or nil.
func hiddenValue(_ key: String) -> String?
func setHiddenValue(_ value: String, key: String)
}
extension DeviceDataSource {
func wavetableFrames(osc: Int) -> (frames: Int, size: Int, data: [Float])? { nil }
func samplePeaks(key: String, buckets: Int) -> [Float]? { nil }
func loadFile(_ url: URL, kind: String) -> String? { "Not available here yet." }
func effectScope(capacity: Int) -> (samples: [Float], playhead: Float)? { nil }
func hiddenValue(_ key: String) -> String? { nil }
func setHiddenValue(_ value: String, key: String) {}
}
/// Hand-built pieces of device editors (the Android app's bespoke editors), by
/// device. DeviceEditor asks here first and falls back to the card layout. Each
/// device's views live in their own file in this folder.
@MainActor
enum BespokeEditors {
/// Shown above the tabs (e.g. the Grain Cloud's source strip).
static func header(_ model: DeviceModel) -> AnyView? {
switch model.toolboxType {
case "GRAIN_CLOUD": return GrainCloudBespoke.header(model)
default: return nil
}
}
/// Replaces the card pages entirely (devices whose Android editor is hand-built).
static func body(_ model: DeviceModel) -> AnyView? {
switch model.toolboxType {
case "DELAY": return DelayBespoke.body(model)
case "TAPE_ENGINE": return TapeEngineBespoke.body(model)
case "MIX_TIGHTENER": return MixTightenerBespoke.body(model)
case "GRANULAR": return GranularBespoke.body(model)
default: return nil
}
}
/// A card drawing the generic VizView doesn't know (kind "wavetable").
static func viz(_ viz: LayoutPanel.Viz, tone: Color, model: DeviceModel) -> AnyView? {
switch viz.kind {
case "wavetable": return WavetableBespoke.preview(osc: viz.osc ?? 1, tone: tone, model: model)
default: return nil
}
}
/// A card's title-row action (LayoutPanel.action, e.g. "loadTable").
static func action(_ action: String, tone: Color, model: DeviceModel) -> AnyView? {
switch action {
case "loadTable": return WavetableBespoke.loadTableAction(tone: tone, model: model)
default: return nil
}
}
}