Mixing spatial music
At a glance
| Item | Summary |
|---|---|
| Purpose | Preview ray-traced reverb by adjusting a spatialized multitrack audio mix in an immersive scene. |
| App architecture | A Swift sample with the source-visible chain MixingSpatialMusicApp → SettingsView → AppModel → ReverbMeshLoader → RealityKit APIs. |
| Main patterns | Binding-based state propagation |
| Project style | 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, async declaration or closure, Task closure isolated to MainActor, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | RealityKit, SwiftUI, OSLog, UIKit, os; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── MixingSpatialMusic/
├── MixingSpatialMusicApp.swift
├── AppModel.swift
├── ECS/
│ ├── ReverbMeshLoader.swift
│ └── ViewpointComponent.swift
├── Views/
│ ├── AudioMixer/
│ │ ├── MixerView.swift
│ │ ├── TrackView.swift
│ │ ├── LabeledFader.swift
│ │ └── MuteSolo.swift
│ ├── ImmersiveView.swift
│ └── SettingsView.swift
├── Logger.swift
└── Model/
└── AudioStem.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 21 source declaration(s).
Overall architecture
flowchart LR
N1["MixingSpatialMusicApp"]
N2["SettingsView"]
N3["AppModel"]
N4["ReverbMeshLoader"]
N5["RealityKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
MixingSpatialMusic/MixingSpatialMusicApp.swift:10 — architecture anchor
@main
struct MixingSpatialMusicApp: App {
// ...
@State private var appModel = AppModel()
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into RealityKit.
Ownership and state
classDiagram
MixingSpatialMusicApp *-- AppModel : appModel
AppModel *-- Entity : root
AppModel *-- Entity : audioSourcesRoot
AppModel o-- PlaybackState : playbackState
Ownership evidence
MixingSpatialMusic/MixingSpatialMusicApp.swift:13 — stored dependency or nearest verified ownership anchor
@main
struct MixingSpatialMusicApp: App {
// ...
@State private var appModel = AppModel()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
MixingSpatialMusicApp |
AppModel (appModel) |
owns wrapper-managed state | Owning lexical scope |
AppModel |
Entity (root) |
creates and retains | Initialized by the owner; the binding is immutable |
AppModel |
Entity (audioSourcesRoot) |
creates and retains | Initialized by the owner; the binding is immutable |
AppModel |
PlaybackState (playbackState) |
stores or receives | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | MixingSpatialMusic/AppModel.swift:12 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | MixingSpatialMusic/AppModel.swift:62 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | MixingSpatialMusic/Views/ToggleImmersiveSpaceButton.swift:19 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | MixingSpatialMusic/Views/ToggleImmersiveSpaceButton.swift:19 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
MixingSpatialMusic/AppModel.swift:12 — representative execution boundary
@MainActor
@Observable
class AppModel {
// ...
var immersiveSpaceState = ImmersiveSpaceState.closed
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | @Observable |
Observation macro publishes source-visible changes. | MixingSpatialMusic/AppModel.swift:13 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | MixingSpatialMusic/MixingSpatialMusicApp.swift:13 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MixingSpatialMusic/AppModel.swift:10 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | MixingSpatialMusic/AppModel.swift:9 |
| Source import | OSLog |
The cited file imports this module; runtime use and architectural role are not inferred. | MixingSpatialMusic/AppModel.swift:8 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MixingSpatialMusic/ECS/Entity+Viewpoint.swift:9 |
| Source import | os |
The cited file imports this module; runtime use and architectural role are not inferred. | MixingSpatialMusic/Views/AudioMixer/MixerView.swift:8 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
MixingSpatialMusic/MixingSpatialMusicApp.swift:11 — representative type boundary
@main
struct MixingSpatialMusicApp: App {
// ...
@State private var appModel = AppModel()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
MixingSpatialMusicApp |
Application entry and top-level composition | App |
AppModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
ReverbMeshLoader |
Loads and prepares feature data or resources | Concrete collaborators/imported frameworks |
ViewpointComponent |
Stores entity-component data or behavior | Component |
MixerView |
User-interface presentation and input forwarding | View |
TrackView |
User-interface presentation and input forwarding | View |
ImmersiveView |
User-interface presentation and input forwarding | View |
SettingsView |
User-interface presentation and input forwarding | View |
VisualModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
ImmersiveSpaceState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
addViewpoints (MixingSpatialMusic/AppModel.swift:102) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
configureAudioMixGroups (MixingSpatialMusic/AppModel.swift:109) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
makeAudioSource (MixingSpatialMusic/AppModel.swift:121) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
updatePlaybackState (MixingSpatialMusic/AppModel.swift:129) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
MixingSpatialMusic/AppModel.swift:102 — representative boundary
private func addViewpoints() {
for viewpoint in Viewpoint.all {
root.addChild(.makeViewpoint(viewpoint))
}
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | MixingSpatialMusicApp |
The source’s App suffix makes this role explicit. |
| Stores entity-component data or behavior | ViewpointComponent |
The source’s Component suffix makes this role explicit. |
| Loads and prepares feature data or resources | ReverbMeshLoader |
The source’s Loader suffix makes this role explicit. |
| Feature data or observable state | AppModel, VisualModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ImmersiveView, MixerView, SettingsView, TrackView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Binding-based state propagation | MixingSpatialMusic/Views/AudioMixer/LabeledFader.swift:15 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: MixingSpatialMusicApp; Component: ViewpointComponent; Loader: ReverbMeshLoader; Model: AppModel, VisualModel; View: ImmersiveView, MixerView, SettingsView, TrackView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
teleportToStartingViewpoint,teleport,loadVisualEnvironment,loadAudioEnvironment,loadAudio,addViewpoints,configureAudioMixGroups,makeAudioSource. - Files:
MixingSpatialMusic/MixingSpatialMusicApp.swift,MixingSpatialMusic/AppModel.swift,MixingSpatialMusic/ECS/ReverbMeshLoader.swift,MixingSpatialMusic/ECS/ViewpointComponent.swift,MixingSpatialMusic/Views/AudioMixer/MixerView.swift,MixingSpatialMusic/Views/AudioMixer/TrackView.swift.
Architecture takeaways
MixingSpatialMusicAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches RealityKit, SwiftUI, UIKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
MixingSpatialMusic/MixingSpatialMusicApp.swift |
Cited implementation, MixingSpatialMusicApp, SwiftUI state property wrapper |
MixingSpatialMusic/AppModel.swift |
Cited implementation, @MainActor, async declaration or closure, @Observable, RealityKit, SwiftUI, OSLog, AppModel, ImmersiveSpaceState |
MixingSpatialMusic/Views/AudioMixer/LabeledFader.swift |
Cited implementation, LabeledFader, TickMarksShape, TickLabels |
MixingSpatialMusic/Views/ToggleImmersiveSpaceButton.swift |
Task closure isolated to MainActor, Task, ToggleImmersiveSpaceButton |
MixingSpatialMusic/ECS/Entity+Viewpoint.swift |
UIKit, Feature implementation |
MixingSpatialMusic/Views/AudioMixer/MixerView.swift |
os, MixerView |
MixingSpatialMusic/ECS/ReverbMeshLoader.swift |
ReverbMeshLoader |
MixingSpatialMusic/ECS/ViewpointComponent.swift |
ViewpointComponent |
MixingSpatialMusic/Views/AudioMixer/TrackView.swift |
TrackView |
MixingSpatialMusic/Views/ImmersiveView.swift |
ImmersiveView |
MixingSpatialMusic/Views/SettingsView.swift |
SettingsView |
MixingSpatialMusic/Logger.swift |
Feature implementation |
MixingSpatialMusic/Model/AudioStem.swift |
AudioStem, VisualModel |
MixingSpatialMusic/Views/AudioMixer/MuteSolo.swift |
MuteToggleStyle, SoloToggleStyle |
MixingSpatialMusic/Model/MixGroupColors.swift |
MixGroupColors |
MixingSpatialMusic/Model/MuteSoloState.swift |
MuteSoloState |