Swiftpack.co - Package - sammysmallman/OSCKit

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.

“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.

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

Authors

Sammy Smallman - Initial Work - SammySmallman

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

Acknowledgments

Github

link
Stars: 42
Last commit: 2 weeks ago

Related Packages

Releases

OSCKit v2.1.3 - 2020-11-15T09:38:01

  • Refactored TCP SLIP framing.
  • Renamed OSCBundle initialisation methods to be shorter and more in keeping with Apple's style.
  • The broadcast flag for UDP packets is automatically set.
  • Added a debug delegate to receive all log messages.