MIDI2Core

Foundation Module

Core 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
utility0x032-bitNOOP, JR Clock, JR Timestamp
system0x132-bitSystem Real Time / Common
midi1ChannelVoice0x232-bitMIDI 1.0 Channel Voice (wrapped)
data640x364-bitSysEx7
midi2ChannelVoice0x464-bitMIDI 2.0 Channel Voice
data1280x5128-bitSysEx8, Mixed Data Set
flexData0xD128-bitFlex Data
umpStream0xF128-bitUMP 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
CaseValueDescription
noteOff0x8Note Off
noteOn0x9Note On
polyPressure0xAPolyphonic Aftertouch
controlChange0xBControl Change (32-bit value)
programChange0xCProgram Change (with bank)
channelPressure0xDChannel Aftertouch (32-bit)
pitchBend0xEPitch Bend (32-bit)
registeredController0x2RPN (32-bit value)
assignableController0x3NRPN (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

PropertyTypeDescription
valueUInt32Raw 28-bit value
isBroadcastBoolTrue 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

PropertyTypeDescription
manufacturerIDManufacturerID1-byte or 3-byte manufacturer ID
familyIDUInt16Device family
modelIDUInt16Device model
versionIDUInt32Software 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

MethodDescription
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
}