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>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 09:47:25 +01:00
co-authored by Claude Opus 5.5
parent 42f66534bf
commit 3b035d6a7d
21 changed files with 251 additions and 4 deletions
+3 -2
View File
@@ -98,7 +98,7 @@ au-test: build/core/au_test
# Mac snapshots of the SwiftUI device editors (AUAudioUnit and SwiftUI exist on
# macOS too): the AU classes + core as a dylib, the editor Swift on top.
EDITOR_SWIFT := $(wildcard app/FX/Editor/*.swift)
EDITOR_SWIFT := $(shell find app/FX/Editor -name '*.swift')
build/snapshots/libsizzlesnap.dylib: $(AU_SRC) app/tests/SnapshotComponents.mm $(CORE_SRC) $(CORE_HDR)
mkdir -p build/snapshots
$(CXX) $(CXXFLAGS) -Wno-deprecated-declarations -fobjc-arc -Iapp/FX -dynamiclib -install_name @rpath/libsizzlesnap.dylib \
@@ -116,7 +116,8 @@ SNAPDIR ?= build/screens
# Mac snapshots of the app's tabs with the demo song (SizzleSession runs on macOS
# too, without audio). Screens must stay SwiftUI-only (no UIKit) to render here.
SCREEN_SWIFT := $(EDITOR_SWIFT) app/Host/AppModel.swift app/Host/RootView.swift app/Host/SlotDeviceModel.swift \
app/Host/KeyboardView.swift $(shell find app/Host/Screens -name '*.swift')
app/Host/KeyboardView.swift app/Host/SlotDataSource.swift \
$(shell find app/Host/Screens app/Host/Bespoke -name '*.swift')
$(SNAPDIR)/libsizzlescreens.dylib: $(AU_SRC) $(wildcard app/Host/SizzleSession*.mm app/Host/SizzleSession*.h) app/tests/SnapshotComponents.mm $(CORE_SRC) $(CORE_HDR)
mkdir -p $(SNAPDIR)
$(CXX) $(CXXFLAGS) -Wno-deprecated-declarations -fobjc-arc -Iapp/FX -Iapp/Host -dynamiclib -install_name @rpath/libsizzlescreens.dylib \
+12
View File
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation
/// DeviceDataSource for an AUv3 (the plugin extension, the device lab). Each
/// device's Bespoke file adds what it supports in an extension of this class.
@MainActor
final class AUDataSource: DeviceDataSource {
let au: SizzleDeviceAU
init(au: SizzleDeviceAU) { self.au = au }
}
+78
View File
@@ -0,0 +1,78 @@
// 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
}
}
}
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The Delay's hand-built editor parts (stub: card layout until ported).
@MainActor
enum DelayBespoke {
static func body(_ model: DeviceModel) -> AnyView? { nil }
}
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The GrainCloud's hand-built editor parts (stub: card layout until ported).
@MainActor
enum GrainCloudBespoke {
static func header(_ model: DeviceModel) -> AnyView? { nil }
}
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The Granular's hand-built editor parts (stub: card layout until ported).
@MainActor
enum GranularBespoke {
static func body(_ model: DeviceModel) -> AnyView? { nil }
}
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The MixTightener's hand-built editor parts (stub: card layout until ported).
@MainActor
enum MixTightenerBespoke {
static func body(_ model: DeviceModel) -> AnyView? { nil }
}
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The TapeEngine's hand-built editor parts (stub: card layout until ported).
@MainActor
enum TapeEngineBespoke {
static func body(_ model: DeviceModel) -> AnyView? { nil }
}
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// The Wavetable's table drawing and LOAD TABLE (stub until ported).
@MainActor
enum WavetableBespoke {
static func preview(osc: Int, tone: Color, model: DeviceModel) -> AnyView? { nil }
static func loadTableAction(tone: Color, model: DeviceModel) -> AnyView? { nil }
}
+10 -2
View File
@@ -33,6 +33,10 @@ struct DeviceEditor: View {
}
}
}
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
@@ -56,6 +60,7 @@ struct DeviceEditor: View {
}
SnapScroll { cards }
}
}
.padding(10)
.background(Theme.background)
}
@@ -79,9 +84,12 @@ struct CardView: View {
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, viz.kind != "wavetable" {
VizView(viz: viz, tone: tone, model: model)
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)
+3
View File
@@ -30,6 +30,8 @@ final class DeviceModel: ObservableObject {
let presetNames: [String]
@Published private(set) var values: [String: Float] = [:]
@Published var presetName: String?
/// Data the DSP owns and non-parameter settings (see Bespoke/Bespoke.swift).
var data: DeviceDataSource?
private let write: (String, Float) -> Void
private let applyPresetNamed: (String) -> Void
@@ -70,6 +72,7 @@ final class DeviceModel: ObservableObject {
applyPreset: { name in if let p = presets.first(where: { $0.name == name }) { au.currentPreset = p } },
reread: { Dictionary(uniqueKeysWithValues: all.map { ($0.identifier, $0.value) }) })
presetName = au.currentPreset?.name
data = AUDataSource(au: au)
token = au.parameterTree?.token(byAddingParameterObserver: { [weak self] address, value in
DispatchQueue.main.async {
guard let self = self, let p = all.first(where: { $0.address == address }) else { return }
+4
View File
@@ -35,6 +35,10 @@ NS_ASSUME_NONNULL_BEGIN
- (AUValue)defaultValueForParameter:(AUParameter *)param;
/// Whether the parameter takes whole numbers only.
- (BOOL)isIntegerParameter:(AUParameter *)param;
/// A setting that isn't an AU parameter (e.g. the Mix Tightener's stage trims),
/// as stored text, or nil; saved with the AU's state. Main thread.
- (nullable NSString *)hiddenValueForKey:(NSString *)key;
- (void)setHiddenValue:(NSString *)value forKey:(NSString *)key;
/// Its label in Sizzle's spec, e.g. "Osc1 Level", "Wet (dB)" (displayName is the same).
- (NSString *)specLabelForParameter:(AUParameter *)param;
+11
View File
@@ -160,6 +160,17 @@ static NSString *const kStateKey = @"sizzleValues";
return @(_k->spec->params[param.address].label);
}
- (NSString *)hiddenValueForKey:(NSString *)key {
[self pullBase];
return _base.has(key.UTF8String) ? @(_base.s(key.UTF8String)) : nil;
}
- (void)setHiddenValue:(NSString *)value forKey:(NSString *)key {
[self pullBase];
_base.set(key.UTF8String, value.UTF8String);
_k->publish(_base);
}
#pragma mark - presets and state
- (void)buildFactoryPresets {
+2
View File
@@ -5,3 +5,5 @@
#import "SizzleSession+Tracker.h"
#import "SizzleSession+Mix.h"
#import "SizzleSession+Setup.h"
#import "SizzleSession+Sources.h"
#import "SizzleSession+Viz.h"
+12
View File
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
#import "SizzleSession.h"
NS_ASSUME_NONNULL_BEGIN
/// API for the device editors' Sources views beyond SizzleSession.h.
@interface SizzleSession (Sources)
@end
NS_ASSUME_NONNULL_END
+10
View File
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
#import "SizzleSession+Sources.h"
#import "SizzleSession+Internal.h"
using namespace sizzle;
@implementation SizzleSession (Sources)
@end
+12
View File
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
#import "SizzleSession.h"
NS_ASSUME_NONNULL_BEGIN
/// API for the device editors' Viz views beyond SizzleSession.h.
@interface SizzleSession (Viz)
@end
NS_ASSUME_NONNULL_END
+10
View File
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
#import "SizzleSession+Viz.h"
#import "SizzleSession+Internal.h"
using namespace sizzle;
@implementation SizzleSession (Viz)
@end
+20
View File
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation
/// DeviceDataSource for toolbox slot [slot] of the app's song. Each device's
/// support lives in an extension in Host/Bespoke/.
@MainActor
final class SlotDataSource: DeviceDataSource {
let session: SizzleSession
let slot: Int
init(session: SizzleSession, slot: Int) { self.session = session; self.slot = slot }
// Hidden settings are plain slot values here.
func hiddenValue(_ key: String) -> String? {
let v = session.value(ofSlot: slot, key: key)
return v.isEmpty ? nil : v
}
func setHiddenValue(_ value: String, key: String) { session.setValue(value, ofSlot: slot, key: key) }
}
+1
View File
@@ -31,6 +31,7 @@ extension DeviceModel {
},
applyPreset: { name in session.applyFactoryPreset(name, toSlot: slot) },
reread: read)
data = SlotDataSource(session: session, slot: slot)
}
}
+2
View File
@@ -4,3 +4,5 @@
#import "SizzleSession+Tracker.h"
#import "SizzleSession+Mix.h"
#import "SizzleSession+Setup.h"
#import "SizzleSession+Sources.h"
#import "SizzleSession+Viz.h"