2

I am using the Pyosc library to send code from python to Sonic Pi on a Raspberry Pi.

The following code sends my code to Sonic Pi.

code = SOME SONIC PI CODE
oscmsg = OSC.OSCMessage()
oscmsg.setAddress("/run-code")
oscmsg.append(code)
c.send(oscmsg)

How do I terminate this code and send new code? What is the address/command for terminating the current code that is playing?

user1011332
  • 773
  • 12
  • 27
  • Can you paste the code you use in Sonic Pi to receive the OSC messages? Maybe you could send another message like "/stop-code" or something like that. – George Aug 12 '15 at 11:51

2 Answers2

0

It's all written on the Sonic Pi github wiki page.

Therefore the address/command you're looking for is /stop-all-jobs.

sel
  • 3
  • 2
0

This might answer even more questions.

# do this first:
# pip install pyosc

import OSC
import time

def sendCmd(cmd,par = None):
    oscmsg = OSC.OSCMessage()
    oscmsg.append('MY_PYTHON_GUI')
    oscmsg.setAddress(cmd)
    if par:
        oscmsg.append(par)
    c.send(oscmsg)

c = OSC.OSCClient()
c.connect(('127.0.0.1', 4557))   # connect to SuperCollider

#change these:
MYPATH = "/Users/you/path/"

# currentSong = MYSONG + ".txt"
# song = open( currentSong, 'r').read()
# MYSONG = "cloudbeat"

song = """
# music by Pit Noack
# http://www.maschinennah.de/sonic-pi-codeschnipsel-compus-loop/

use_bpm 80

live_loop :compus do
  with_fx :ixi_techno, phase: [0.125, 0.25, 0.5, 1, 2].choose do
    sample :loop_compus, beat_stretch: (ring 4, 8)[tick], amp: 4
    sleep (ring 4, 8)[look]
  end
end
"""

sendCmd("/stop-all-jobs")
sendCmd("/start-recording")

sendCmd("/run-code", song)

# the recording time should be calculated
time.sleep(3)

sendCmd("/stop-all-jobs")

# wait for reverb tail, etc
time.sleep(1)
sendCmd("/stop-recording")

time.sleep(0.1)
# sendCmd("/save-recording", MYPATH + MYSONG + ".wav")
sendCmd("/save-recording", MYPATH  + "song.wav")
dirkk0
  • 2,460
  • 28
  • 34