0

Communication from Python to scsynth via pyosc goes well, but instead when trying to receive in Python osc messages sent from scsynth audio server (just scsynth, not SuperCollider), I don't understand how to get the port scsynth is sending to.

If I try to send a "/notify" message to scsynth it should reply with the sending address, but with pyosc I can't set a listener on the same port as the sending one, and so I can't retrieve the information that should come back.

Any suggestions about how to do that?

Julien Marrec
  • 11,605
  • 4
  • 46
  • 63
F.R.D
  • 143
  • 1
  • 11

2 Answers2

1

You can accomplish this by using OSCClient.setServer to tell your OSC client to use the server's socket for transmission. Here's an example to illustrate this where the OSC message is send and received at socket 8000:

import OSC

def handle_message(address, tags, contents, source):
    # prints out the message
    print(address)
    print(source)

server = OSC.OSCServer(("localhost",8000))
server.addMsgHandler("/test", handle_message)

msg = OSC.OSCMessage("/test", [1])

client = OSC.OSCClient()
client.setServer(server)
client.connect(("localhost", 8000))
client.send(msg)

server.serve_forever()
Charles Martin
  • 338
  • 2
  • 13
0

I am almost positive the sender and the receiver have to be on different ports. A port used for receiving cannot also be used for sending simultaneously.

regarding sending OSC messages back to pyosc I do not understand why you wouldnt use NetAddr.new and then .sendMSg(). For example (this is from the documentation on OSC Communication):

b = NetAddr.new("127.0.0.1", 7771);
b.sendMsg("/hello", "there");

More info here.

If you wanted automatic reply from SC then you could just write a way to trigger a responding .sendMsg into your OSCDef or OSCFunc, for example, which could simply wait for the initial message from python and respond with whatever you want python to get back.

caseyanderson
  • 490
  • 1
  • 5
  • 13
  • This answer is about how to do send an OSC message from sclang to python - but the question is actually about sending messages from scsynth to python. – Charles Martin Feb 28 '17 at 11:54
  • Let me emphasize a key point of my answer: regarding sending OSC messages back to pyosc I do not understand why you wouldn't use `NetAddr.new` and then `.sendMSg()`. I am well aware that those things are in sclang. – caseyanderson Mar 01 '17 at 17:27
  • `sclang` is probably not actually running, it sounds to me like OP is running `scsynth` separately (e.g., by running `scsynth -u 57110`) and intends to completely control it with Python without having anything to do with `sclang`. – Charles Martin Mar 02 '17 at 09:46
  • makes sense. I appreciate your answer below as it gives me some new techniques to try out (I go between python and sc often). – caseyanderson Mar 02 '17 at 19:07