- 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>
109 lines
4.8 KiB
Swift
109 lines
4.8 KiB
Swift
// 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) {}
|
||
}
|
||
|
||
/// A host's file picker for bespoke views (the app's slot editor provides one: on
|
||
/// iOS 15 a .fileImporter nested inside another one may not present). A view
|
||
/// calls it with what to do with the picked URL; without one (the plugins) it
|
||
/// uses its own .fileImporter.
|
||
private struct DeviceFilePickerKey: EnvironmentKey {
|
||
static let defaultValue: ((@escaping (URL) -> Void) -> Void)? = nil
|
||
}
|
||
extension EnvironmentValues {
|
||
var deviceFilePicker: ((@escaping (URL) -> Void) -> Void)? {
|
||
get { self[DeviceFilePickerKey.self] }
|
||
set { self[DeviceFilePickerKey.self] = newValue }
|
||
}
|
||
}
|
||
|
||
/// The app's microphone recorder for editors that take a recording (the Grain
|
||
/// Cloud's RECORD); nil in the plugin, which shows no RECORD button.
|
||
struct DeviceRecordControl {
|
||
let isRecording: Bool
|
||
let toggle: () -> Void
|
||
}
|
||
private struct DeviceRecorderKey: EnvironmentKey {
|
||
static let defaultValue: DeviceRecordControl? = nil
|
||
}
|
||
extension EnvironmentValues {
|
||
var deviceRecorder: DeviceRecordControl? {
|
||
get { self[DeviceRecorderKey.self] }
|
||
set { self[DeviceRecorderKey.self] = newValue }
|
||
}
|
||
}
|
||
|
||
/// 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
|
||
}
|
||
}
|
||
}
|