def run(): # SETUP # resetCanvas() import time out.FADERATE = 8 # fade rate, currently broken? out.start() # OSC SERVER/HANDLERS # initOSCServer(ip, port) # setup OSC server setOSCHandler('/reset', reset) # resets the visualization setOSCHandler('/asteroid', orb) # when an orb moves on the screen setOSCHandler('/set_max_brightness', setMax) setOSCHandler('/set_min_brightness', setMin) # SERVER START # startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) # SERVER LOOP# try: clock = 1 while (1): out.write(canvas) # write to canvas time.sleep(0.1) # tick every 0.1 seconds if ((clock % 1000) == 0): # every 1000 ticks plasmaCanvas() clock = (clock + 1) % 10000 # increment clock, reseting every 10000 ticks except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ import time # in this example we will have a small delay in the while loop initOSCClient() # takes args : ip, port initOSCServer() # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server # bind addresses to functions setOSCHandler('/check', checkcheckcheck) startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...' try: while 1: sendOSCMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = createOSCBundle("/test/bndlprt1") bundle.append(666) # 1st message appent to bundle bundle.append("the number of the beast") # 2nd message appent to bundle sendOSCBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible. except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def app(): # Init Dynamixel connection global dxlIO, foundIds ports = pypot.dynamixel.get_available_ports() if not ports: raise IOError('No port available.') port = ports[0] dxlIO = pypot.dynamixel.DxlIO(port) print 'Connected' # Setup motors dxlIO.enable_torque([leftWheelMotorId, rightWheelMotorId, dremelMotorId]) dxlIO.set_moving_speed({dremelMotorId: dremelJointSpeedMin}) # Init OSC server simpleOSC.initOSCServer(receiveAddress, receivePort) simpleOSC.setOSCHandler('/wheelspeed', wheelSpeedHandler) simpleOSC.setOSCHandler('/wheelslowdown', wheelSlowdownHandler) simpleOSC.setOSCHandler('/dremeljointpos', dremelJointPosHandler) simpleOSC.setOSCHandler('/dremeljointspeed', dremelJointSpeedHandler) simpleOSC.startOSCServer() # Enter infinite loop to be able to catch KeyboardInterrupt try: while True: time.sleep(0) except KeyboardInterrupt: simpleOSC.closeOSC()
def run_server(self): # OSC SERVER/HANDLERS # initOSCServer(self.ip, self.rport) # setup OSC server setOSCHandler('/shape', shape_handler) setOSCHandler('/boundary', boundary_handler) setOSCHandler('/contact', contact_handler) setOSCHandler('/hand', hand_handler) setOSCHandler('/finger', finger_handler) setOSCHandler('/background', background_handler) setOSCHandler('/bgrgb/red', bgred_handler) setOSCHandler('/bgrgb/green', bggreen_handler) setOSCHandler('/bgrgb/blue',bgblue_handler) # SERVER START # startOSCServer() print "server is running, listening at " + str(self.ip) + ":" + str(self.rport) print "use Ctrl-C to quit." # SERVER LOOP # try: clock = 1 while(1): time.sleep(5) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ import time # in this example we will have a small delay in the while loop # initOSCClient() # takes args : ip, port # initOSCServer() # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server # bind addresses to functions # setOSCHandler('/check', checkcheckcheck) # startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...' try: while 1: simpleTest() # sendOSCMsg("/test", [1234]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # sendOSCMsg("/rpm", [1234]) # create and send a bundle # bundle = createOSCBundle("/test/bndlprt1") # bundle.append(666) # 1st message appent to bundle # bundle.append("the number of the beast") # 2nd message appent to bundle # sendOSCBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible. except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def run(): # SETUP # resetCanvas() import time out.FADERATE = 8 # fade rate, currently broken? out.start() # OSC SERVER/HANDLERS # initOSCServer(ip, port) # setup OSC server setOSCHandler('/reset', reset) # resets the visualization setOSCHandler('/asteroid', orb) # when an orb moves on the screen setOSCHandler('/set_max_brightness', setMax) setOSCHandler('/set_min_brightness', setMin) # SERVER START # startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) # SERVER LOOP# try: clock = 1 while(1): out.write(canvas) # write to canvas time.sleep(0.1) # tick every 0.1 seconds if ((clock%1000) == 0): # every 1000 ticks plasmaCanvas() clock = (clock+1)%10000 # increment clock, reseting every 10000 ticks except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def run(self): prev_t = time.time() count = 0 t0 = time.time() try: while True: curr_t = time.time() if count < self.nsamples: m_x = self.x[count] m_y = self.y[count] else: print(Exception('Finished sending samples for ' + self.name )) break # rand = np.random.rand(1) # if rand > 0.7: # m_x = np.nan # m_y = np.nan # print m_x, m_y count += 1 msg = [m_x, m_y, self.width, self.height] self.sent_trajectory.append([m_x, m_y, self.width, self.height]) self.timestamps.append(curr_t - t0) sendOSCMsg(self.addr, msg) time.sleep(self.period) t1 = time.time() print('finished in ', t1 - t0) except KeyboardInterrupt: closeOSC() # finally close the connection before exiting or program pass
def loop(): """ sends pending commands to robot, listens for reply, relays reply to OSC """ global haveClient, messageToRobot, busy, sentAddr, sentData try: while True: if haveClient and messageToRobot != 0: if sentAddr == "/initialize": initializeRobot() # blocks elif sentAddr == "/calibrate": calibrateRobot() # blocks else: sendCommand() if getReply() == True: # blocks sendOSCMsg(sentAddr, [sentData, "DONE"]) else: sendOSCMsg(sentAddr, [sentData, "ABORTED"]) busy = False messageToRobot = 0 sentAddr = 0 sentData = 0 except KeyboardInterrupt: print "closing all connections and exiting..." closeOSC()
def poll(self): """ Polls the program """ try: while True: time.sleep(1000) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def run(): try: initOSCServer(ip, port) setOSCHandler('/collision', col) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) except KeyboardInterrupt: closeOSC()
def main(): initOSCClient('127.0.0.1', 9001) sendOSCMsg("/start") fname = sys.argv[1] f = open(fname, "rt") text = f.read() root = Tkinter.Tk() # have to initialize the sound system, required!! tkSnack.initializeSnack(root) # set the volume of the sound system (0 to 100%) tg.setVolume(100) tg.translateNote('A4') notes = text.split() d = build_dict(notes) sent = generate_music(d) j = 0 for i in sent: # Nota mais grave vai pro cello i = tg.translateNote(i) # Sua terça vai pro violino 1 j = i*(4/5) # Sua quinta vai pra viola k = j*(3/2) # E sua oitava pro violino 2 l = i*2 sendOSCMsg("/cello", [i]) sendOSCMsg("/viola", [j]) sendOSCMsg("/violin1", [k]) sendOSCMsg("/violin2", [l]) time.sleep(0.5) # tg.soundStop() sendOSCMsg("/cello", [0]) sendOSCMsg("/viola", [0]) sendOSCMsg("/violin1", [0]) sendOSCMsg("/violin2", [0]) sendOSCMsg("/stop") closeOSC() root.withdraw()
def main(): initOSCClient('127.0.0.1', 9001) sendOSCMsg("/start") fname = sys.argv[1] f = open(fname, "rt") text = f.read() root = Tkinter.Tk() # have to initialize the sound system, required!! tkSnack.initializeSnack(root) # set the volume of the sound system (0 to 100%) tg.setVolume(100) tg.translateNote('A4') notes = text.split() d = build_dict(notes) sent = generate_music(d) j = 0 for i in sent: # Nota mais grave vai pro cello i = tg.translateNote(i) # Sua terça vai pro violino 1 j = i * (4 / 5) # Sua quinta vai pra viola k = j * (3 / 2) # E sua oitava pro violino 2 l = i * 2 sendOSCMsg("/cello", [i]) sendOSCMsg("/viola", [j]) sendOSCMsg("/violin1", [k]) sendOSCMsg("/violin2", [l]) time.sleep(0.5) # tg.soundStop() sendOSCMsg("/cello", [0]) sendOSCMsg("/viola", [0]) sendOSCMsg("/violin1", [0]) sendOSCMsg("/violin2", [0]) sendOSCMsg("/stop") closeOSC() root.withdraw()
def run(): try: initOSCClient(ip, client_port) # initOSCClient(ip, client_port) initOSCServer(ip, server_boids_port) setOSCHandler('/collision', col) startOSCServer() initOSCServer(ip, server_sound_port) setOSCHandler('/request', request) startOSCServer() except KeyboardInterrupt: closeOSC()
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ import time # in this example we will have a small delay in the while loop initOSCClient("37.34.68.87", 3333) # takes args : ip, port try: while 1: for i in xrange(100): sendOSCMsg("/score", ["%.2f" % (i / 100.0)]) time.sleep(0.01) except KeyboardInterrupt: closeOSC() # finally close the connection before exiting or program.
def myTest(): initOSCClient("192.168.0.2", 9000) # takes args : ip, port initOSCServer( "192.168.0.7", 9001, 0) # takes args : ip, port, mode => 0 basic, 1 threading, 2 forking setOSCHandler('/test', test) startOSCServer() print 'ready to receive and send osc messages...' try: while 1: sendOSCMsg("/sup", [444, 4.4, 'yomama is a baby']) time.sleep(1) except KeyboardInterrupt: print "closing all OSC connections and exiting" closeOSC()
def stuff(): import time a = [] a.len initOSCServer(ip, port) setOSCHandler('/collision', collision) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) try: while(1): time.sleep(1000) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def run_server(self): # OSC SERVER/HANDLERS # initOSCServer(self.ip, self.rport) # setup OSC server setOSCHandler('/async/hue', hue_handler) # SERVER START # startOSCServer() print "server is running, listening at " + str(self.ip) + ":" + str(self.rport) print "use Ctrl-C to quit." # SERVER LOOP # try: clock = 1 while(1): time.sleep(5) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def samplesocketstream(request): import subprocess import ast import time # use URL string VARS: http://stackoverflow.com/questions/150505/capturing-url-parameters-in-request-get # http://stackoverflow.com/questions/6164540/getting-two-strings-in-variable-from-url-in-django # https://docs.python.org/2/library/re.html # http://www.djangobook.com/en/2.0/chapter07.html if request.method == 'GET': # C:\Users\DusX\CODE\python\TCPIP_bridge\bridgeApp\ p = subprocess.Popen(["python", "-u", settings.DX_SOCKETSTREAMFILE], stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1) startT = time.clock() print("launched: " + p.stdout.readline()), # read the first line # prepar OSC server while Popen launching and processing initOSCClient( '127.0.0.1', 1234 ) # takes args : ip, port initOSCClient(ip='127.0.0.1', port=9000) hold = True # setup for loop data = False # setup for loop while hold: # repeat several times to show that it works currentT = time.clock() strOSC = "processing: " + str(currentT - startT) sendOSCMsg("/RPM", [strOSC]) # send text OSC if ( currentT - startT ) >= 70: #if it takes more than a minute+ we should timeout. time should relate to Izzy # TODO: should relaunch after killing process p.terminate() return HttpResponse( "Socket TIMEOUT" ) # untested for how Izzy handles this response data = p.stdout.readline() # read output print("Line" + ": " + data) try: data = ast.literal_eval(data) print("data=: " + str(type(data))) if type(data) is list: print("data match found.") data = data[0] hold = False except: # add timeout code, incase data = False pass # print p.communicate("n\n")[0], # signal the child to exit, # print ("FINAL" + str(p.communicate()[0])) # signal the child to exit, # read the rest of the output, # wait for the child to exit if data: if p: p.terminate() print("process terminated") # SEND OSC sendOSCMsg( "/RPM", [data] ) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 closeOSC() # return HttpResponse("RPM = " + str(data) + "\n") # requests per minute return JsonResponse({'RPM': data}) if request.method == 'POST': return HttpResponse("POST")
control.set_head(data[0]) def set_displacement(addr, tags, data, source): global control control.displace(data[0]) def playback_displaced(addr, tags, data, source): global control d = control.get_data_displaced() sendOSCMsg("/ga", d) setOSCHandler('/kinect', receive_kinect_data) setOSCHandler('/ping', ping) setOSCHandler('/playback', playback_data_point) setOSCHandler('/set_head', set_head) setOSCHandler('/displace', set_displacement) setOSCHandler('/playback_displace', playback_displaced) startOSCServer() try: n = 0 while 1: n = n + 1 print "Server is alive! Message # ", n time.sleep(1) except: print "Closing OSC server" closeOSC() file_handler.close()
def on_stop(self): closeOSC()
def do_connect(self): config = self.config host = config.get('network', 'host') sport = config.getint('monome', 'send_port') rport = config.getint('monome', 'receive_port') mdevice = config.getint('midi', 'device') # osc initOSCClient(host, sport) initOSCServer(host, rport) # midi #pygame.midi.init() #pygame.midi.get_count() #self.midi_out = pygame.midi.Output(device_id=mdevice) #self.device_name = pygame.midi.get_device_info(mdevice) # switch to main screen parent = self.root.parent parent.remove_widget(self.root) self.root = BrokerControlMain(app=self) parent.add_widget(self.root) if __name__ in ('__main__', '__android__'): try: Config.set('graphics', 'width', '320') Config.set('graphics', 'height', '240') BrokerControlApp().run() finally: closeOSC()
def end(addr, tags, data, source): closeOSC() print "Bye" sys.exit()
def shutdown(pl): input("Press any key to close OSC server") closeOSC() pl.terminate()