使用PyOSC终止Sonic Pi

时间:2015-08-10 17:11:32

标签: python raspberry-pi osc

我正在使用Pyosc库将代码从python发送到Raspberry Pi上的Sonic Pi。

以下代码将我的代码发送给Sonic Pi。

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

如何终止此代码并发送新代码?终止当前正在播放的代码的地址/命令是什么?

2 个答案:

答案 0 :(得分:0)

全部写在Sonic Pi github wiki page

因此,您要查找的地址/命令是/stop-all-jobs

答案 1 :(得分:0)

这可能会回答更多问题。

# 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")