sonic-pi-net / sonic-pi

Code. Music. Live.
https://sonic-pi.net
Other
10.85k stars 923 forks source link

/run-code not playing anything, other methods work fine though #767

Closed martinpgrayson closed 9 years ago

martinpgrayson commented 9 years ago

Hi,

I am writing a snoic pi code generator in python. I am using pyOSC (https://trac.v2.nl/wiki/pyOSC) to send messages to SuperCollider.

I start Sonic Pi, (so scsynth is running in the background on port 4557) and then run my python code which creates an OSCClient and attempts to send messsages. Viewing the log in the Sonic Pi UI, I can see that messages such as "/stop-all-jobs", "/start-recording", '/stop-recording" etc all work, showing output in the log.

However, if I try to send "/run-code play 100", or /"run-code" with "play 100" appended to the message, Sonic Pi does not play.

Here is my python code:

import OSC

c = OSCClient() c.connect(("127.0.0.1", 4557))

msg = OSCMessage() msg.setAddress('/run_code') msg.append('play 100') c.send(msg)

My setup is this: Windows 10 (RTM Build 1024) Python 2.7.10 PyCharm 4.5.4 (Python IDE) Sonic Pi 2.7 Windows Edition

Any help is much appreciated, thanks.

xavriley commented 9 years ago

Hi Martin,

Sounds like a fun project. Might be a good idea to post this kind of thing on the mailing list in future as it's not so much of an "issue" with Sonic Pi so to speak, but don't worry about it for now.

I think it looks like you're missing the GUI ID part of the OSC message. This was introduced in 2.7 (I think) to lay the groundwork for dealing with multiple clients sending code to Sonic Pi's Ruby server (just like you're doing here!). That means your code will probably have to look something like:

msg = OSCMessage()
msg.setAddress('/run_code')
msg.append('MY_PYTHON_GUI')
msg.append('play 100')
c.send(msg)

It doesn't really matter what the GUI ID is, it just has to be there for the message to work.

You can see some useful code for the sonic_pi_cli gem which allows you to send OSC messages to Sonic Pi from the command line here https://github.com/Widdershin/sonic-pi-cli/blob/master/lib/sonic_pi.rb#L38

It's not an official gem so I wouldn't rely on it too heavily, but it does the job and the code is quite simple.

Hope that helps - if it does then perhaps you can close off this issue? Best of luck.

samaaron commented 9 years ago

Yep, @xavriley is right.

The ID part ideally should be unique across all potential clients. Therefore a reverse domain name or UUID would be best...

martinpgrayson commented 9 years ago

That was it! Thank you so much - it now works perfectly. I wasnt aware of the mailing list, but will of course use that for future questions.

I really, really appreciate the super fast response.

Consider this issue now closed.

samaaron commented 9 years ago

Great that you have it working.

However, please be warned. The OSC API is not stable yet and is likely to change as I bash on it. I'll prefix any OSC related commits with OSC API in the commit message so you can watch out for them...