I am a fairly experienced python user, but I have no experience with OSC protocol, MAX and SuperCollider.
I am helping a friend in building a python code that should do the following:
- receive a message from MAX via OSC
- elaborate the message in python
- send the elaborated message to SuperCollider
What it is not clear to me is what concerns the 1 and 3 points.
PART 0
I import the following libraries
from pythonosc import dispatcher
from pythonosc import osc_server
from pythonosc import udp_client
PART 1
I tried to setup a simple server for point 1, since I am only receiving one string at a time from MAX:
def listen2Max(ip,port):
'''
set up server
'''
# dispatcher to receive message
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/filter", print)
# server to listen
server = osc_server.ThreadingOSCUDPServer((ip,port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
but i do not know what to return
in this function, also I do not get the use of "/filter"
in the map
. Is it something that must be specified in MAX?
PART 2
This is actually my strong suit: I take the string message returned by my listen2Max function, do some py stuff and prepare a message called mymove
to be sent to SuperCollider
PART 3
For point 3 I set up a simple client to communicate the string var mymove
to SuperCollider
def talk2SC(ip,port,mymove):
'''
set up client
'''
client = udp_client.SimpleUDPClient(ip,port)
client.send_message("/filter", mymove)
Should it work like that?
This is the code that gets (at least part of) the job done.
Bear in mind that, in this case, Max sends strings to python. The messages I get are something like this:
O-O e8g8 8 1
This code gets messages from a client like this:
and sends messages to a server like this:
The tricky part is to make it communicate with Max. Luckily enough I found an answer here:
/path "O-O e8g8 8 1"
/path
If one wants python to listen to each and every path, one could change the default path in the parser item and use
"*"
as default. Thenparser.add_argument("-UI", "--uripathIN", type=str, default="*", help="MAX's URI path")
Now, I just have to fix the SuperCollider part.