GitXplorerGitXplorer
d

MIDIKit

public
14 stars
4 forks
3 issues

Commits

List of commits on branch master.
Unverified
79f786e60164545efe0081aaf9615a9c870b6ad9

make device identifier non-optional because we already check in the initializer for non zero id's

ddnadoba committed 3 years ago
Unverified
8843f20c6ed45ff17d953ee4775b393bfbb1bc94

add offline property to MIDIDevice

ddnadoba committed 3 years ago
Unverified
c024e588849f8c87cb7a896875814683086fe4ca

improve playground output

ddnadoba committed 4 years ago
Verified
9a4462a712c0f139bb03e22cfa8c96bcb4241b12

Update README.md

ddnadoba committed 4 years ago
Unverified
455fe9769823c576c8881d32b0628f0f61378995

update playground

ddnadoba committed 4 years ago
Unverified
1c191b88c491670a093b87349856550ccd0ad27b

use Unmanaged instead of pointers

ddnadoba committed 4 years ago

README

The README file for this repository.

MIDIKit Documentation

MIDIKit is a Swift Package for decoding and encoding MIDI Packages and a Swifty Wrapper for CoreMIDI on iOS and macOS.

Playground

There is a playground in the root folder of this repository. You should be able to run it by first opening this Swift Package in Xcode by double-clicking the Package.swift and then opening the Playground in the Project Navigator.

The Playground lists all connected devices, logs all MIDI messages received. You can also send MIDI messages back to all connected devices by using the send(_:) function at the end of the Playground. Make sure you connect your MIDI device to your Mac before you start the Playground.

Connection basics

Create and start the MIDI Client

let midiClient = MIDIClient(name: "My Client")

do {
    try midiClient.start()
} catch {
    // catch error
}

Send messages

do {
    let outputPort = try midiClient.makeOutputPort(name: "Output") 
    outputPort.send(MIDIMessage.controlChange(channel: 1, controller: 11, value: 64), to: destination)
} catch {
    // catch error
}

Receive messages

let midiInputPort = try midiClient.makeInputPort(name: "Input", callback: { (result) in
    
    do {
        let packet = try result.get()
        let message = packet.message
        
        // Handle message
    } catch {
        // catch error
    }
})

MIDI Messages

MIDIKit supports the creation of all common MIDI Messages via dedicated enums. Here some examples:

    // Control change
    let messsage = MIDIMessage.controlChange(channel: 1, controller: 11, value: 64), to: destination)
    
    // Note on
    let message = MIDIMessage.noteOnEvent(channel: 1, key: 20, velocity: 100)
    
    // Sysex
    let data: [UInt8] = [0xF0, 0x01, 0x02, 0xF7]
    let message = MIDIMessage.systemExclusivMessage(data)

MIDI Network support

To connect your client to a MIDI network session, create a specialized MIDINetworkClient

let connection = MIDINetworkConnection(host: MIDINetworkHost(name: "Session 1", address: "192.168.0.100", port: 5006))
let midiClient = try MIDINetworkClient(name: "My Client", connection: connection)

do {
    try midiClient.start()
} catch {
    // catch error
}

When connected to a MIDI Network, you can use the dedicated source and destination endpoints for sending and receiving MIDI messages:

...

let source = midiClient.sourceEndpoint
let destination = midiClient.destinationEndpoint

// Send a MIDI message
do {
    let outputPort = try midiClient.makeOutputPort(name: "Output") 
    outputPort.send(MIDIMessage.controlChange(channel: 1, controller: 11, value: 64), to: destination)
} catch {
    // catch error
}

// Receive MIDI messages
let midiInputPort = try midiClient.makeInputPort(name: "Input", callback: { (result) in
    
    do {
        let packet = try result.get()
        let message = packet.message
        
        // Handle message
    } catch {
        // catch error
    }
})

midiInputPort.connect(to: source)