Creating a MIDI device driver
At a glance
| Item | Summary |
|---|---|
| Purpose | Implement a configurable virtual MIDI driver as a driver extension that runs in user space in macOS and iPadOS. |
| App architecture | A C++, C/Objective-C header, Objective-C++, Swift sample with the source-visible chain CreatingMIDIDriverSampleApp → CreatingMIDIDriverSampleAppView → CreatingMIDIDriverSampleAppViewModel → CreatingMIDIDriverSampleAppUserClient → DriverKit / MIDIDriverKit APIs. |
| Main patterns | Model-View-ViewModel, Delegate or data-source callbacks, Publisher-backed observable state |
| Project style | 10 scanned source file(s) across C++, C/Objective-C header, Objective-C++, Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── CreatingMIDIDriverSampleApp/
│ ├── CreatingMIDIDriverSampleApp.swift
│ ├── CreatingMIDIDriverSampleAppViewModel.swift
│ ├── CreatingMIDIDriverSampleAppUserClient.mm
│ ├── CreatingMIDIDriverSampleAppView.swift
│ ├── CreatingMIDIDriverSampleAppUserClient.h
│ ├── CreatingMIDIDriverSampleAppDriverKeys.h
│ └── CreatingMIDIDriverSampleApp.entitlements
├── CreatingMIDIDriverSampleAppExtension/
│ ├── CreatingMIDIDriverSampleAppDriverUserClient.cpp
│ ├── CreatingMIDIDriverSampleAppDevice.cpp
│ ├── CreatingMIDIDriverSampleAppDriver.cpp
│ └── CreatingMIDIDriverSampleAppDriverKeys.h
└── Configuration/
└── SampleCode.xcconfig
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C++, C/Objective-C header, Objective-C++, Swift.
- The verified tree contains 7 project/configuration file(s) and 10 source declaration(s).
Overall architecture
flowchart LR
N1["CreatingMIDIDriverSampleApp"]
N2["CreatingMIDIDriverSampleAppView"]
N3["CreatingMIDIDriverSampleAppViewModel"]
N4["CreatingMIDIDriverSampleAppUserClient"]
N5["DriverKit / MIDIDriverKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleApp.swift:10 — architecture anchor
@main
struct CreatingMIDIDriverSampleApp: App {
var body: some Scene {
WindowGroup {
CreatingMIDIDriverSampleAppView()
}
}
}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 MIDIDriverKit.
Ownership and state
classDiagram
CreatingMIDIDriverSampleAppViewModel o-- State : state
CreatingMIDIDriverSampleAppViewModel *-- String : dextIdentifier
CreatingMIDIDriverSampleAppUserClient o-- io_object_t : ioObject
CreatingMIDIDriverSampleAppUserClient o-- io_connect_t : ioConnection
Ownership evidence
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:94 — stored dependency or nearest verified ownership anchor
class CreatingMIDIDriverSampleAppViewModel: NSObject {
// ...
@Published private var state: CreatingMIDIDriverSampleAppStateMachine.State = .unloaded
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
CreatingMIDIDriverSampleAppViewModel |
State (state) |
stores or receives | Owning lexical scope |
CreatingMIDIDriverSampleAppViewModel |
String (dextIdentifier) |
owns value state | Initialized by the owner; the binding is immutable |
CreatingMIDIDriverSampleAppUserClient |
io_object_t (ioObject) |
stores or receives | Owning Objective-C implementation |
CreatingMIDIDriverSampleAppUserClient |
io_connect_t (ioConnection) |
stores or receives | Owning Objective-C implementation |
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.
Class and protocol design
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleApp.swift:11 — representative type boundary
struct CreatingMIDIDriverSampleApp: App {
var body: some Scene {
WindowGroup {
CreatingMIDIDriverSampleAppView()
}
}
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
CreatingMIDIDriverSampleApp |
Application entry and top-level composition | App |
CreatingMIDIDriverSampleAppViewModel |
UI-facing state and feature coordination | NSObject |
CreatingMIDIDriverSampleAppView |
User-interface presentation and input forwarding | View |
CreatingMIDIDriverSampleAppUserClient |
External-system or framework client | NSObject |
CreatingMIDIDriverSampleAppStateMachine |
Owns feature behavior and collaborator lifecycle | Concrete collaborators/imported frameworks |
State |
Represents mutable feature state | Concrete collaborators/imported frameworks |
Event |
Defines a closed set of feature states or choices | Concrete collaborators/imported frameworks |
CreatingMIDIDriverSampleAppDriverUserClient_IVars |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
CreatingMIDIDriverSampleAppDevice_IVars |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
CreatingMIDIDriverSampleAppDriver_IVars |
Represents a feature value or composable behavior | 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 |
|---|---|---|---|
ioObject (CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.mm:13) |
implementation |
Visibility follows header/implementation and language linkage rules. | Inference: keep the declaration in the Objective-C implementation boundary. |
ioConnection (CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.mm:14) |
implementation |
Visibility follows header/implementation and language linkage rules. | Inference: keep the declaration in the Objective-C implementation boundary. |
state (CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:94) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
dextIdentifier (CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:96) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.mm:13 — representative boundary
@interface CreatingMIDIDriverSampleAppUserClient()
@property io_object_t ioObject;
@property io_connect_t ioConnection;
@endSwift 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 | CreatingMIDIDriverSampleApp |
The source’s App suffix makes this role explicit. |
| External-system or framework client | CreatingMIDIDriverSampleAppUserClient |
The source’s Client suffix makes this role explicit. |
| User-interface presentation and input forwarding | CreatingMIDIDriverSampleAppView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | CreatingMIDIDriverSampleAppViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:91 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| Delegate or data-source callbacks | CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:150 |
Callback protocols invert event delivery back into the sample’s owner. |
| Publisher-backed observable state | CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift:94 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: CreatingMIDIDriverSampleApp; Client: CreatingMIDIDriverSampleAppUserClient; View: CreatingMIDIDriverSampleAppView; ViewModel: CreatingMIDIDriverSampleAppViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
onUnloaded,onActivatingOrNeedsApproval,onActivated,onActivationError,process,activateMyDext,activateExtension,deactivateExtension. - Files:
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleApp.swift,CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift,CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.mm,CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppView.swift,CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.h.
Architecture takeaways
CreatingMIDIDriverSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches DriverKit, MIDIDriverKit, SwiftUI, IOKit 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 |
|---|---|
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleApp.swift |
CreatingMIDIDriverSampleApp |
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppViewModel.swift |
CreatingMIDIDriverSampleAppStateMachine, State, Event, CreatingMIDIDriverSampleAppViewModel |
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.mm |
CreatingMIDIDriverSampleAppUserClient, CreatingMIDIDriverSampleAppUserClient |
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppView.swift |
CreatingMIDIDriverSampleAppView, CreatingMIDIDriverSampleAppView_Previews |
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppUserClient.h |
CreatingMIDIDriverSampleAppUserClient |
CreatingMIDIDriverSampleAppExtension/CreatingMIDIDriverSampleAppDriverUserClient.cpp |
CreatingMIDIDriverSampleAppDriverUserClient_IVars |
CreatingMIDIDriverSampleAppExtension/CreatingMIDIDriverSampleAppDevice.cpp |
CreatingMIDIDriverSampleAppDevice_IVars |
CreatingMIDIDriverSampleAppExtension/CreatingMIDIDriverSampleAppDriver.cpp |
CreatingMIDIDriverSampleAppDriver_IVars |
CreatingMIDIDriverSampleApp/CreatingMIDIDriverSampleAppDriverKeys.h |
Feature implementation |
CreatingMIDIDriverSampleAppExtension/CreatingMIDIDriverSampleAppDriverKeys.h |
Feature implementation |