Common Lisp Package: OSC

OSC aka the 'open sound control' protocol

README:

Open Sound Control

This is a common lisp implementation of the Open Sound Control Protocol aka OSC. The code should be close to the ansi standard, and does not rely on any external code/ffi/etc+ to do the basic encoding and decoding of packets. since OSC does not specify a transport layer, messages can be send using TCP or UDP (or carrier pigeons), however it seems UDP is more common amongst the programmes that communicate using the OSC protocol. the osc-examples.lisp file contains a few simple examples of how to send and recieve OSC via UDP, and so far seems reasonably compatible with the packets send from/to max-msp, pd, supercollider and liblo. more details about OSC can be found at http://www.cnmat.berkeley.edu/OpenSoundControl/

the current version of this code is avilable from github

git clone https://github.com/zzkt/osc 

or via asdf-install.. .

(asdf-install:install :osc) 

limitations

  • doesnt send nested bundles or syncronisable timetags
  • will raise an exception if the input is malformed
  • doesn't do any pattern matching on addresses
  • float en/decoding only tested on sbcl, cmucl, openmcl and allegro
  • only supports the type(tag)s specified in the OSC spec

things to do in :osc

  • address patterns using pcre
  • data checking and error handling
  • portable en/decoding of floats -=> ieee754 tests
  • doubles and other defacto typetags
  • correct en/decoding of timetags

things to do in :osc-ex[tensions|tras]

  • liblo like network wrapping
  • add namespace exploration using cl-zeroconf

changes

  • 2011-04-19
    • converted repo from darcs->git
  • 2007-02-20
    • version 0.5
    • Allegro CL float en/decoding from vincent akkermans <vincent.akkermans@gmail.com>
  • 2006-02-11
    • version 0.4
    • partial timetag implemetation
  • 2005-12-05
    • version 0.3
    • fixed openmcl float bug (decode-uint32)
  • 2005-11-29
    • version 0.2
    • openmcl float en/decoding
  • 2005-08-12
    • corrections from Matthew Kennedy <mkennedy@gentoo.org>
  • 2005-08-11
    • version 0.1
  • 2005-03-16
    • packaged as an asdf installable lump
  • 2005-03-11
    • bundle and blob en/de- coding
  • 2005-03-05
    • 'declare' scattering and other optimisations
  • 2005-02-08
    • in-package'd
    • basic dispatcher
  • 2005-03-01
    • fixed address string bug
  • 2005-01-26
    • fixed string handling bug
  • 2005-01-24
    • sends and receives multiple arguments
    • tests in osc-tests.lisp
  • 2004-12-18
    • initial version, single args only

FUNCTION

Public

DECODE-BUNDLE (DATA)

decodes an osc bundle into a list of decoded-messages, which has an osc-timetagas its first element

DECODE-MESSAGE (MESSAGE)

reduces an osc message to an (address . data) pair. ..

ENCODE-BUNDLE (DATA &OPTIONAL TIMETAG)

will encode an osc message, or list of messages as a bundle with an optional timetag (symbol or 64bit int). doesnt handle nested bundles

ENCODE-MESSAGE (ADDRESS &REST DATA)

encodes an osc message with the given address and data.

Private

DECODE-BLOB (BLOB)

decode a blob as a vector of unsigned bytes.

DECODE-FLOAT32 (S)

ieee754 float from a vector of 4 bytes in network byte order

DECODE-INT32 (S)

4 byte -> 32 bit int -> two's compliment (in network byte order)

DECODE-STRING (DATA)

converts a binary vector to a string and removes trailing #nul characters

DECODE-TAGED-DATA (DATA)

decodes data encoded with typetags... NOTE: currently handles the following tags i => #(105) => int32 f => #(102) => float s => #(115) => string b => #(98) => blob

DECODE-TIMETAG (TIMETAG)

decomposes a timetag into unix-time and a subsecond,. . .

DECODE-UINT32 (S)

4 byte -> 32 bit unsigned int

ENCODE-BLOB (BLOB)

encodes a blob from a given vector

ENCODE-DATA (DATA)

encodes data in a format suitable for an OSC message

ENCODE-FLOAT32 (F)

encode an ieee754 float as a 4 byte vector. currently sbcl/cmucl specifc

ENCODE-INT32 (I)

convert an integer into a sequence of 4 bytes in network byte order.

ENCODE-STRING (STRING)

encodes a string as a vector of character-codes, padded to 4 byte boundary

ENCODE-TIMETAG (UTIME &OPTIONAL SUBSECONDS)

encodes an osc timetag from a universal-time and 32bit 'sub-second' part. for an 'instantaneous' timetag use (encode-timetag :now) for a timetag with the current time use (encode-timetag :time)

ENCODE-TYPETAGS (DATA)

creates a typetag string suitable for the given data. valid typetags according to the osc spec are ,i ,f ,s and ,b non-std extensions include ,{h|t|d|S|c|r|m|T|F|N|I|[|]} see the spec for more details. .. NOTE: currently handles the following tags i => #(105) => int32 f => #(102) => float s => #(115) => string b => #(98) => blob and considers non int/float/string data to be a blob.

PAD (N)

make a sequence of the required number of #Nul characters

PADDED-LENGTH (S)

returns the length of an osc-string made from a given length of string

PADDING-LENGTH (S)

returns the length of padding required for a given length of string

STRING-PADDING (STRING)

returns the padding required for a given osc string

Undocumented

CAT (&REST CATATAC)

DECODE-ADDRESS (ADDRESS)

ENCODE-ADDRESS (ADDRESS)

ENCODE-BUNDLE-ELT (DATA)

CONSTANT

Private

Undocumented

+UNIX-EPOCH+