hedgehog/software/ OscPythonScripts001


These all use pythonosc. There is a change (recently merged as of Jan 2023) to allow you to specify the address family when sending. See PythonOscAddressFamilyMod. See PythonMidiDevicesToOsc for scripts that translate Midi↔OSc. Note that the current conventions used should in no way be considered stable or final. This (Hedgehog) is all at an early experimental stage.

Trivial send

description = '''
load in interactive mode (i.e. python -i trivial_send.py)
then use s("/osc/message",[1,2,3,4]) to send

from pythonosc import udp_client client = udp_client.SimpleUDPClient(host,9000,family=socket.AF_INET) # needs mod with family= optional parameter def s(path,*args): print(f"Sending path= args=") client.send_message(path,args)


## Trivial threading receive
```python
description = '''
Receives [OSC](OSC) on port (default is 4567, else specify via port environment variable) 
and dumps to the terminal. Only listens on the [IPV4](IPV4) address.

import os from pythonosc import dispatcher,osc_server

def dump(xs): n,ys = xs print(f"{n}: {ys})

def main(): port = int(os.getenv("port",4567))

disp = dispatcher.Dispatcher() disp.set_default_handler(dump) serv = osc_server.ThreadingOSCUDPServer(("0.0.0.0",port),disp) print(f"Serving on port {port}") serv.serve_forever()

if name == "main": main()