sc3.base.responders module

ResponseDefs.sc

class AbstractMessageMatcher

Bases: abc.ABC

class AbstractDispatcher

Bases: abc.ABC

all = {}
abstract add(func_proxy)

Proxies call this to add themselves to this dispatcher. Should register this if needed.

abstract remove(func_proxy)

Proxies call this to remove themselves from this dispatcher. Should unregister if needed.

abstract register()

Register this dispatcher to listen for its message type.

abstract unregister()

Unregister this dispatcher so it no longer listens.

free()
abstract type_key()

Name of the dispatcher as str.

class AbstractWrappingDispatcher

Bases: sc3.base.responders.AbstractDispatcher

add(func_proxy)

Proxies call this to add themselves to this dispatcher. Should register this if needed.

remove(func_proxy)

Proxies call this to remove themselves from this dispatcher. Should unregister if needed.

update_func_for_func_proxy(func_proxy)
abstract wrap_func(func_proxy)
abstract get_keys_for_func_proxy(func_proxy)
free()
class AbstractResponderFunc

Bases: object

Abstract superclass of responder funcs, which are classes which register one or more functions to respond to a particular type of input. It provides some common functionality such as introspection. Its two main subclasses are OscFunc, and MidiFunc. By default responder funcs do not persist beyond CmdPeriod.run() (see permanent property below).

Instances will register with a dispatcher (an instance of a subclass of AbstractDispatcher), which will actually dispatch incoming messages to an instance’s function(s).

property func

Responder function.

property permanent

A permanent responder is persistent after CmdPeriod.run().

By default this property is False.

enable()

Enable the responder to process incoming data.

disable()

Disable the responder, no data is processed.

one_shot()

Make the responder a one time action.

free()

Remove the responder form the set of available responders and disable it. This should be done when you are finished using this object.

class OscFuncAddrMessageMatcher(addr, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class OscFuncRecvPortMessageMatcher(recv_port, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class OscFuncBothMessageMatcher(addr, recv_port, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class OscArgsMatcher(arg_template, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class OscMessageDispatcher

Bases: sc3.base.responders.AbstractWrappingDispatcher

wrap_func(func_proxy)
get_keys_for_func_proxy(func_proxy)
register()

Register this dispatcher to listen for its message type.

unregister()

Unregister this dispatcher so it no longer listens.

type_key()

Name of the dispatcher as str.

class OscMessagePatternDispatcher

Bases: sc3.base.responders.OscMessageDispatcher

type_key()

Name of the dispatcher as str.

class OscFunc(func, path, src_id=None, recv_port=None, *, arg_template=None, dispatcher=None)

Bases: sc3.base.responders.AbstractResponderFunc

Fast Responder for incoming Open Sound Control Messages.

Instances of this class register one or more functions to respond to an incoming OSC message which matches a specified OSC Address. Many of its methods are inherited from its superclass AbstractResponderFunc. It supports pattern matching of wildcards etc. in incoming messages. For efficiency reasons you must specify that an OscFunc will employ pattern matching by creating it with the matching constructor, or by passing a matching dispatcher to dispatcher parameter of the default constructor. For details on the Open Sound Control protocol, see https://opensoundcontrol.stanford.edu/spec-1_0.html.

Parameters
  • func (callable) – A function which will respond to the incoming message. When evaluated it will be passed the following arguments: msg, the OSC message as a list in the form [‘/oscaddress’, args1, arg2, …], time, the bundle’s time plus the latency or the time of reception for messages, addr, a NetAddr instance corresponding to the IP address of the sender, and recv_port, an int corresponding to the port on which the message was received.

  • path (str) – The path of the OSC address of this object. Note that OscFunc demands OSC compliant addresses. If the path does not begin with a ‘/’ one will be added automatically.

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

  • recv_port (int) – Optional parameter indicating the port on which messages will be received. If set, this object will only respond to message received on that port. Note that setting this parameter it will open an UDP port if not opened already.

  • arg_template (list) – An optional list composed of valid OSC values or functions used to match the arguments of an incoming OSC message by position. If a function, it will be evaluated with the corresponding message’s value at the same positon 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 None will match any incoming argument value at that position.

  • dispatcher (AbstractDispatcher) – An optional instance of an appropriate subclass of AbstractDispatcher. This can be used to allow for customised dispatching. Normally this should not be needed and it requires to use the internal interface.

classmethod matching(func, path, src_id=None, recv_port=None, *, arg_template=None)

Create a responder with pattern matching capabilities.

Pattern matching will be applied to any incoming messages to see if they match this address (path). 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 https://opensoundcontrol.stanford.edu/spec-1_0.html.

See the default constructor other parameters description.

classmethod trace(flag=True, hide_status=False)

A convenience method which dumps all incoming OSC messages.

Parameters
  • flag (bool) – Dumping on or off.

  • hide_status (bool) – Whether server status messages are excluded from the dump or not.

class MidiFuncRecvPortMessageMatcher(midi_in, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class MidiArgsMatcher(arg_template, func)

Bases: sc3.base.responders.AbstractMessageMatcher

class MidiMessageDispatcher

Bases: sc3.base.responders.AbstractWrappingDispatcher

wrap_func(func_proxy)
get_keys_for_func_proxy(func_proxy)
register()

Register this dispatcher to listen for its message type.

unregister()

Unregister this dispatcher so it no longer listens.

type_key()

Name of the dispatcher as str.

class MidiFunc(func, midi_msg, port=None, *, arg_template=None, dispatcher=None)

Bases: sc3.base.responders.AbstractResponderFunc

classmethod trace(flag=True)

A convenience method which dumps all incoming MIDI messages.

Parameters

flag (bool) – Dumping on or off.

oscfunc(path, matching=False, **kwargs)

Decorator function to build OscFunc responders.

The ‘path’ argument is mandatory and must contain an OSC address as str.

Examples

@oscfunc('/message')
def resp(msg, time, addr, recv_port):
    print(msg, time, addr, recv_port)
midifunc(midi_msg, **kwargs)

Decorator function to build MidiFunc responders.

The ‘midi_msg’ argument is mandatory and must contain a MIDI message as str or a list of midi messages.

Examples

@midifunc('note_on')
def resp(msg, midi_in):
    print(msg, midi_in)

@midifunc(['note_on', 'note_off'])
def resp(msg, midi_in):
    print(msg, midi_in)