basic exemple somewhere ? #9
-
Hi, i'm very intersting with your library but since i'm new to Swift i'm unable to find a working exemple for now. From the doc : do { what should be the "destination" variable. Thank you very much for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Benoit, You can find a working example in the Playground that is in the root folder of this repository. I have just update that playground. Here is the code of the Playground: import Foundation
import MIDIKit
import PlaygroundSupport
// Keep playground running
PlaygroundPage.current.needsIndefiniteExecution = true
let client = MIDIClient(name: "MidiTestClient")
try client.start()
// log all currently connected devices
print("Devices:")
MIDIDevice.getAll().forEach {
print(" \($0.name as Any)")
print(" Entities:")
$0.getEntities().forEach {
print(" \($0.name as Any)")
print(" Sources:")
$0.getSources().forEach {
print(" \($0.name as Any)")
}
print(" Destinations:")
$0.getDestinations().forEach {
print(" \($0.name as Any)")
}
}
}
// receiving all messages
let inputPorts = try MIDIEndpoint.getAllSources().map { source -> MIDIInputPort in
let inputPort = try client.makeInputPort(name: "MIDItest_inputPort") { (result) in
do {
let packet = try result.get()
print("MIDI Received From Source: \(packet.source.displayName ?? "-") \(packet.source.entity?.device?.identifier.debugDescription ?? "-")")
for message in packet.messages {
print(message)
}
} catch {
print(error)
}
}
try inputPort.connect(to: source)
return inputPort
}
let outputPort = try client.makeOutputPort(name: "MIDITest_outputPort")
/// sends message to all devices
/// - Parameter messages: MIDI messages to send
func send(_ messages: [MIDIMessage]) throws {
let allDesitnations = MIDIEndpoint.getAllDestinations()
if allDesitnations.isEmpty {
print("no destinations available")
}
try allDesitnations.forEach { (destination) in
try outputPort.send(messages, to: destination)
}
}
/// send messages to all devices
try send([.controlChange(channel: 0, controller: 0, value: 0)]) To come back to your initial question: You can find more Information about all available types and their methods/properites by looking at the documentation at https://dnadoba.github.io/MIDIKit/index.html. Hope that helps :) |
Beta Was this translation helpful? Give feedback.
Hi Benoit,
You can find a working example in the Playground that is in the root folder of this repository. I have just update that playground.
When you open MIDIKit in Xcode, you can just click on the Playground and you should be able to run it.
It will print all currently connected devices and will start listening for the incoming MIDI messages. Make sure your MIDI Device is connected to your Mac before you execute the Playground.
Here is the code of the Playground: