SwiftOSC is a Swift Open Sound Control (OSC) 1.1 client and server framework.
If you are using SwiftOSC in a project, let me know. I would love to make a list of projects using SwiftOSC.
pod 'SwiftOSC', '~> 1.4'
OR
Clone or download repository from Github.
Open SwiftOSC.xcworkspace and build SwiftOSC frameworks.
Embed SwiftOSC into project.
Import SwiftOSC framework into your project
import SwiftOSC
Create Server
var server = OSCServer(address: "", port: 8080)
Start server
server.start()
Setup server delegate to handle incoming OSC Data
class OSCHandler: OSCServerDelegate {
func didReceive(_ message: OSCMessage){
if let integer = message.arguments[0] as? Int {
print("Received int \(integer)")
} else {
print(message)
}
}
}
server.delegate = OSCHandler()
Import SwiftOSC framework into your project
import SwiftOSC
Create client
var client = OSCClient(address: "localhost", port: 8080)
Create a message
var message = OSCMessage(
OSCAddressPattern("/"),
100,
5.0,
"Hello World",
Blob(),
true,
false,
nil,
impulse,
Timetag(1)
)
Create a bundle
var bundle = OSCBundle(Timetag(secondsSinceNow: 5.0), message)
Send message
client.send(message)
Send bundle
// If the server fully supports timetags, like SwiftOSC, the bundle will be delivered at the correct time.
client.send(bundle)
For additional information on Open Sound Control visit http://opensoundcontrol.org/.