def __init__( self, dst=None, dstPort=None, src=None, srcPort=None, ): """ This is the main class we the use as a nexus point in this module. - dst: destination/target host for OSC responses. If None will default to local network broadcast only. - src: Which local interface / ip to bind to, if unset defaults to all - srcPort: Source port to bind the server to for incoming OSC queries. Defaults to 9000 - dstPort: Destination port for OSC responses sent by callbacks. Defaults to 9001 By default we define and set callbacks for two utility functions that may be useful in testing. /remix/echo -> OSCServer.callbackEcho() - For responding to /remix/echo queries. /remix/time -> OSCServer.callbackTime() - Returns time.time() (time in float seconds) I chose OSC to deliver messages out of necessity, my opinion of OSC at this point is that its addressing system is heavyweight although the idea is a reasonable one. But taking into consideration the ratio of address:data it becomes somewhat unreasonable unless you take the route of making unreadable addresses. As an example I offer the following address, /ableton/track/1/volume/set float(0.98) To set a single 4 byte float value, we need to use a 27 byte string to get it routed to the correct area, and even then we need to make an O(N) comparison on the address since we don't have the luxury of a switch statement in Python. If you're trying to interact with devices in near-realtime the number of ops wasted on just getting things to the right place can take the wind out of your sails. But basically for this project to be accepted or useful to anyone it was important to me that we provide a method of accessing that other tools could use without having to introduce a new linewire protocol. It should be noted that performance even with the added ops isn't that bad. On my dualcore system I was able to process about 1380 OSC callbacks per second. Or, ~86 callbacks per 60ms tick. """ self.udpServer = UDPServer(src, srcPort) self.udpClient = UDPClient(dst, dstPort) self.udpClient.open() self.oscClient = OSCClient(self.udpClient, None, None) # Create our callback manager and register some utility # callbacks to show how its done. self.callbackManager = OSC.CallbackManager() self.callbackManager.add(self.callbackEcho, '/remix/echo') self.callbackManager.add(self.callbackEcho, '/remix/time') self.udpServer.setCallbackManager(self.callbackManager) self.udpServer.bind()
def __init__(self, **kwargs): self.addressManager = OSC.CallbackManager() self.queue = Queue() Process.__init__(self, args=(self.queue, )) self.daemon = True self._isRunning = Value('b', True) self._haveSocket = Value('b', False)
def __init__(self, remotehost='127.0.0.1', remoteport=9000, localhost='127.0.0.1', localport=9001): self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setblocking(0) self._local_addr = (localhost, localport) self._remote_addr = (remotehost, remoteport) try: self._socket.bind(self._local_addr) self.log_message('Starting on: ' + str(self._local_addr) + ', remote addr: ' + str(self._remote_addr)) except: self._in_error = True msg = 'ERROR: Cannot bind to ' + str( self._local_addr) + ', port in use' self.show_message(msg) self.log_message(msg) self._callback_manager = OSC.CallbackManager() self._callback_manager.add('/live/set_peer', self._set_peer)
def __init__(self, host='127.0.0.1', port=3333): self.host = host self.port = port self.current_frame = 0 self.last_frame = 0 self.open_socket() self.manager = OSC.CallbackManager() self.profiles = self.load_profiles()
def __init__(self, server_address, remote_address, prefix=''): self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setblocking(0) self.server_address = server_address self.remote_address = remote_address self._socket.bind(self.server_address) self.prefix = prefix self._callback_manager = OSC.CallbackManager() self.add_callback('/set_peer', self._set_peer)
def __init__(self, remotehost = '127.0.0.1', remoteport=9000, localhost='127.0.0.1', localport=9001): self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setblocking(0) self._local_addr = (localhost, localport) self._remote_addr = (remotehost, remoteport) self._socket.bind(self._local_addr) self.log_message('LiveOSC2 starting on: ' + str(self._local_addr) + ', remote addr: '+ str(self._remote_addr)) self._callback_manager = OSC.CallbackManager() self._callback_manager.add('/live/set_peer', self._set_peer)
def __init__( self, remoteHost='127.0.0.1', remotePort=9031, localHost='127.0.0.1', localPort=9030, ): """ This is the main class we the use as a nexus point in this module. - remoteHost and remotePort define the address of the peer that we send data to by default. It can be changed, at run time, using the /remix/set_peer OSC message. - localHost and localPort define the address that we are listening to for incoming OSC packets. By default, we are listening on all interfaces with port 9000. By default we define and set callbacks for some utility addresses: /remix/echo - Echos back the string argument to the peer. /remix/time - Returns time.time() (time in float seconds) /remix/set_peer - Reconfigures the peer address which we send OSC messages to """ self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.setblocking(0) self.localAddr = (localHost, localPort) self.socket.bind(self.localAddr) self.remoteAddr = (remoteHost, remotePort) log('OSCEndpoint starting, local address ' + str(self.localAddr) + ' remote address ' + str(self.remoteAddr)) # Create our callback manager and register some utility # callbacks self.callbackManager = OSC.CallbackManager() self.callbackManager.add('/remix/echo', self.callbackEcho) self.callbackManager.add('/remix/time', self.callbackEcho) self.callbackManager.add('/remix/set_peer', self.setPeer)
def __init__(self, **kwargs): Thread.__init__(self) self.addressManager = OSC.CallbackManager() self.daemon = True self.isRunning = True self.haveSocket = False
def init(): """ instantiates address manager and outsocket as globals """ global outSocket, addressManager outSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) addressManager = OSC.CallbackManager()
def createCallBackManager(): global addressManager addressManager = OSC.CallbackManager()