def start_server_in_separate_thread(): global server_thread, server_ip, server_port, server our_dispatcher = dispatcher.Dispatcher() our_dispatcher.map("/tick", handle_tick) # add other dispatcher hooks here server = osc_server.ForkingOSCUDPServer((server_ip, server_port), our_dispatcher) server_thread = threading.Thread(target=server.serve_forever) server_thread.start()
"""Small example OSC server This program listens to several addresses, and prints some information about received packets. """ import threading from pythonosc import dispatcher from pythonosc import osc_server from pythonosc import osc_message_builder from pythonosc import udp_client if __name__ == "__main__": dispatcher = dispatcher.Dispatcher() dispatcher.map("/hello", print) server = osc_server.ForkingOSCUDPServer(("127.0.0.1", 7771), dispatcher) server_thread = threading.Thread(target=server.serve_forever) server_thread.start() #Send a message client = udp_client.SimpleUDPClient("127.0.0.1", 7772) for x in range(10): client.send_message("/test", "blah") # server = osc_server.ThreadingOSCUDPServer( # ("127.0.0.1", 7771), dispatcher) # print("Serving on {}".format(server.server_address)) #server.serve_forever()
print('Sending: ', "/recommendations", ' : ', choice) client.send_message("/recommendations", choice) # faked_choice = json.loads('["cinematicscore130BPM/Cinematic-DrumPart-001.wav", "futuredubstep140BPM/FutureDub-BassWobble-140BPM-038.wav", "ukhouse120BPM/UKHouse-SoloDrumPart-019.wav", "Techno125BPM/TSFX/TechnoWhiteNoiseSFX-008.wav", "HipHop98BPM/HHTrapBeatPart/HipHopTrapBeatPart-011.wav", "edm120BPM/EDM-RaveLead-006.wav", "ukhouse120BPM/UKHouse-MainBeat-026.wav", "pop80bpm2/crash.wav", "edm120BPM/EDM-RaveLead-002.wav", "newfunk115bpm/synth-bass2.wav"]') # print('Sending: ', "/recommendations", ' : ', faked_choice) # client.send_message("/recommendations", faked_choice) print('Sending: ', "/selectedsamples", ' : ', sampleNames) client.send_message("/selectedsamples", sampleNames) sampleNames = [] client = udp_client.SimpleUDPClient(remoteIPAddress, remotePort) dispatcher = dispatcher.Dispatcher() server = osc_server.ForkingOSCUDPServer((localIPAddress, localPort), dispatcher) def add_sample(unused_addr, args): print('Received: ', unused_addr, ' : ', args) global sampleNames # names = str(args).split(",") # for i in names: # sampleNames.append(i) sampleNames = args send(sampleNames) def clear(unused_addr, args): print('Received: ', unused_addr, ' : ', args) global sampleNames
led_1.off() sleep(0.3) elif msg == 's': led_2.on() sleep(0.3) led_2.off() sleep(0.3) elif msg == 'd': led_3.on() sleep(0.3) led_3.off() sleep(0.3) else: led_1.off() sleep(0.3) led_2.off() sleep(0.3) led_3.off() sleep(0.3) print(addr, msg) dispatch = dispatcher.Dispatcher() dispatch.map("/position", position_func) addr = ("0.0.0.0", 5000) server = osc_server.ForkingOSCUDPServer(addr, dispatch) server.serve_forever()
lo_addr = "osc.udp://[::ffff:" + ip_local + "]:" + str(port_local) dispatcher = dispatcher.Dispatcher() # This will print all parameters to stdout. dispatcher.map("/broadcast", print) dispatcher.map("/echo", print) dispatcher.map("/paths", print) dispatcher.map("/loadbank", print) dispatcher.map("/bank-list", print) dispatcher.map("/bankview", print) client = udp_client.UDPClient(ip_remote, port_remote) #server = ForkingOSCUDPServer((ip_local, port_local), dispatcher) #server.serve_forever() server = osc_server.ForkingOSCUDPServer((ip_local, port_local), dispatcher) server_thread = threading.Thread(target=server.serve_forever) server_thread.start() msg = osc_message_builder.OscMessageBuilder(address="/echo") msg.add_arg("OSC_URL") msg.add_arg(lo_addr) msg = msg.build() client.send(msg) time.sleep(0.1) msg = osc_message_builder.OscMessageBuilder(address="/loadbank") msg.add_arg(7) msg = msg.build() client.send(msg)
GPIO.add_event_detect(BUTTON_AMBER_IN, GPIO.FALLING, callback=button_amber, bouncetime=500) GPIO.add_event_detect(BUTTON_RED_IN, GPIO.FALLING, callback=button_red, bouncetime=500) # Display the default pattern once button_amber() # Set up the OSC listener dispatcher = dispatcher.Dispatcher() dispatcher.map("/erupt", erupt_handler, "Erupt") # Run the server on its own thread server = osc_server.ForkingOSCUDPServer((args.ip, args.port), dispatcher) server_thread = threading.Thread(target=server.serve_forever) server_thread.start() print("OSC listening on {}".format(server.server_address)) # Idle loop try: while True: time.sleep(1) except KeyboardInterrupt: print("\nAttempting to clean up…") finally: server.shutdown() GPIO.cleanup()
ip = "127.0.0.1"# the IP of whatever computer this program is running on # do not change this, it is required for OSC communication between # this program and python send_port = 6449 client = udp_client.SimpleUDPClient(ip, send_port) print("listening to : {}".format((ip, send_port))) dispatcher = dispatcher.Dispatcher() dispatcher.map("/display", recvDisplayMsg) dispatcher.map("/switchInfo", recvSwitchInfo) dispatcher.map("/neopixel", recvNeoPixelInfo) dispatcher.map("/encoderInfo", recvEncoderInfo) dispatcher.map("/modeInfo", recvModeInfo) recv_port = 6450 ip = "127.0.0.1" server = osc_server.ForkingOSCUDPServer( (ip, recv_port), dispatcher) server_thread = threading.Thread(target=server.serve_forever) print("serving on {}".format(server.server_address)) server_thread.start() if __name__ == "__main__": while (True): sendWetDryGain(random()) sleep(2) # sendReverbGain(random()) # sleep(2) sendOutputGain(random()) sleep(2) sendSwitchEvent(randint(0, 4)) sleep(2) sendStompEvent(randint(0,2))