A Swift framework for sending, receiving, and parsing OSC messages & bundles.
Largely inspired and adapted from Figure 53's F53OSC Library.
Added features include:
- takeBundle() - OSCPacketDestinations are notified when an OSC bundle is received so that embedded messages and bundles can be acted upon asynchronously using the bundles timetag.
- Multicasting - Servers can join & leave multicast groups.
- OSC 1.0 & 1.1 Stream Framing.
For convenience, I've included a few public domain source files, Thanks and curiosity should rightfully be directed towards them:
CocoaAsyncSocket.
Swift-Netutils.
Inluded is a small demo app "Demo"
Import OSCKit framework into your project
import OSCKit
Create client
let client = OSCClient()
client.interface = "en0"
client.host = "10.101.100.101"
client.port = 3001
client.useTCP = true
client.delegate = self
Conform to the Client Delegate Protocol's
OSCClientDelegate:
func clientDidConnect(client: OSCClient) {
print("Client did connect")
}
func clientDidDisconnect(client: OSCClient) {
print("Client did disconnect")
}
OSCPacketDestination:
func take(message: OSCMessage) {
print("Received message - \(message.addressPattern)")
}
func take(bundle: OSCBundle) {
print("Received bundle - time tag: \(bundle.timeTag.hex() elements: \(bundle.elements.count)")
}
Create a message
let message = OSCMessage(messageWithAddressPattern: "/stamp/ping", arguments: [1, 3.142, "aStringArgument"])
Send a message
client.send(packet: message)