MIDI2Core
Foundation ModuleCore types and utilities for MIDI 2.0: UMP message types, MUID, DeviceIdentity, and value scaling.
UMP Message Types
MIDI 2.0 uses Universal MIDI Packet (UMP) as the transport format. Each packet has a message type that determines its size and interpretation.
UMPMessageType
public enum UMPMessageType: UInt8, Sendable, CaseIterable
| Case | Value | Size | Description |
|---|---|---|---|
utility | 0x0 | 32-bit | NOOP, JR Clock, JR Timestamp |
system | 0x1 | 32-bit | System Real Time / Common |
midi1ChannelVoice | 0x2 | 32-bit | MIDI 1.0 Channel Voice (wrapped) |
data64 | 0x3 | 64-bit | SysEx7 |
midi2ChannelVoice | 0x4 | 64-bit | MIDI 2.0 Channel Voice |
data128 | 0x5 | 128-bit | SysEx8, Mixed Data Set |
flexData | 0xD | 128-bit | Flex Data |
umpStream | 0xF | 128-bit | UMP Stream messages |
let messageType = UMPMessageType.midi2ChannelVoice
print(messageType.wordCount) // 2 (64-bit = 2 words)
MIDI2ChannelVoiceStatus
Status codes for MIDI 2.0 Channel Voice messages (message type 0x4).
public enum MIDI2ChannelVoiceStatus: UInt8, Sendable, CaseIterable
| Case | Value | Description |
|---|---|---|
noteOff | 0x8 | Note Off |
noteOn | 0x9 | Note On |
polyPressure | 0xA | Polyphonic Aftertouch |
controlChange | 0xB | Control Change (32-bit value) |
programChange | 0xC | Program Change (with bank) |
channelPressure | 0xD | Channel Aftertouch (32-bit) |
pitchBend | 0xE | Pitch Bend (32-bit) |
registeredController | 0x2 | RPN (32-bit value) |
assignableController | 0x3 | NRPN (32-bit value) |
UMPGroup / MIDIChannel
Type-safe wrappers for groups (0-15) and channels (0-15).
let group = UMPGroup(rawValue: 0) // Group 1
let channel = MIDIChannel(rawValue: 9) // Channel 10
print(channel.displayValue) // 10 (1-indexed for display)
MUID
MIDI Unique Identifier — a 28-bit value used to identify devices in MIDI-CI communication.
public struct MUID: Sendable, Hashable, CustomStringConvertible
Properties
| Property | Type | Description |
|---|---|---|
value | UInt32 | Raw 28-bit value |
isBroadcast | Bool | True if 0x0FFFFFFF |
Factory Methods
let muid = MUID.random() // Generate random MUID
let broadcast = MUID.broadcast // 0x0FFFFFFF
DeviceIdentity
Device identification for MIDI-CI Discovery.
public struct DeviceIdentity: Sendable, Hashable
Properties
| Property | Type | Description |
|---|---|---|
manufacturerID | ManufacturerID | 1-byte or 3-byte manufacturer ID |
familyID | UInt16 | Device family |
modelID | UInt16 | Device model |
versionID | UInt32 | Software version (4 bytes) |
let identity = DeviceIdentity(
manufacturerID: .extended(0x00, 0x20), // Roland
familyID: 0x0001,
modelID: 0x0015,
versionID: 0x01500000 // v1.50.0.0
)
Value Scaling
Utilities for converting between MIDI 1.0 (7/14-bit) and MIDI 2.0 (32-bit) resolutions.
public enum UMPValueScaling
Methods
| Method | Description |
|---|---|
scale7To32(_:) | 7-bit (0-127) → 32-bit |
scale32To7(_:) | 32-bit → 7-bit (0-127) |
scale14To32(_:) | 14-bit (0-16383) → 32-bit |
scale32To14(_:) | 32-bit → 14-bit (0-16383) |
normalizedTo32(_:) | 0.0-1.0 → 32-bit |
to32Normalized(_:) | 32-bit → 0.0-1.0 |
// Convert MIDI 1.0 velocity to MIDI 2.0
let velocity7: UInt8 = 100
let velocity32 = UMPValueScaling.scale7To32(velocity7)
// Convert normalized value to 32-bit
let normalized = 0.75
let value32 = UMPValueScaling.normalizedTo32(normalized)
Mcoded7
Encoding/decoding for transmitting 8-bit data over 7-bit MIDI.
public enum Mcoded7
Property Exchange data is encoded using Mcoded7 to ensure all bytes are 7-bit safe for MIDI transmission.
// Encode 8-bit data for transmission
let originalData = Data([0x00, 0xFF, 0x80, 0x7F])
let encoded = Mcoded7.encode(originalData)
// Decode received data
if let decoded = Mcoded7.decode(encoded) {
// decoded == originalData
}