This documentation can be read online here: http://derlivecode.github.com/chaosc. You can also generate this in a lot of different output formats with sphinx, e.g pdf:
cd chaosc/docs
make latexpdf
The git repository is hosted by github here: https://github.com/DerLiveCode/chaosc
This documentation is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Chaosc is licensed under the GPL-3.
The chaosc framework was developed for a theatre project called “Der Live-Code”. It consists of several tools and a custom OSC library.
Chaosc itself is a osc hub/proxy, which takes osc messages and delivers them to subscribed receivers via UDP, written with two goals in mind.
For the sake of speed, we’ve completely rewritten the OSC.py lib. The usage is more streamlined, but also more error prone for using false type-tagged data in arguments, little type checking is done here. So devs working with the code are on their own to use the osc classes sanely, but it’s bleeding fast. There is a version written with cython for c level speed, and a fall-back pure python library. Below we’ll prove, that it’s also easy to use.
For now it supports the OSC 1.0 spec, and is optimized for UDP only. TCP is not supported. Chaosc runs in dualstack mode which have to be ironed out a bit more.
chaosc
The multi unicast osc proxy
chaosc_ctl
command line tool to control chaosc
chaosc_ts
test script to create n parallel osc senders
chaosc_tt
test script to create n parallel osc receivers
chaosc_filter
tool to filter and transcode osc messages by matching regular expressions on the osc address
chaosc_serial
tool to transcode data coming from a serial input into osc messages and vis versa. Used as a middleware for a gefen 4x4 hdmi video matrix, which sends its state back via serial on a routing change and a jazzmutant Lemur. The Lemur gefen control sketch can also be retrieved via the ‘DerLiveCode’ organization page on github.
chaosc_serial_input
tool to test the chaosc_serial client without serial hardware
chaosc_recorder
tool to record and replay osc messages like an audio recorder. In case that hub_address equals forward_address, no data will be forwarded in record or bypass mode.
Additionally there is a simple visual monitoring tool for chaosc written in java/processing.org, which can be found via https://github.com/DerLiveCode.
Dependencies should be automatically pulled in when installing chaosc. If you prefer using another installation method for the dependencies, install these packages.
easy_install -Z git://github.com/DerLiveCode/chaosc.git
Obtaining the repository:
git clone git://github.com/DerLiveCode/chaosc.git
Change current directory to your copy of chaosc:
cd chaosc
Install into system path:
sudo python setup.py install
Local developer mode installation:
sudo python setup.py develop
For more information about setup.py commands:
python setup.py --help-commands
Let’s check which flags our new tools understand:
chaosc -h
chaosc_ctl -h
chaosc_ts -h
chaosc_tt -h
chaosc_filter -h
chaosc_serial -h
chaosc_serial_input -h
Start your instance with a string token and a port of your choice. The token will be needed later. The right one must be appended to ctl messages to prove you are authorzied to control chaosc. It’s perhaps a good idea to use screen or another terminal multiplexer. After every code snipped you have to detach from the session if you use screen or open another terminal:
screen -U
chaosc -p 12345 -t foobar
# detach from screen session
To get other receivers subscribed, use the chaosc_ctl tool or create an osc message and send it to chaosc. The ctl commands are explained below in detail. Fire now up your senders and receivers on your own and skip the next shell code or use the test tools to start e.g 4 receivers beginning from port 13000 to 13003:
screen -U
chaosc_tt -H 127.0.0.1 -p 12345 -o 127.0.0.1 -r 13000 -t foobar -s -n 4
# detach from screen session
Pick another shell and start e.g 4 senders beginning from port 14000 to 14003:
screen -U
chaosc_ts -H localhost -p 12345 -n 4
# detach from screen session
We have created 4 test senders which get every osc message delivered to all 4 test receivers. Our receivers managed to subscribe to chaosc on their own by using the -s flag.
Now we want to test our serial tools. If you have no real serial device yet, you can create a pts pair. We’ll use socat for that task:
skoegl@workstation ~ % screen -U
skoegl@workstation ~ % sudo socat -d -d pty,raw,echo=1 pty,raw,echo=1
2013/01/22 18:53:26 socat[28831] N PTY is /dev/pts/4
2013/01/22 18:53:26 socat[28831] N PTY is /dev/pts/5
2013/01/22 18:53:26 socat[28831] N starting data transfer loop with FDs [3,3] and [5,5]
# detach from screen session
Use one pts node for the chaosc_filter and one for the chaosc_serial_input. To test the serial line, we need a running osc receiver or chaosc_tt and then the chaosc_serial tool. Let’s start our serial tool:
screen -U
chaosc_serial -i /dev/pts/4 -o localhost -r 11000 -H localhost -p 13000 -c ~/foobar_config
# detach from screen session
And our serial test tool:
screen -U
chaosc_serial_input -o /dev/pts/5
# detach from screen session
You place your subscriptions in a file called targets.config in your chaosc config directory you specify with the cli flag “-c path/to/your/cfg_dir”. The cli flag -s loads your targets.conf file.
Each line represents one recipient and should be of the form “host=foo;port=bar;label=baz”.
Let’s use the chaosc_ctl tool to subscribe a Lemur:
chaosc_ctl 127.0.0.1 12345 -t foobar subscribe 192.168.2.23 9999
Or the same configured up-front in the target.config file:
host=192.168.2.23;port=9999;label=lemur-1
And after our session we want to be nice users and remove the lemur from chaosc subscription:
chaosc_ctl -H 127.0.0.1 -p 12345 -t foobar unsubscribe 192.168.2.23 9999
By sending a ‘(un-)subscribe’ osc message. See OSC control interface for more information about using osc messages to control chaosc.
If you want to filter osc messages with regular expressions on the osc addresses, you can do so with the help of chaosc_filter. You have a white-list and a blacklist. Look into the example config file ‘filter.config’. There you can put a regular expression on each line prefixed with ‘white-list=’ or ‘black-list=’. The filter will load and use them. The white-list will be evaluated first, then the blacklist. So, if you use a filter tool, you should not subscribe the receiving client to which filtered messages gets forwarded, and subscribe your filter instance instead.
You can also transcode or modify osc messages as you like, but this is a bit more tricky. Look into transcoders.py how to implement custom ones. We have also implemented some transcoders for our tasks. e.g to change the osc address for a osc2midi device, extracting some integer data from the osc address, map all floating point arguments to the midi value space from 0-127, and finally use some of the matched data as new arguments. The configuration takes place in a real python file located at config/transcoding_config.py.
Also the filtering client can dump messages for monitoring purposes. If you provide the dump_only flag, it will not forward anything, just dumps the receiving messages.
Here is an example to start chaosc_filter:
screen -U
chaosc_filter -H 127.0.0.1 -p 12345 -o 127.0.0.1 -r 14000 -f 127.0.0.1 -F 12000 -t foobar -d -c ~/foobar_config
# detach from screen session
You want to have full control, which data will be used for the new OSCMessage. So we need a parameterized way to reference arguments in the old message, groups from the regular expression match, transcoder members.
The ‘regex’ parameter holds the string used to match against the osc address. Groups you match can be used in the mapper.
‘to_fmt’ is the string format template used by str.format
The mapper is an iterable of iterables aka a mapping clause with 5 items. Each mapping clause has the form [“from_directive”, “from_value”, “to_directive”, “to_value”, “format_directive”]
Here are the from_directives:
And the to_directives:
The from_value and to_value kann be a string as used as an attribute name usable by getattr or an integer used as an positional index.
The format_directive has to be an registered function in transcoders:converters:
- midi
- int
- float
- str
- unicode
You can use custom OSCMessages to control chaosc or to get operational stats.
The last typetagged argument “label’ is optional.
A OSCBundle with a list of OSCMessages.
makes chaosc_filter to activate filters for scene id.
makes chaosc_filter to activate filters for the following scene id.
makes chaosc_filter to activate filters for the previous scene id.
This module implements a osc hub/proxy
A multi-unicast osc application level gateway
Multiplexes osc messages from osc sources to subscribed targets.
Targets will receive messages after they are subscribed to chaosc. You can also use a targets.config file for static subscriptions.
Loads predefined subcriptions from a file in given config directory
Parameters: | path (str) – the directory in which the targets.config file resists |
---|
Sends incoming osc messages to subscribed receivers
Sends a osc bundle with subscribed clients and statistical data for monitoring and visualization usage.
handles a target subscription.
The provided ‘typetags’ equals [“s”, “i”, “s”, “s”] and ‘args’ contains [host, portnumber, token, label] or [“s”, “i”, “s”] and ‘args’ contains [host, portnumber, token]
only subscription requests with valid host and token will be granted.
Handle the actual unsubscription
The provided ‘typetags’ equals [“s”, “i”, “s”] and ‘args’ contains [host, portnumber, token]
Only unsubscription requests with valid host and token will be granted.
Instantiate an OSCServer. server_address ((host, port) tuple): the local host & UDP-port the server listens on
Parameters: |
|
---|
Returns a string containing this Server’s Class-name, software-version and local bound address (if any)
Registers a handler for an OSC-address
Parameters: |
|
---|
The callback-function must accept four arguments (str addr, tuple typetags, tuple args, tuple client_address), as returned by decode_osc.
Returns a (host,port) tuple of the local address this server is bound to or None if not bound to any address.
Handle incoming requests
Remove the registered handler for the given OSC-address
Parameters: | address (str) – the OSC address-string. It should start with ‘/’ and may not contain ‘*’ |
---|
Send the given OSCMessage to the specified address.
Parameters: |
|
---|---|
Except : | OSCError when timing out while waiting for the socket. |
This is a pure python osc lib implementation. This software is based on OSC.py, but was heavily modified and streamlined. There is also a cython based implementation, which should be prefered named c_osc_lib.pyx.
Use this import statement to be sure to get the c lib:
try:
from chaosc.c_osc_lib import *
except ImportError:
from chaosc.osc_lib import *
To use this library, you should have some basic knowledge how the OSC container format works. An OSCMessage is like a binary container or a list. It has a header, and some optional payload of heterogenous data. You can store arguments in the payload, but not OSCMessages. There also are OSCBundles. These are defined recursively as a container of OSCBundles and or OSCMessages. Never put an OSCMessage in an OSCMessage or a raw argument in an OSCBundle.
- 32 bit integer
- 32-bit float
- 64-bit long
- 64-bit double
- variable length string with length annotation
- variable length blob with length annotation
Base Class for all OSC-related errors
list of weak references to the object (if defined)
Marker Class for OSC Bundles
list of weak references to the object (if defined)
Builds typetagged OSC messages.
An OSCMessage is a container object used for construction of osc messages. On the ‘front’ end, they behave much like list-objects, and when needed they generate a OSC 1.1 spec compliant binary representation.
OSC-messages consist of an ‘address’-string (not to be confused with a (host, port) IP-address!), followed by a string of ‘typetags’ which indicates the arguments’ types, and finally the arguments themselves, encoded in an OSC-specific way.
On the Python end, OSCMessage are lists of arguments, prepended by the message’s address. The message contents can be manipulated much like a list:
>>> msg = OSCMessage("/my/osc/address")
>>> msg.append('something')
>>> msg.insert(0, 'something else')
>>> msg[1] = 'entirely'
>>> msg.extend([1,2,3.])
>>> msg.appendTypedArg(4, "i")
>>> msg.appendTypedArg(5, "i")
>>> msg.append(6.)
>>> del msg[3:6]
>>> msg.pop(-2)
5
>>> print msg
/my/osc/address ['something else', 'entirely', 1, 6.0]
>>> binary = encode_osc(msg)
>>> print repr(binary)
'/my/osc/address\x00,ssif\x00\x00\x00something else\x00\x00entirely\x00\x00\x00\x00\x00\x00\x00\x01@\xc0\x00\x00'
>>> msg2 = decode_osc(binary, 0, len(binary))
>>> print repr(msg2)
('/my/osc/address', ['s', 's', 'i', 'f'], ['something else', 'entirely', 1, 6.0])
Additional convenient methods exist for retrieving typetags or manipulating items as (typetag, value) tuples.
It’s perfectly ok to directly access the object members, but it’s up to you to keep typetags and args in sync.
Best practice for performance is to create your OSCMessage and store the binary representation in a variable and reuse it whenever possible. We’re also played with a simple representation cache, but decided against it. It’s really simple to implement one with annotations, subclassing or simply fork and hack straight into this module.
string which holds the messages’ osc address. This attribute can be changed directly.
list which holds the messages’ typetags.
list which holds the messages’ arguments.
To construct a timetagged collection of multiple OSCMessages, see OSCBundle!
Test if the given value appears in the OSCMessage’s arguments
Parameters: | argument (str or int or float or double) – the argument to check for presence |
---|---|
Return type: | bool |
Removes the indicated argument
Parameters: | index (int) – the position |
---|
Removes the indicated slice
Parameters: |
|
---|
Returns True if two OSCMessages have the same address & content
Parameters: | other (OSCMessage) – the osc message to compare |
---|---|
Return type: | bool |
Returns the indicated argument (or slice)
Parameters: | index (int) – the position |
---|---|
Returns: | the argument at position ‘index’ |
Return type: | str or int or float or double |
Instantiate a new OSCMessage. The OSC-address can be specified with the ‘address’ argument. The rest of the arguments are appended as data.
Parameters: | address (str) – osc address string |
---|
Returns an iterator of the OSCMessage’s arguments
Return type: | iterator |
---|
Returns the number of arguments this message contains
Return type: | int |
---|
Returns True if two OSCMessages have not the same address or content
Parameters: | other (OSCMessage) – the osc message to compare |
---|---|
Return type: | bool |
Returns a string containing the decode Message
Return type: | str |
---|
Returns a reverse iterator of the OSCMessage’s arguments
Return type: | iterator |
---|
Set indicatated argument (or slice) to a new value. ‘val’ can be a single int/float/string, or a (typehint, value) tuple. Or, if ‘i’ is a slice, a list of these or another OSCMessage.
Parameters: |
|
---|
Returns the Message’s address and contents as a string.
Return type: | str |
---|
list of weak references to the object (if defined)
Appends _one_ argument to the message.
The typetag is inferred from the argument’s type. If the argument is a blob (counted string) pass in ‘b’ as typetag.
Parameters: | argument (str or int or float or double) – a item to store in the message |
---|
Appends a typed argument to the message.
If the argument is a blob (counted string) pass in ‘b’ as typetag. Prefer this method above append().
Parameters: |
|
---|
clears all attributes to factory state and sets the address
Parameters: | address (str) – osc address |
---|
Returns the count a given value occurs in the OSCMessage’s arguments
Return type: | int |
---|
Returns the binary representation of the message
Parameters: | self (OSCMessage) – the OSCMessage to encode |
---|---|
Return type: | str |
Append the contents of ‘arguments’ to this OSCMessage. ‘values’ a list/tuple of ints/floats/strings
Parameters: | arguments (tuple) – the arguments to append |
---|
Extents this OSCMessage with the given arguments.
Prefer this method above extend().
Parameters: |
|
---|
Returns the index of the first occurence of the given value.
Parameters: | argument (str or int or float or double) – value to find in args |
---|---|
Raises : | ValueError if val isn’t found |
Return type: | int |
Insert given argument into the OSCMessage at the given index.
The typetag will be inferred.
Parameters: |
|
---|
Insert a typed argument at the given index.
Parameters: |
|
---|
Returns a list of (typetag, value) tuples for the arguments appended so far
Return type: | list |
---|
Deletes the given argument from the OSCMessage, and returns it.
Parameters: | argument (str or int or float or double) – the argument to insert |
---|---|
Returns: | argument |
Return type: | str or int or float or double |
Deletes the given argument from the OSCMessage, and returns it.
Parameters: | argument (str or int or float or double) – the argument to insert |
---|---|
Returns: | (typetag, argument) |
Return type: | tuple |
Removes the first argument with the given value from the OSCMessage.
Parameters: | argument (str or int or float or double) – the argument to insert |
---|---|
Return type: | ValueError if argument isn’t found. |
Reverses the arguments of the OSCMessage (in place)
Returns a list of typetags of the appended arguments
Return type: | list of str |
---|
Returns a list of the arguments appended so far
Return type: | list |
---|
Builds a ‘bundle’ of OSC messages.
OSCBundles are list objects for building binary osc containers for more than one message or bundle. They are defined recursively, so a bundle can hold more bundles or osc messages.
an argument must be an OSCMessage or an OSCBundle
OSC-messages do.
be processed. The default timetag value (0) means ‘immediately’.
Return True if two OSCBundles have the same timetag & content
Instantiate a new OSCBundle.
Parameters: |
|
---|
Returns the Bundle’s contents (and timetag, if nonzero) as a string.
list of weak references to the object (if defined)
Appends an OSCMessage
Any newly created OSCMessage inherits the OSCBundle’s address at the time of creation.
Parameters: | osc_message (OSCMessage) – the osc message to append |
---|
Returns the binary representation of the message
Returns: | the binary representation |
---|---|
Return type: | str |
Return the TimeTag as a human-readable string
Returns: | a human readable timetag representation |
---|---|
Return type: | str |
Set or change the OSCBundle’s TimeTag
Parameters: | time (float) – floating seconds since the Epoch, must be positive |
---|
Converts a binary OSC message to a Python list.
Convert a string into a zero-padded OSC String. The length of the resulting string is always a multiple of 4 bytes. The string ends with 1 to 4 zero-bytes (‘’)
Parameters: | argument (str) – the string to encode |
---|---|
Return type: | str |
Converts a binary OSC message to a Python list.
Parameters: |
|
---|---|
Returns: | osc_address, typetags, args |
Return type: | tuple |
A simple osc server/client to build upon our tools.
Subscribes to chaosc if you want.
Compare function.
Instantiate an OSCServer. server_address ((host, port) tuple): the local host & UDP-port the server listens on
Compare function.
Register a handler for an OSC-address - ‘address’ is the OSC address-string. the address-string should start with ‘/’ and may not contain ‘*’ - ‘callback’ is the function called for incoming OSCMessages that match ‘address’. The callback-function will be called with the same arguments as the ‘msgPrinter_handler’ below
Returns a (host,port) tuple of the local address this server is bound to, or None if not bound to any address.
Stops serving requests, closes server (socket), closes used client
connects as a sending client to another server
Remove the registered handler for the given OSC-address
Dispatches messages to a callback or a default msg handler, which should be registered with “X” as osc address.
If you don’t need message dispatching, you can also overwrite the SimpleOSCServer.process_request() inherited from BaseServer
Send the given OSCMessage to the specified address.
Parameters: |
|
---|---|
Except : | OSCError when timing out while waiting for the socket. |
Use this procedure for a quick’n dirty subscription to your chaosc instance.
Parameters: |
|
---|
This module implements the standalone filtering tool in the chaosc framework.
It uses the chaosc osc_lib but does not depend on chaosc features, so it can be used with other osc compatible gear.
We provide here osc message filtering based on python regex defined in a file and a very flexible transcoding toolchain, but it’s up to your python skills to master them. The TranscoderBaseHandler subclasses should be defined in the appropriate python module you place in the config directory. Please refer for a howto/examples to our comprehensive docs or look into the provided example transcoding.py file.
OSC filtering/transcoding middleware
ctor for filter server
starts the server, loads scene filters and transcoders and chooses the request handler, which is one of forward only, forward and dump, dump only.
Parameters: | result (namespace object) – return value of argparse.parse_args |
---|
Adds a transcoder to chaosc.
Parameters: | handler (ITranscoderHandler) – an TranscoderBaseHandler implementation |
---|
Handles this filtering, transcoding steps and forwards the result
Parameters: |
|
---|
Handles this filtering, transcoding steps and forwards the result
Parameters: |
|
---|
Handles this filtering, transcoding steps and forwards the result
Parameters: |
|
---|