Open Sound Control (OSC) library written in Swift.
Note: The library does not contain a networking layer so you can modularly integrate OSCKit into whatever network module you choose. The repo contains an example project demonstrating using it with Apple's Network.framework
.
Unit tests implemented.
To add OSCKit to your Xcode project:
https://github.com/orchetect/OSCKit
as the URL.import OSCKit
// set up your UDP port(s) with a 3rd-party network library of choice;
// no network layer is included in OSCKit
// in your UDP socket receive handler,
// assuming the "data" variable is raw data bytes from a received UDP packet:
do {
guard let oscPayload = try data.parseOSC() else { return }
handleOSCPayload(oscPayload)
} catch let error as OSCBundle.DecodeError {
// handle bundle errors
} catch let error as OSCMessage.DecodeError {
// handle message errors
} catch {
// handle other errors
}
func handleOSCPayload(_ oscPayload: OSCPayload) {
switch oscPayload {
case .bundle(let bundle):
// recursively handle nested bundles and messages
bundle.elements.forEach { handleOSCPayload($0) }
case .message(let message):
// handle message
}
}
To send multiple OSC messages or nested OSC bundles to the same destination at the same time, pack them in an OSCBundle
and send the bundle's rawData
bytes as the outgoing UDP message.
let msg1 = OSCMessage(address: "/msg1")
let msg2 = OSCMessage(address: "/msg2", values: [.string("string"), .int32(123)])
let bundle = OSCBundle([msg1, msg2])
yourUDPSocket.send(bundle.rawData)
To send a single message, construct an OSCMessage
and send the message's rawData
bytes as the outgoing UDP message.
let msg = OSCMessage(address: "/msg2", values: [.string("string"), .int32(123)])
yourUDPSocket.send(msg.rawData)
Will be added in future.
Coded by a bunch of 🐹 hamsters in a trenchcoat that calls itself @orchetect.
Licensed under the MIT license. See LICENSE for details.
Contributions are welcome. Feel free to post an Issue to discuss.
link |
Stars: 23 |
Last commit: 3 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics