Swiftpack.co - orchetect/OSCKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by orchetect.
orchetect/OSCKit 0.2.2
Open Sound Control (OSC) library written in Swift.
⭐️ 23
🕓 46 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/orchetect/OSCKit.git", from: "0.2.2")

OSCKit

CI Build Status Platforms - macOS | iOS | tvOS | watchOS License: MIT

Open Sound Control (OSC) library written in Swift.

Note: The library does not contain a networking layer so you can modularly integrate OSCKit into whatever network module you choose. The repo contains an example project demonstrating using it with Apple's Network.framework.

Unit tests implemented.

Installation

Swift Package Manager (SPM)

To add OSCKit to your Xcode project:

  1. Select File → Swift Packages → Add Package Dependency
  2. Add package using https://github.com/orchetect/OSCKit as the URL.

Getting Started

Setup

import OSCKit

// set up your UDP port(s) with a 3rd-party network library of choice;
// no network layer is included in OSCKit

Receive

// in your UDP socket receive handler,
// assuming the "data" variable is raw data bytes from a received UDP packet:

do {
  guard let oscPayload = try data.parseOSC() else { return }
  handleOSCPayload(oscPayload)
} catch let error as OSCBundle.DecodeError {
  // handle bundle errors
} catch let error as OSCMessage.DecodeError {
  // handle message errors
} catch {
  // handle other errors
}

func handleOSCPayload(_ oscPayload: OSCPayload) {
  switch oscPayload {
  case .bundle(let bundle):
    // recursively handle nested bundles and messages
    bundle.elements.forEach { handleOSCPayload($0) }
  case .message(let message):
    // handle message
  }
}

Send

Bundle

To send multiple OSC messages or nested OSC bundles to the same destination at the same time, pack them in an OSCBundle and send the bundle's rawData bytes as the outgoing UDP message.

let msg1 = OSCMessage(address: "/msg1")
let msg2 = OSCMessage(address: "/msg2", values: [.string("string"), .int32(123)])

let bundle = OSCBundle([msg1, msg2])

yourUDPSocket.send(bundle.rawData)

Message

To send a single message, construct an OSCMessage and send the message's rawData bytes as the outgoing UDP message.

let msg = OSCMessage(address: "/msg2", values: [.string("string"), .int32(123)])

yourUDPSocket.send(msg.rawData)

Documentation

Will be added in future.

Roadmap

  • ☐ Add full timetag support (OSC 1.0 spec)
  • ☐ Add address parsing (OSC 1.0 spec)
  • ☐ Cross-platform testing
  • ☐ Add custom OSC type tag values (♻️ In Progress)

Author

Coded by a bunch of 🐹 hamsters in a trenchcoat that calls itself @orchetect.

License

Licensed under the MIT license. See LICENSE for details.

Contributions

Contributions are welcome. Feel free to post an Issue to discuss.

GitHub

link
Stars: 23
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.2.2
46 weeks ago
  • Fixed example project so it works on localhost as expected

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