def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ osc.init() ## osc.createListener() # this defaults to port 9001 as well osc.listen('127.0.0.1', 9001) # bind addresses to functions -> printStuff() function will be triggered everytime a # "/test" labeled message arrives osc.bind(printStuff, "/test") import time # in this example we will have a small delay in the while loop print 'ready to receive and send osc messages ...' while 1: ## osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port osc.sendMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = osc.createBundle() osc.appendToBundle(bundle, "/test/bndlprt1", [1, 2, 3]) # 1st message appent to bundle osc.appendToBundle(bundle, "/test/bndlprt2", [4, 5, 6]) # 2nd message appent to bundle ## osc.sendBundle(bundle, "127.0.0.1", 9000) # send it to a specific ip and port osc.sendBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 #osc.getOSC(inSocket) # listen to incomming OSC in this socket time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible. osc.dontListen() # finally close the connection bfore exiting or program
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ osc.init() ## osc.createListener() # this defaults to port 9001 as well osc.listen('127.0.0.1', 40001) # bind addresses to functions -> printStuff() function will be triggered everytime a # "/test" labeled message arrives osc.bind(update, "/tuio/Get") import time # in this example we will have a small delay in the while loop print ' ready to receive and send osc messages ... FROM SERVER', 40001 while 1: #osc.sendMsg("/test", [], "127.0.0.1", 4001) # send normal msg to a specific ip and port time.sleep( 0.5 ) # you don't need this, but otherwise we're sending as fast as possible. osc.dontListen() # finally close the connection bfore exiting or program
def myTest(): osc.init() osc.listen('192.168.11.15', 8000) #local IP; listen on port 8000 osc.bind(recvMsg, "/echo") # enable reporting of all adc channels osc.sendMsg("/echo", [0], '192.168.11.200', 8888) # Arduino's IP and Port while 1: time.sleep(0.1)
def myTest(): osc.init() osc.listen('192.168.11.15', 8000) #local IP; listen on port 8000 osc.bind(recvMsg,"/echo") # enable reporting of all adc channels osc.sendMsg("/echo",[0],'192.168.11.200',8888) # Arduino's IP and Port while 1: time.sleep(0.1)
def main(): osc.init() osc.listen("127.0.0.1",9001) osc.bind(heartBeat, "/beat") while(1): global last_beat time_diff = (time.clock() - last_beat) print time_diff; time.sleep(0.1);
def listen(self, prefix = "/global", port = 9900): if not PStaticGlobal.listening: import osc osc.init() osc.listen(port = port) PStaticGlobal.listening = True self.prefix = prefix osc.bind(self.recv, prefix)
def __init__(self, default = 0, address = "/value", port = 9900): if not PStaticViaOSC.initialised: import osc osc.init() osc.listen(port = port) self.value = default self.address = address osc.bind(self.recv, address)
def __init__(self): osc.init() osc.listen('localhost', 9001) osc.listen('10.211.55.2', 9001) self._threads = [] self._threads.append(g_drinkControlThread) self._threads.append(g_ambxThread) self._threads.append(g_tranceVibratorThread) [thread.start() for thread in self._threads]
def __init__(self, default=0, address="/value", port=9900): if not PStaticViaOSC.initialised: import osc osc.init() osc.listen(port=port) self.value = default self.address = address osc.bind(self.recv, address)
def __init__(self, host, port): self.client = {} self.host = host self.port = port osc.init() ## osc.createListener() # this defaults to port 9001 as well osc.listen(self.host, self.port) # bind addresses to functions -> printStuff() function will be triggered everytime a # "/test" labeled message arrives osc.bind(self.update, "/tuio/Set") osc.bind(self.sendClients, "/tuio/Get") osc.bind(self.send, "/tuio/msg")
def start(self): '''Start the tuio provider''' osc.init() self.oscid = osc.listen(self.ip, self.port) for oscpath in TuioTouchProvider.__handlers__: self.touches[oscpath] = {} osc.bind(self._osc_tuio_cb, oscpath)
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ osc.init() osc.listen('127.0.0.1', 10001) osc.bind(printStuff, "/generickey") osc.bind(printStuff, "/key1") osc.bind(printStuff, "/key2") osc.bind(printStuff, "/key3") inSocket = osc.createListener("127.0.0.1", 9000) import time while 1: osc.getOSC(inSocket) osc.dontListen()
def init_osc(self): osc.init() self.oscid = osc.listen(ipAddr='127.0.0.1', port=self.receive_port) osc.bind(self.oscid, self.receive_osc_message, b'/stdout') osc.bind(self.oscid, self.receive_osc_message, b'/stderr') osc.bind(self.oscid, self.receive_osc_message, b'/interpreter') osc.bind(self.oscid, self.receive_osc_message, b'/pong') osc.bind(self.oscid, self.receive_osc_message, b'/requestinput')
def start(self): '''Start the tuio provider''' self.oscid = osc.listen(self.ip, self.port) osc.bind(self.oscid, self._osc_tuio_cb, '') self.touches[''] = {} for oscpath in TuioListener.__handlers__: self.touches[oscpath] = {} osc.bind(self.oscid, self._osc_tuio_cb, oscpath)
def __init__(self, ip='127.0.0.1', port=3333): osc.init() osc.listen(ip, port) osc.bind(self.osc_2dcur_Callback, "/tuio/2Dcur") osc.bind(self.osc_2dobj_Callback, "/tuio/2Dobj")
def main(): global mainObj global sendIP global sendPort configFile = open('OSCadr.cfg', 'r') for line in configFile: line = line.split() if line[0] == "sendPort": sendPort = int(line[1]) if line[0] == "sendIP": sendIP = line[1] if line[0] == "listenIP": listenIP = line[1] if line[0] == "listenPort": listenPort = int(line[1]) pygame.init() osc.init() osc.listen(listenIP, listenPort) mainObj = Globject() clock = pygame.time.Clock() osc.bind(mainObj.curve.editCurve, '/curve/gui_curve/edit') osc.bind(mainObj.curve.editMidi, '/curve/midi_params') osc.bind(mainObj.curve.editLengths, '/curve/curve_lengths') osc.bind(mainObj.curve.editPlayStates, '/curve/play_states') osc.bind(mainObj.grid16.editGrid, '/grid16/pattern_grid/edit') osc.bind(mainObj.grid16.editMidi, '/grid16/midi_params') osc.bind(mainObj.grid16.editPatternSeqLength, '/grid16/pattern_seq/length') osc.bind(mainObj.grid16.editPatternSeq, '/grid16/pattern_seq') osc.bind(mainObj.grid32.editGrid, '/grid32/pattern_grid/edit') osc.bind(mainObj.grid32.editMidi, '/grid32/midi_params') osc.bind(mainObj.grid32.editPatternSeqLength, '/grid32/pattern_seq/length') osc.bind(mainObj.grid32.editPatternSeq, '/grid32/pattern_seq') osc.bind(mainObj.menu.trackInfo, '/main/track_info') osc.bind(mainObj.menu.seqStepNumber, '/main/stepnumber') loop = True while loop: clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: loop = False if event.type == pygame.MOUSEBUTTONUP: mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('up', mousePosition) if event.type == pygame.MOUSEBUTTONDOWN: mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('down', mousePosition) if event.type == pygame.MOUSEMOTION: mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('drag', mousePosition) mainObj.drawStuff() osc.dontListen() pygame.quit() sys.exit()
print('got this far') to = os.environ.get('PYTHON_SERVICE_ARGUMENT', '') for entry in to.split(':'): if entry.startswith('throttle_output='): throttle_output = False if entry[16:] == '0' else True if entry.startswith('use_thread='): use_thread = False if entry[11:] == '0' else True if entry.startswith('send_port='): send_port = int(entry.split('=')[-1]) if entry.startswith('receive_port='): receive_port = int(entry.split('=')[-1]) osc.init() oscid = osc.listen(ipAddr='127.0.0.1', port=receive_port) osc.bind(oscid, receive_message, b'/interpret') osc.bind(oscid, receive_message, b'/ping') osc.bind(oscid, receive_message, b'/sigint') osc.bind(oscid, receive_message, b'/throttling') osc.bind(oscid, receive_message, b'/userinput') osc.bind(oscid, receive_message, b'/execfile') sys.stdout = OscOut(b'/stdout', send_port) sys.stderr = OscOut(b'/stderr', send_port) real_print('got this far4') while True: osc.readQueue(oscid) time.sleep(.1)
def shoot_end_handler(*msg): # ipAddress, x, y try: ipAddress = msg[0][2] x = msg[0][3] y = msg[0][4] global current_state current_state.shoot_end_handler(ipAddress, x, y) except Exception, e: print e def add_player(ipAddress): players[ipAddress] = Player(ipAddress, random.randint(0, 639), random.randint(0, 479), 0, 0) def player_exists(ipAddress): return players.has_key(ipAddress) if __name__ == "__main__": setup() osc.init() osc.listen('127.0.0.1', 9002) osc.bind(move_start_handler, '/movestart') osc.bind(move_end_handler, '/moveend') osc.bind(shoot_start_handler, '/shootstart') osc.bind(shoot_end_handler, '/shootend') pyglet.clock.schedule(update) current_state.enter() pyglet.app.run()
def main(): osc.init() osc.listen("127.0.0.1",9001) osc.bind(heartBeat, "/beat")
def ping(*args): osc.sendMsg( '/message', [''.join(sample(ascii_letters, randint(10, 20))), ], port=3002) def printy(mesg, *args): print(mesg) osc.sendMsg( '/message', [mesg[2], ], port=3002) def send_date(): osc.sendMsg('/date', [asctime(localtime()), ], port=3002) if __name__ == '__main__': osc.init() oscid = osc.listen(ipAddr='0.0.0.0', port=3000) osc.bind(oscid, ping, '/ping') osc.bind(oscid, printy, '/printy') while True: osc.readQueue(oscid) send_date() sleep(.1)
def start(self): '''Start the tuio provider''' self.oscid = osc.listen(self.ip, self.port) for oscpath in TuioMotionEventProvider.__handlers__: self.touches[oscpath] = {} osc.bind(self.oscid, self._osc_tuio_cb, oscpath)
self.box_loop.get_text(), [self.box_command2.get_active_text()]) def callback_stop(self): """The callback for "stop"-button.""" self.stop_() self.box_start.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#6B8E23")) def callback_start(self): """This feature responds to the volume control.""" self.start_() self.box_start.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("orange")) def callback_quit(self): """The callback for "quit"-button.""" self.quit_() gtk.main_quit() if __name__ == "__main__": win = MainWin() if DEBUG: osc.init() try: osc.listen("%s" % win.box_ip.get_text(), int(win.box_port.get_text())) except AttributeError, e: ErrorHandler(e) sys.stderr.write("Maybe the port is already taken by another process?\n") sys.stderr.write("SooperLooper is activ?") gtk.gdk.threads_init() gtk.main()
def python_fu_receiveosc( inImage, inDrawable, netAddr="127.0.0.1", port=57130): global receiving,newSpecs,pic inImage.disable_undo() gimp.progress_init("receiving...") receiving = 1 startingTime = time.time() # get right port for sc if shelf.has_key('oscnetaddr'): sendAddr = shelf['oscnetaddr'][0] else: sendAddr = "127.0.0.1" if shelf.has_key('oscport'): sendPort = shelf['oscport'][0] else: sendPort = 57120 ## init osc listeners osc.init() osc.listen(netAddr, port) osc.bind(python_fu_receiveosc_storeSpecs, "/gimp/spec") osc.bind(python_fu_receiveosc_receiveImage, "/gimp/pic") osc.bind(python_fu_receiveosc_displayImage, "/gimp/end") ## ping sc to send image osc.sendMsg("/gimp/ping", [-1], sendAddr, sendPort) ## loop until done while receiving: #print("ping", len(pic)) if receiving == 3: time.sleep(1) gimp.progress_update(96) newPic = [] newLayer = gimp.Layer(inImage, "fromOSC", newSpecs[0], newSpecs[1], RGB_IMAGE, 100, NORMAL_MODE) inImage.add_layer(newLayer, 0) pdb.gimp_edit_fill(newLayer, BACKGROUND_FILL) newPic = newLayer.get_pixel_rgn(0,0, newSpecs[0],newSpecs[1], True) #newPic = pic print(len(pic)) ## remove all brightness values ## convert from int to chr-values ## if newSpecs[2] == 4: ## for index in range(len(pic)): ## if index%4 == 3: ## pic[index] = 255 ## elif index == 0: ## picAsStr = chr(pic[index]) ## else: ## picAsStr = picAsStr + chr(pic[index]) ## set the pixel region to pic #print(pic) newPic[0:newSpecs[0],0:newSpecs[1]] = pic newLayer.flush() newLayer.update(0,0,newSpecs[0],newSpecs[1]) print("flushed & updated") receiving = 0 elif time.time() - startingTime > 20: print("time's up") receiving = 0 else: gimp.progress_update(int(18 * (time.time() - startingTime))) #time.sleep(0.2) osc.dontListen() inImage.enable_undo() gimp.displays_flush() gimp.extension_ack()
def main(): global mainObj global sendIP global sendPort configFile = open('OSCadr.cfg', 'r') for line in configFile: line = line.split() if line[0] == "sendPort": sendPort = int(line[1]) if line[0] == "sendIP": sendIP = line[1] if line[0] == "listenIP": listenIP = line[1] if line[0] == "listenPort": listenPort = int(line[1]) pygame.init() osc.init() osc.listen(listenIP, listenPort) mainObj = Globject() clock = pygame.time.Clock() osc.bind(mainObj.curve.editCurve, '/curve/gui_curve/edit') osc.bind(mainObj.curve.editMidi, '/curve/midi_params') osc.bind(mainObj.curve.editLengths, '/curve/curve_lengths') osc.bind(mainObj.curve.editPlayStates, '/curve/play_states') osc.bind(mainObj.grid16.editGrid, '/grid16/pattern_grid/edit') osc.bind(mainObj.grid16.editMidi, '/grid16/midi_params') osc.bind(mainObj.grid16.editPatternSeqLength, '/grid16/pattern_seq/length') osc.bind(mainObj.grid16.editPatternSeq, '/grid16/pattern_seq') osc.bind(mainObj.grid32.editGrid, '/grid32/pattern_grid/edit') osc.bind(mainObj.grid32.editMidi, '/grid32/midi_params') osc.bind(mainObj.grid32.editPatternSeqLength, '/grid32/pattern_seq/length') osc.bind(mainObj.grid32.editPatternSeq, '/grid32/pattern_seq') osc.bind(mainObj.menu.trackInfo, '/main/track_info') osc.bind(mainObj.menu.seqStepNumber, '/main/stepnumber') loop = True while loop: clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: loop = False if event.type == pygame.MOUSEBUTTONUP : mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('up',mousePosition) if event.type == pygame.MOUSEBUTTONDOWN : mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('down',mousePosition) if event.type == pygame.MOUSEMOTION : mousePosition = pygame.mouse.get_pos() mainObj.modeObject.mouseInput('drag',mousePosition) mainObj.drawStuff() osc.dontListen() pygame.quit() sys.exit()
def main(host='0.0.0.0', port=8000, address='/update'): oscid = listen(host, port) bind(oscid, dump_data, address) while True: readQueue(oscid)
def __init__(self): osc.init() oscid = osc.listen(ipAddr="0.0.0.0", port=3000) # Receive start/stop message osc.bind(oscid, self.startquit, "/start") self.can_start = False # Cycle info? osc.bind(oscid, self.send_hello, "/hello") # Send status of simulation osc.bind(oscid, self.simulation_status_send, "/simu-status_ask") # Receive simulation speed osc.bind(oscid, self.simuspeed, "/simu-speed") # Init actual model self.sim = Simulation() self.sim_speed = 1 self.cycle = 0 self.max_cycles = self.sim.model.parameters.get("max_cycles") print("Max cycles: {}".format(self.max_cycles)) # Make statistics instance # Only for testing writing to CSV self.statistics = Statistics() # Send server is running self.simulation_status_send() # Code always running / waiting for instructions while True: # Try so that a server stopped message can be send try: if self.cycle % 1000 == 0 or self.cycle == 0: print("Current cycle: {}".format(self.cycle)) osc.readQueue(oscid) # Only run simulation when started and max cycles not reached # print("Start: {}, Max Cycles: {}".format(self.can_start, self.max_cycles)) if self.can_start == True and self.cycle < self.max_cycles: # Reset model if self.cycle == 0: print("\nNew simulation detected!!!\n") print("\nReset model") self.sim.model.reset() self.statistics.driver_update(self.sim.model.drivers) # print("\nCSV filename function") self.statistics.create_csv(self.sim.model.parameters.param) # Make statistics instance # print "LIST PRINTED in LOOP\n" # Agent stuff self.sim.run() # Send agent positions self.positions() # Statistics stuff self.do_statistics() # Hello world test self.cycle += 1 self.send_hello() sleep(self.sim_speed) # Send message server stopped except: traceback.print_exc() # Please tell me what is wrong then... self.send_server_stop() exit()
finger = msg[0][3] if not finger in fingers: fingers[finger] = [0,0] # msg[0][4] should be X, but seems to be Y. why? fingers[finger][X] = msg[0][4] # msg[0]5] should be Y, but seems to be X. why ? and flipped!?!?!? fingers[finger][Y] = msg[0][5] # print 'set', finger, fingers[finger] elif msg[0][2] == 'alive': # go through fingerState and mark the living fingers livingFingers = msg[0][3:] # print 'alive', livingFingers osc.init() #osc.listen('192.168.1.7',9001) osc.listen('127.0.0.1', 3333) osc.bind ( tuioCursorHandler, "/tuio/2Dcur" ) ########################################### # game objects # class Bullet: def __init__(self, pos=(0,0), vel=(0,0)): x,y = pos self.position = numpy.array([float(x),float(y)]) x,y = vel self.velocity = numpy.array([float(x),float(y)]) def update(self): global targets
try: ipAddress = msg[0][2] x = msg[0][3] y = msg[0][4] global current_state current_state.shoot_end_handler(ipAddress, x, y) except Exception, e: print e def add_player(ipAddress): players[ipAddress] = Player(ipAddress, random.randint(0, 639), random.randint(0, 479), 0, 0) def player_exists(ipAddress): return players.has_key(ipAddress) if __name__ == "__main__": setup() osc.init() osc.listen('127.0.0.1', 9002) osc.bind(move_start_handler, '/movestart') osc.bind(move_end_handler, '/moveend') osc.bind(shoot_start_handler, '/shootstart') osc.bind(shoot_end_handler, '/shootend') pyglet.clock.schedule(update) current_state.enter() pyglet.app.run()