Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. from time import sleep
  2. import os
  3. import osc4py3
  4.  
  5. from osc4py3.as_comthreads import *
  6. from osc4py3 import oscmethod as osm
  7.  
  8. from queue import Queue
  9.  
  10. import time
  11.  
  12. q = Queue()
  13. recv = {}
  14. to_print= {}
  15. port = 6565
  16. last_sample = 0
  17. sample_delay = 0.1
  18.  
  19. clear_cmd = "clear"
  20. try:
  21.     os.system(clear_cmd)
  22. except Exception as e:
  23.     clear_cmd = "cls"
  24.  
  25. try:
  26.     os.system(clear_cmd)
  27. except Exception as e:
  28.     print("Can't run the program, we don't know how to clear the console on your system")
  29.     quit()
  30.  
  31.  
  32. def handlerfunction(address, args):
  33.     global recv
  34.     global last_sample, sample_delay
  35.     t = time.time()
  36.  
  37.     sample_delay = t - last_sample
  38.     last_sample = t
  39.  
  40.     if address not in recv.keys():
  41.         recv[address] = time.time()
  42.         return
  43.  
  44.     to_print[address] = t - recv[address]
  45.     recv[address] = t
  46.     # print(recv[address])  
  47.  
  48. osc_startup()
  49. osc_udp_server("0.0.0.0", 6565, "anotherserver")
  50. osc_method("//", handlerfunction, argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATA)
  51.  
  52.  
  53. def display_title_bar():
  54.     os.system('clear')
  55.     print("*"*56)
  56.     print(" Test notochord send rate | listening at port {:6d}".format(port))
  57.     print("*"*56)
  58.     bigger_recv_delta = 0.1
  59.     for delta in to_print.values():
  60.         bigger_recv_delta =  max(bigger_recv_delta, delta)
  61.  
  62.     acc = 100
  63.     try:
  64.         acc = 100 / (bigger_recv_delta / sample_delay)
  65.     except Exception as e:
  66.         pass    
  67.  
  68.     print(" Sample rate = {:4d}ms  |   Sampling accuracy = {:2.1f}%".format(
  69.                                     int(sample_delay*1000), 100-acc ))
  70.     print("-"*56)
  71.  
  72.     count = 1
  73.     for ms, t in to_print.items():
  74.         print("{:2d}] {:_<26} > {:5.0f}ms  |  {:2.1f}Hz".format(count, ms, t*1000, 1/t ))
  75.         count +=1
  76.  
  77.  
  78. while 1:
  79.     display_title_bar()
  80.     for i in range(500):
  81.         osc_process()
  82.         sleep(0.001)
  83.  
  84. osc_terminate()