OSCdef:
Filter:
Classes | External Control > OSC > Dispatchers

OSCdef : OSCFunc : AbstractResponderFunc : Object

OSC response reference definition

Description

OSCdef provides a global reference to the functionality of its superclass OSCFunc. Essentially it stores itself at a key within a global dictionary, allowing replacement at any time. Most methods are inherited from its superclass.

Class Methods

OSCdef.all

Get the global dictionary of all OSCdefs.

Returns:

OSCdef.new(key, func, path, srcID, recvPort, argTemplate, dispatcher)

Create a new, enabled OSCdef. If an OSCdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).

Arguments:

key

The key at which to store this OSCdef in the global collection. Generally this will be a Symbol.

func

A Function or similar object which will respond to the incoming message. When evaluated it will be passed the following arguments:

msgmessage as an Array in the form [OSC address, args1, arg2, ...]
timethe time received (for messages) / the OSC bundle's timestamp (if the message was in a bundle)
addra NetAddr corresponding to the IP address of the sender
recvPortInteger corresponding to the port on which the message was received.
path

A Symbol indicating the path of the OSC address of this object. Note that OSCdef demands OSC compliant addresses. If the path does not begin with a / one will be added automatically.

srcID

An optional instance of NetAddr indicating the IP address of the sender. If set this object will only respond to messages from that source.

recvPort

An optional Integer indicating the port on which messages will be received. If set this object will only respond to message received on that port. This method calls Main: -openUDPPort to ensure that the port is opened.

argTemplate

An optional Array composed of instances of Integer or Function (or objects which respond to the method Methods: matchItem) used to match the arguments of an incoming OSC message. If a Function, it will be evaluated with the corresponding message arg as an argument, and should return a Boolean indicating whether the argument matches and this OSCdef should respond (providing all other arguments match). Template values of nil will match any incoming argument value.

dispatcher

An optional instance of an appropriate subclass of AbstractDispatcher. This can be used to allow for customised dispatching. Normally this should not be needed.

Returns:

An instance of OSCdef.

OSCdef.newMatching(key, func, path, srcID, recvPort, argTemplate)

A convenience method to create a new, enabled OSCdef whose dispatcher will perform pattern matching on incoming OSC messages to see if their address patterns match this object's path.

Arguments:

key

The key at which to store this OSCdef in the global collection. Generally this will be a Symbol.

func

A Function or similar object which will respond to the incoming message. When evaluated it will be passed the arguments msg, time, addr, and recvPort, corresponding to the message as an Array [OSC address, args1, arg2, ...], the time that the message was sent, a NetAddr corresponding to the IP address of the sender, and an Integer corresponding to the port on which the message was received.

path

A Symbol indicating the path of the OSC address of this object. Note that OSCdef demands OSC compliant addresses. If the path does not begin with a / one will be added automatically. Pattern matching will be applied to any incoming messages to see if they match this address. Note that according to the OSC spec, regular expression wildcards are only permitted in the incoming message's address pattern. Thus path should not contain wildcards. For more details on OSC pattern matching, see http://opensoundcontrol.org/spec-1_0

srcID

An optional instance of NetAddr indicating the IP address of the sender. If set this object will only respond to messages from that source.

recvPort

An optional Integer indicating the port on which messages will be received.

argTemplate

An optional Array composed of instances of Integer or Function (or objects which respond to the method Methods: matchItem) used to match the arguments of an incoming OSC message. If a Function, it will be evaluated with the corresponding message arg as an argument, and should return a Boolean indicating whether the argument matches and this OSCFunc should respond (providing all other arguments match). Template values of nil will match any incoming argument value.

Returns:

An instance of OSCdef.

OSCdef.freeAll

Clears and deactivates all OSCdefs from the global collection.

Inherited class methods

Instance Methods

.key

Get this OSCdef's key.

Returns:

Usually a Symbol.

.free

Clears this OSCdef from the global collection and deactivates it.

Inherited instance methods

Examples

Timing in incoming bundles

The time argument indicates the time the message was sent plus, if given, the latency added to the bundle: