About
Welcome to the documentation for osckit, a powerful toolkit for working with Open Sound Control (OSC) messages in your iOS applications.
Installation
To integrate osckit into your Xcode project using CocoaPods, add the following line to your `Podfile`:
pod 'osckit'
To manually install osckit into your project, follow these steps:
- Download the latest release from the GitHub repository.
- Unzip the downloaded file and navigate to the extracted folder.
- Drag and drop the `osckit.framework` file into the “Embedded Binaries” section of your Xcode project.
- In the project settings, select your app target, go to the “Build Phases” tab, and click the “+” button to add a new “Run Script Phase”.
- Within the run script, add the following command to copy the framework into the app bundle:
“`shell
/bin/sh “$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/osckit.framework/install-framework.sh”
“`
Usage
Importing osckit
In your Swift file, import osckit using the following statement:
import osckit
Sending OSC messages
To send an OSC message, use the following code:
“`swift
let oscManager = OSCManager(serverAddress: “192.168.1.100”, serverPort: 9000)
let message = OSCMessage(address: “/example”)
message.add(Float(3.14))
message.add(“Hello, world!”)
message.add(42)
oscManager.sendMessage(message)
“`
Receiving OSC messages
To receive OSC messages, create an `OSCDelegate` object and implement the `receivedMessage` method:
“`swift
class ExampleDelegate: OSCDelegate {
func receivedMessage(_ message: OSCMessage) {
// Handle the received OSC message
print(message.address)
print(message.arguments)
}
}
let oscManager = OSCManager(serverPort: 9000)
let delegate = ExampleDelegate()
oscManager.addDelegate(delegate)
oscManager.startListening()
“`
Advanced Features
Bundle and Unbundle
osckit provides functions to bundle and unbundle OSC messages. This allows you to serialize OSC messages into binary data or deserialize binary data into OSC messages.
“`swift
// Bundle an OSC message into binary data
let bundledData = OSCManager.bundle(message)
// Unbundle binary data into an OSC message
let unbundledMessage = OSCManager.unbundle(bundledData)
“`
Introspection
osckit allows you to inspect OSC messages and retrieve information about their addresses and arguments.
“`swift
let message = OSCMessage(address: “/example”)
message.add(Float(3.14))
message.add(“Hello, world!”)
print(message.address) // Output: “/example”
print(message.arguments) // Output: [3.14, “Hello, world!”]
“`
Address Pattern Matching
osckit supports address pattern matching to filter incoming OSC messages based on their addresses.
“`swift
class ExampleDelegate: OSCDelegate {
func receivedMessage(_ message: OSCMessage) {
if message.matchesAddress(“/example/*”) {
// Handle the received OSC message with the address matching pattern
}
}
}
“`
Example App
For a complete example app utilizing osckit, please check out our GitHub repository.