def mainLoop(maxHistory=50, pointLifetime=1e6, lineDetectionLevel=64, lineMinLength=100, circleDetectionLevel=8192, circleMaxRadius=256, circleMinRadius=30): global FRAMENUMBER try: oscServer = liblo.Server(9000) except liblo.AddressError, err: print(str(err)) sys.exit()
def main(): def tuio(dt): """pyglet callback event to check for OSC messages""" server.recv(0.0333333333333) skreen = canvas(photoDeck(skreenPics().sprites)) server = liblo.Server(3333) server.add_method('/tuio/2Dcur', None, skreen.handleOsc) #server.add_method('/tuio/2Dcur', None, debugtuio) pyglet.clock.schedule_interval(tuio, 0.0001) pyglet.clock.schedule(rabbyt.add_time) rabbyt.set_default_attribs() rabbyt.set_viewport((skreen.window.height, skreen.window.width)) pyglet.app.run()
def __init__(self): self.nleds = 160 self.sensitivity = 1. self.OSCserver = liblo.Server(8666) self.OSCserver.add_method(None, None, self.handleOSC) self.buff = bytearray(self.nleds*3) for i in range(len(self.buff)): self.buff[i] = 0x80 self.zeros = bytearray(5) self.spokes = [] for i in range(8): self.spokes.append([-1 for j in range(20)]) self.launchpad = [bytearray([0x80,0x80,0x80])]*8 self.colorTable = colorTable
def __init__(self, inst_type, inst_num): self.inst = artifastring_instrument.ArtifastringInstrument( inst_type, inst_num) self.Fb = [0.0,0.0,0.0,0.0] self.xb = [0.125,0.125,0.125,0.125] self.vb = [0.4,0.4,0.4,0.4] self.fp = [0.0,0.0,0.0,0.0] #self.active = [False, False, False, False] try: self.server = liblo.Server(3123) except liblo.ServerError, err: print str(err) exit()
def listen(): """blocking function listening to OSC messages. A callback is fired each time a message os received """ try: server = liblo.Server(OSClistenPort) print("listening to incoming OSC on port %i" % OSClistenPort) except liblo.ServerError as e: print(e) raise SystemError server.add_method(None, None, OSCcallback) while listenToOSC: server.recv(1)
def init(etc_object): global osc_server, osc_target, etc etc = etc_object # OSC init server and client try: osc_target = liblo.Address(4001) except liblo.AddressError as err: print(err) try: osc_server = liblo.Server(4000) except liblo.ServerError, err: print str(err)
def __init__(self, address=("127.0.0.1", 9900), listen_port=9002): self.beat_callback = None self.startup_callback = None self.listen_port = listen_port #------------------------------------------------------------------------ # Handler callbacks for particular messages from Live. # Used so that other processes can register callbacks when states change. #------------------------------------------------------------------------ self.handlers = {} self.osc_address = address if OSC_BACKEND == 'liblo': self.osc_target = liblo.Address(address[0], address[1]) self.osc_server = liblo.Server(listen_port) self.osc_server.add_method(None, None, self.handler) self.osc_server.add_bundle_handlers(self.start_bundle_handler, self.end_bundle_handler) elif OSC_BACKEND == 'pythonosc': # TODO how to deal w/ bundles? even necessary? # (the handlers seem to be just logging...) # (i think only some of the clip code refers to bundles at all) ip = address[0] self.osc_client = SimpleUDPClient(ip, address[1]) self.dispatcher = Dispatcher() self.dispatcher.set_default_handler(self.pythonosc_handler_wrapper) # TODO TODO may need to take more care that this, or the other # pythonosc objects, actually close all of their connections before # exit / atexit # for some reason, maybe most likely something else, there seem to # be less frequent apparent "connection" issues with liblo than with # pythonosc... self.osc_server = ThreadingOSCUDPServer((ip, listen_port), self.dispatcher) self.osc_server_thread = None self.osc_read_event = None self.osc_timeout = 3.0 self.osc_server_events = {} self.query_address = None self.query_rv = [] self.listen()
def osc_init(self): global zyngine_osc_port try: self.osc_target = liblo.Address(zyngine_osc_port) self.osc_server = liblo.Server() #self.osc_server.add_method(None, None, self.cb_osc_all) self.osc_server.add_method("/volume", 'i', self.cb_osc_load_instr) self.osc_server.add_method("/paths", None, self.cb_osc_paths) self.osc_server.add_method(None, 'i', self.cb_osc_ctrl) #print("OSC server running in port " % (str(self.osc_server.get_port()))) #liblo.send(self.osc_target, "/echo") print("OSC Server running"); except liblo.AddressError as err: print("ERROR: OSC Server can't be initialized (%s). Running without OSC feedback." % (str(err)))
def __init__(self, size=(600,600)): pygame.init() pygame.display.set_caption('SoundPuddle Simulator') self.size = size self.radius = np.sqrt(self.size[0]**2+self.size[1]**2) self.screen = pygame.display.set_mode(self.size) self.center = self.size[0]/2, self.size[1]/2 self.spokes = [ np.array([np.cos(2*np.pi*i/24), np.sin(2*np.pi*i/24)]) for i in range(24) ] # unit vectors self.particles = [] ### self.drawLines() pygame.display.flip() self.OSCserver = liblo.Server(8666) self.OSCserver.add_method(None, None, self.handleOSC)
def init_osc(): global osc_server, osc_target print "config osc target" osc_target = liblo.Address(4001) print "config osc osc_server" # make sure the port is available... ahh ok os.system("fuser -k 4002/udp") try: osc_server = liblo.Server(4002) osc_server.add_method("/encoder/turn", 'i', enc_turn) osc_server.add_method("/encoder/button", 'i', enc_press) except liblo.ServerError, err: print str(err) sys.exit()
def osc_init(self, port=1370, proto=liblo.UDP): try: self.osc_server = liblo.Server(port, proto) self.osc_server_port = self.osc_server.get_port() self.osc_server_url = liblo.Address('localhost', self.osc_server_port, proto).get_url() logging.info("ZYNTHIAN-UI OSC server running in port {}".format( self.osc_server_port)) self.osc_server.add_method(None, None, self.osc_cb_all) #self.osc_server.start() #except liblo.AddressError as err: except Exception as err: logging.error( "ZYNTHIAN-UI OSC Server can't be started: {}".format(err))
def listenToOSC(): try: server = liblo.Server(OSClistenPort) print("listening to incoming OSC on port %i" % OSClistenPort) except liblo.ServerError as e: print(e) raise SystemError server.add_method("/ACK", None, handleAck) server.add_method("/fadeACK", None, handleAck) server.add_method("/myID", None, handleID) server.add_method(None, None, unknownOSC) while runOSCserver: server.recv(50) print(" OSC server has closed")
def __init__(self, oscport=11111): self.conn = None self.connect_serial() self.oscport = oscport self.minbrightness = 0 self.maxbrightness = 1000 try: # self.server = MyOSCServer(("localhost", oscport)) self.server = liblo.Server(11111) except: logging.debug("Could not create OSC server. Is it already open?") raise RuntimeError("osc error") self._running = False self._lastlum = -1 self.thread = None self.add_handlers_liblo()
def __init__(self): # This is how you register a parameter with the lux engine. # Parameters can be controlled using OSC or in the GUI. lux.register( Parameter(name="TouchCubes_simple_rate", description="0..1 controls the rate of spinning cubes", namespace="touch_cubes", min_value=0.0, max_value=1.0, default_value=1.0, stateful=True)) # create server, listening on port 1234 try: self.server = liblo.Server(8000) except liblo.ServerError, err: print str(err) sys.exit()
def __init__(self, gui, pedlbrd_address, parent=None): QThread.__init__(self, parent) self.s = liblo.Server() if isinstance(pedlbrd_address, (list, tuple)): addr = liblo.Address(*pedlbrd_address) else: addr = liblo.Address(pedlbrd_address) self.pedlbrd_address = addr self.register_osc_methods() self.s.send(self.pedlbrd_address, '/register') self.s.send(self.pedlbrd_address, '/registerui') self.gui = gui self._heartbeat_counter = 0 self._reply_callbacks = {} self._last_replyid = 0 self._last_time_anpin = [0, 0, 0, 0] self._analog_value = [0, 0, 0, 0]
def listenToOSC(): """ this function handles OSC reception. It is blocking and meant to be run as a thread. The thread will exit gracefully when the runOSCserver bool is set to False""" try: server = liblo.Server(OSClistenPort) print(" listening to incoming OSC on port %i" % OSClistenPort) except liblo.ServerError as e: print(e) raise SystemError server.add_method("/ACK", None, handleAck) server.add_method("/fadeACK", None, handleAck) server.add_method("/myID", None, handleID) server.add_method(None, None, unknownOSC) while runOSCserver: server.recv(50) print(" OSC server has closed")
def __init__(self): #self.touch_osc_host = g.touch_osc_host self.touch_osc = liblo.Address(g.touch_osc_host, self.touch_osc_out_port) self.send_part_names() self.send_slider_names() self.send_channel_names() self.send_parts() self.send_sliders() self.send_channels() self.send_mutes() self.clear_beats() try: self.osc_server = liblo.Server(self.touch_osc_in_port) except liblo.ServerError, err: print str(err)
def listen(): global server readMidiNote() if not os.path.isdir("wav"): os.makedirs("wav") myIP = getLocalIP() try: server = liblo.Server(listenPort) print("listening to incoming OSC on port %i" % listenPort) except liblo.ServerError as e: print(e) raise SystemError server.add_method( "/solenoid", None, solenoid.actuate ) # ex1 : /solenoid | ex2 : /solenoid 50 (pulse duration in ms) server.add_method( "/noteOn", None, noteOn) # ex1 : /solenoid | ex2 : /solenoid 50 (pulse duration in ms) server.add_method( "/play", None, audio.playFile ) # ex : /readAudio myfile.wav [transducer] : if no output is named, defaults to transducer server.add_method("/stop", None, audio.stop) # ex : /stop server.add_method("/route", None, audio.route) # ex : /route analogIN analogOUT server.add_method("/disconnect", None, audio.disconnect) # ex : /unroute analogIN server.add_method("/mute", None, audio.mute) # ex : /mute analogOUT server.add_method("/unmute", None, audio.mute) # ex : /unmute analogOUT server.add_method("/toggle", None, audio.mute) # ex : /toggle analogOUT server.add_method("/volume", None, audio.setVolume) # ex : /volume analogOUT 96 server.add_method("/delete", None, deleteAudioFile) # ex : /volume analogOUT 96 server.add_method("/shutdown", None, shutdown) # ex : /volume analogOUT 96 server.add_method("/getFileList", None, sendFileList) # ex : /volume analogOUT 96 server.add_method("/getInfos", None, sendID) # ex : /volume analogOUT 96 server.add_method("/changeHostname", None, changeHostname) # ex : /volume analogOUT 96 server.add_method(None, None, unknownOSC) while runServer: server.recv(100) print(" OSC server has closed")
def __init__(self, port=1234, queue=None): # thread init super(OSCsrv, self).__init__() # threading.Thread.__init__(self) self.server = None self.port = port self.queue = queue # self.name = 'OSCsrv' self.name = str(self.__class__).split(".")[-1].replace("'>", "") # signal.signal(signal.SIGINT, self.shutdown_handler) # rospy.init_node(self.name, anonymous=True) # self.isrunning = True # self.cnt_main = 0 # self.loop_time = 0.1 try: self.server = liblo.Server(self.port) print(f'oscsrv.OSCsrv server started on port {self.port}') self.isrunning = True except liblo.ServerError as err: print(err) self.isrunning = False # sys.exit() # register method taking an int and a float # self.server.add_method("/mfcc", 'i' + 'f' * 38, self.cb_mfcc) # self.server.add_method("/mfcc", 'i' + 'f' * 1024, self.cb_mfcc) # self.cb_mfcc_stats = { # 'cnt': 0, # 'seq': 0, # 'last': time.time(), # 'freq': 0., # 'period_mu': 1000., # 'period_var': 0., # } # self.server.add_method("/beat", 'f' * 3, self.cb_beat) self.st = threading.Thread(target=self.run) self.st.start()
def __init__(self, client, edge_client, latencyListenerHost, latencyListenerPort, endpoint1='/launchtime'): self.client = client self.edge_client = edge_client try: self.edge_client.findEndpoints() except Exception: logging.error("problem finding endpoints for edge client") sys.exit(0) self.host = latencyListenerHost self.port = latencyListenerPort self.clientRunnerThread = None self.endpoint = endpoint1 self.osc_server = liblo.Server(self.port) self.osc_server.add_method(endpoint1, 'iib', self.launchTime)
def init_osc(self): # create server, listening on port 1234 try: self.server = liblo.Server(OSC_PORT) except liblo.ServerError as err: print(str(err)) sys.exit() # register method taking an int and a float self.server.add_method("/zyn/encoder/inc", 'if', self.osc_encoder_inc) self.server.add_method("/zyn/encoder/dec", 'if', self.osc_encoder_dec) self.server.add_method("/zyn/encoder", 'if', self.osc_encoder) self.server.add_method("/zyn/press", 'i', self.osc_press) self.server.add_method("/zyn/release", 'i', self.osc_release) # default callback self.server.add_method(None, None, self.osc_fallback) # start to listen self.stop_event=threading.Event() self.c_thread=threading.Thread(target=self.OSCListener, args=(self.stop_event,)) self.c_thread.start()
def __init__(self, hostname="127.0.0.1", port=57110): """ Create a new Server object, which is a local representation of a remote SuperCollider server. Args: hostname (str): Hostname or IP address of the server port (int): Port of the server """ self.client_address = liblo.Address(hostname, port) #----------------------------------------------------------------------- # Set up OSC server and default handlers for receiving messages. #----------------------------------------------------------------------- self.osc_server = liblo.Server(random.randint(57200, 57900)) self.osc_server.add_method(None, None, self._osc_handler) self.osc_server_thread = threading.Thread(target=self._osc_server_read) self.osc_server_thread.setDaemon(True) self.osc_server_thread.start() self.handlers = { "/n_set": {}, "/b_info": {}, "/b_setn": {}, "/done": {}, "/status.reply": None, "/version.reply": None, "/synced": None, "/g_queryTree.reply": None } #----------------------------------------------------------------------- # Necessary when querying a node ID for add actions. #----------------------------------------------------------------------- self.id = 0 try: self.sync() except SuperColliderConnectionError as e: self.osc_server.free() self.osc_server = None raise e
def __init__(self, address = ("localhost", 9000), listen_port = 9001): self.indent = 0 self.beat_callback = None self.startup_callback = None self.listen_port = listen_port # handler callbacks for particular messages from Live. # used so that other processes can register callbacks when states change. self.handlers = {} self.osc_address = address self.osc_target = liblo.Address(address[0], address[1]) self.osc_server = liblo.Server(listen_port) self.osc_server.add_method(None, None, self.handler) self.osc_server_thread = None self.osc_read_event = None self.osc_timeout = 5 self.osc_server_events = {} # self.response_address = None self.listen()
def listen(): global server try: server = liblo.Server(listenPort) print("listening to incoming OSC on port %i" % listenPort) except liblo.ServerError as e: print(e) raise SystemError server.add_method("/readMidi", None, midiFile.play) server.add_method("/stopMidi", None, midiFile.stop) server.add_method("/delete", None, midiFile.delete) server.add_method("/whoIsThere", None, clients.whoIsThere) server.add_method("/knownClients", None, clients.sendKnownClients) server.add_method("/heartbeat", None, clients.processHeartbeat) server.add_method("/filesList", None, clients.processFileList) server.add_method("/myID", None, clients.processClientsInfos) server.add_method("/myVolumes", None, UI.refreshVolumes) server.add_method("/shutdown", None, shutdown) server.add_method(None, None, unknownOSC) while listenToOSC : server.recv(100)
def run(self): if self.raw: print("Start Raw listener " + self.raw_ip + ":" + str(self.port)) sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((self.raw_ip, self.port)) UDP_BUFFER_SIZE = 4096 while True: data, addr = sock.recvfrom(UDP_BUFFER_SIZE) # blocking call self.data_handler(data) elif self.osc: try: self.osc_server = liblo.Server(self.port) except liblo.ServerError, err: print str(err) sys.exit() controller.register_osc_callbacks() # loop and dispatch messages every 100ms while True: self.osc_server.recv(100)
def is_lamp_running(): try: s = liblo.Server(LAMPPORT) except liblo.ServerError: return True return False
def is_cs_running(): try: s = liblo.Server(CSPORT) except liblo.ServerError: return True return False
def fallback(path, args, types, src): print("got unknown message '%s' from '%s'" % (path, src.url)) for a, t in zip(args, types): print("argument of type '%s': %s" % (t, a)) def serve_forever(tms=100): while True: server.recv(tms) try: target = liblo.Address(port_remote) server = liblo.Server(port_local) except liblo.AddressError as err: print(err) sys.exit() server.add_method("/bankview", 'iss', cb_bankview) server.add_method("/loadbank", 'i', cb_loadbank) server.add_method("/volume", 'i', cb_volume) # register method taking an int and a float #server.add_method("/foo/bar", 'if', foo_bar_callback) # register method taking a blob, and passing user data to the callback #server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") # register a fallback for unhandled messages
#!/usr/bin/env python from __future__ import print_function import liblo, sys # create server, listening on port 1234 try: server = liblo.Server(1234) except liblo.ServerError as err: print(err) sys.exit() def foo_bar_callback(path, args): i, f = args print("/foo/bar: received message '%s' with arguments '%d' and '%f'" % (path, i, f)) def foo_baz_callback(path, args, types, src, data): print("/foo/baz: received message '%s'" % path) print("blob contains %d bytes, user data was '%s'" % (len(args[0]), data)) def fallback(path, args, types, src): print("got unknown message '%s' from '%s'" % (path, src.url)) for a, t in zip(args, types): print("argument of type '%s': %s" % (t, a)) # register method taking an int and a float server.add_method("/foo/bar", 'if', foo_bar_callback) # register method taking a blob, and passing user data to the callback server.add_method("/foo/baz", 'b', foo_baz_callback, "blah")
import liblo, sys import time # client try: target = liblo.Address(4001) except liblo.AddressError, err: print str(err) sys.exit() # create server try: server = liblo.Server(4000) except liblo.ServerError, err: print str(err) sys.exit() def blob_callback(path, args): # unpack notes notes = [0] * 128 midi_blob = args[0] for i in range(0, 16): for j in range(0, 8): if midi_blob[i] & (1 << j): notes[(i * 8) + j] = 1 else: notes[(i * 8) + j] = 0 # print str(midi_blob) line = '' for i in range(0, 128):