Swiftpack.co -  sammysmallman/OSCKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
sammysmallman/OSCKit
A Swift library for sending, receiving, and parsing OSC messages & bundles.
.package(url: "https://github.com/sammysmallman/OSCKit.git", from: "2.1.5")

“OSCKit”/

OSCKit

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.

A simple demo project can be found here.

Installation

Xcode 11+

Add the package dependency to your Xcode project using the following repository URL:

https://github.com/SammySmallman/OSCKit

Swift Package Manager

Add the package dependency to your Package.swift and depend on "OSCKit" in the necessary targets:

dependencies: [
    .package(url: "https://github.com/SammySmallman/OSCKit", from: "2.1.0")
]

App Sandbox Network Settings

  • Enable Incoming Connections (Server)
  • Enable Outgoing Connections (Client)

Quick Start

OSC Client

Step 1

Import OSCKit framework into your project

import OSCKit

Step 2

Create a client

let client = OSCClient()
client.interface = "en0"
client.host = "10.101.100.101"
client.port = 24601
client.useTCP = true
client.delegate = self

Step 3

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)")
}

Step 4

Create a message

let message = OSCMessage(with: "/osc/kit", arguments: [1,
                                                    3.142,
                                                    "hello world!",
                                                    Data(count: 2),
                                                    OSCArgument.oscTrue,
                                                    OSCArgument.oscFalse,
                                                    OSCArgument.oscNil,
                                                    OSCArgument.oscImpulse])

Step 5

Send a message

client.send(packet: message)

OSC Server

Step 1

Import OSCKit framework into your project

import OSCKit

Step 2

Create a Server

let server = OSCServer()
server.port = 24601
server.interface = "en0"
server.reusePort = true
server.delegate = self

Step 3

Conform to the Server Delegate Protocol's

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)")
}

Step 4

Start Listening

do {
    try server.startListening()
} catch let error {
    print(error.localizedDescription)
}

Authors

Sammy Smallman - Initial Work - SammySmallman

See also the list of contributors who participated in this project.

Acknowledgments

GitHub

link
Stars: 51
Last commit: 3 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Related Packages

Release Notes

OSCKit v2.1.5
13 weeks ago
  • Added minimum platform requirements

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API