Incorporating Audio Effects and Instruments
At a glance
| Item | Summary |
|---|---|
| Purpose | Add custom audio processing and MIDI instruments to your app by hosting Audio Unit (AU) plug-ins. |
| App architecture | A Swift sample bundle with entry-bearing project variants iOS, macOS, each leading to Cocoa / UIKit APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator |
| Project style | 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue.main.async, DispatchQueue(label:), DispatchQueue.global.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: NotificationCenter. |
| Key frameworks/packages | Cocoa, UIKit, AVFoundation, AppKit, CoreAudioKit; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Shared/
│ ├── AudioUnitManager.swift
│ └── Support/
│ ├── SimplePlayEngine.swift
│ └── ViewExtensions.swift
├── macOS/
│ └── AUv3Host/
│ ├── MainViewController.swift
│ ├── AppDelegate.swift
│ ├── ComponentViewController.swift
│ ├── ListViewController.swift
│ ├── PresetsViewController.swift
│ ├── SaveSheetViewController.swift
│ └── AlertExtensions.swift
└── iOS/
└── AUv3Host/
├── AppDelegate.swift
└── MainViewController.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 8 project/configuration file(s) and 22 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["iOS"]
V2["macOS"]
Boundary["Cocoa / UIKit APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Reference code
iOS/AUv3Host/AppDelegate.swift:10 — architecture anchor
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}Interpretation
The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.
Ownership and state
classDiagram
UserPresetsChange o-- UserPresetsChangeType : type
UserPresetsChange *-- Array : userPresets
UserPresetsChange o-- Notification : userPresetsChanged
Preset o-- AUAudioUnitPreset : audioUnitPreset
Ownership evidence
Shared/AudioUnitManager.swift:45 — stored dependency or nearest verified ownership anchor
struct UserPresetsChange {
let type: UserPresetsChangeType
let userPresets: [Preset]
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
UserPresetsChange |
UserPresetsChangeType (type) |
stores or receives | Initialized by the owner; the binding is immutable |
UserPresetsChange |
Array (userPresets) |
owns value state | Initialized by the owner; the binding is immutable |
UserPresetsChange |
Notification (userPresetsChanged) |
stores or receives | Initialized by the owner; the binding is immutable |
Preset |
AUAudioUnitPreset (audioUnitPreset) |
stores or receives | Initialized by the owner; the binding is immutable |
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 |
|---|---|---|---|
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | Shared/AudioUnitManager.swift:141 |
| Queue scheduling | DispatchQueue(label:) |
The source constructs a dispatch queue; its label alone does not prove a thread. | Shared/AudioUnitManager.swift:163 |
| Queue scheduling | DispatchQueue.global.async |
The source addresses a global dispatch queue; no stable thread identity is implied. | Shared/AudioUnitManager.swift:264 |
@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
Shared/AudioUnitManager.swift:141 — representative execution boundary
DispatchQueue.main.async {
var changeType = self.userPresetChangeType
// ...
}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 | NotificationCenter |
NotificationCenter distributes named process-local events. | Shared/AudioUnitManager.swift:151 |
| Source import | Cocoa |
The cited file imports this module; runtime use and architectural role are not inferred. | macOS/AUv3Host/AlertExtensions.swift:7 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared/AudioUnitManager.swift:13 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared/AudioUnitManager.swift:10 |
| Source import | AppKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared/AudioUnitManager.swift:16 |
| Source import | CoreAudioKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared/AudioUnitManager.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared/AudioUnitManager.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
macOS/AUv3Host/MainViewController.swift:10 — representative type boundary
protocol Coordinator: AnyObject {
// ...
func didSelectPreset(_ preset: Preset)
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
AppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate |
Coordinator |
Defines a capability or collaboration contract | AnyObject |
Component |
Stores entity-component data or behavior | Concrete collaborators/imported frameworks |
AudioUnitManager |
Long-lived feature or framework coordination | Concrete collaborators/imported frameworks |
MainViewController |
View lifecycle, callbacks, and feature coordination | NSSplitViewController |
SplitView |
User-interface presentation and input forwarding | NSSplitView |
BarView |
User-interface presentation and input forwarding | NSView |
SimplePlayEngine |
Owns processing or simulation work | Concrete collaborators/imported frameworks |
InstrumentPlayer |
Owns media or timeline playback | Concrete collaborators/imported frameworks |
The source explicitly defines local protocol relationships: MainViewController → Coordinator.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
AudioUnitManager (Shared/AudioUnitManager.swift:61) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
audioUnitPreset (Shared/AudioUnitManager.swift:64) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
number (Shared/AudioUnitManager.swift:65) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
name (Shared/AudioUnitManager.swift:66) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
Reference code
Shared/AudioUnitManager.swift:61 — representative boundary
fileprivate init(preset: AUAudioUnitPreset) {
audioUnitPreset = preset
}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 |
|---|---|---|
| Stores entity-component data or behavior | Component |
The source’s Component suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | ComponentViewController, ListViewController, MainViewController, PresetsViewController |
The source’s Controller suffix makes this role explicit. |
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate |
The source’s Delegate suffix makes this role explicit. |
| Owns processing or simulation work | SimplePlayEngine |
The source’s Engine suffix makes this role explicit. |
| Long-lived feature or framework coordination | AudioUnitManager |
The source’s Manager suffix makes this role explicit. |
| Owns media or timeline playback | InstrumentPlayer |
The source’s Player suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | macOS/AUv3Host/ComponentViewController.swift:10 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | macOS/AUv3Host/MainViewController.swift:22 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | iOS/AUv3Host/AppDelegate.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | macOS/AUv3Host/MainViewController.swift:10 |
A role-named coordinator centralizes cross-object flow. |
Naming conventions
- Types: Component: Component; Controller: ComponentViewController, ListViewController, MainViewController, PresetsViewController, SaveSheetViewController; Coordinator: Coordinator; Delegate: AppDelegate; Engine: SimplePlayEngine; Manager: AudioUnitManager; Player: InstrumentPlayer; View: BarView, SplitView.
- Protocols:
Coordinator. - Methods:
requestGenericViewController,requestViewController,savePreset,deletePreset,toggleViewMode,loadAudioUnits,selectComponent,loadAudioUnitViewController. - Files:
Shared/AudioUnitManager.swift,macOS/AUv3Host/MainViewController.swift,iOS/AUv3Host/AppDelegate.swift,macOS/AUv3Host/AppDelegate.swift,Shared/Support/SimplePlayEngine.swift,iOS/AUv3Host/MainViewController.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches Cocoa, UIKit, AVFoundation, AppKit 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.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
iOS/AUv3Host/AppDelegate.swift |
Cited implementation, AppDelegate |
Shared/AudioUnitManager.swift |
Cited implementation, DispatchQueue.main.async, DispatchQueue(label:), DispatchQueue.global.async, NotificationCenter, UIKit, AVFoundation, AppKit, CoreAudioKit, Foundation, AudioUnitType, InstantiationType, PresetType, UserPresetsChangeType, UserPresetsChange, Preset, Component, AudioUnitManager |
macOS/AUv3Host/MainViewController.swift |
Coordinator, Cited implementation, MainViewController, SplitView, BarView, ToggleToolbarItem |
macOS/AUv3Host/ComponentViewController.swift |
ComponentViewController |
macOS/AUv3Host/AlertExtensions.swift |
Cocoa, func |
macOS/AUv3Host/AppDelegate.swift |
AppDelegate |
Shared/Support/SimplePlayEngine.swift |
SimplePlayEngine, InstrumentPlayer |
iOS/AUv3Host/MainViewController.swift |
MainViewController, func |
macOS/AUv3Host/ListViewController.swift |
ListViewController |
macOS/AUv3Host/PresetsViewController.swift |
PresetsViewController |
macOS/AUv3Host/SaveSheetViewController.swift |
SaveSheetViewController |
Shared/Support/ViewExtensions.swift |
Feature implementation |