Instructions/ Testing to send OSC messages to SC3 with ipython

Download pyOSC here: https://trac.v2.nl/wiki/pyOSC And do sudo ipython setup.py install inside the pyOSC folder.

On OSC more here: http://opensoundcontrol.org/introduction-osc

Source: http://www.caseyanderson.com/teaching/ipython-to-supercollider-via-osc/

Load the code below in SC3 (Supercollider): http://supercollider.sourceforge.net/

SynthDef("grain", { |out, amp=0.1, freq=440, sustain=0.01, pan| var snd = FSinOsc.ar(freq); var amp2 = amp * AmpComp.ir(freq.max(50)) * 0.5; var env = EnvGen.ar(Env.sine(sustain, amp2), doneAction: 2); OffsetOut.ar(out, Pan2.ar(snd * env, pan)); }, \ir ! 5).add; )

OSC message to send: s.sendMsg("s_new", \grain, -1, 0, 1, \freq, 200, \sustain, 0.1, \pan, -1.0); // even more efficient, as no Synth object is created.


In [1]:
import OSC
import time, random
client = OSC.OSCClient()
client.connect( ( '127.0.0.1', 57110 ) )

In [2]:
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(4000)
msg.append("sustain")
msg.append(0.01)
msg.append("pan")
msg.append(0)
client.send(msg)

In [68]:
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(400)
msg.append("sustain")
msg.append(1)
msg.append("pan")
msg.append(0)
client.send(msg)

In [69]:
import time, sys
for i in range(100):
    
    msg = OSC.OSCMessage()
    msg.setAddress("s_new")
    msg.append("grain")
    msg.append(-1)
    msg.append(0)
    msg.append(1)
    msg.append("amp")
    msg.append(1)
    msg.append("freq")
    msg.append(440)
    msg.append("sustain")
    msg.append(0.1)
    msg.append("pan")
    msg.append(0)
    client.send(msg)
    
    print(i)
    
    time.sleep(0.04)


0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

In [2]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, sympy, pyosc,


The version_information extension is already loaded. To reload it, use:
  %reload_ext version_information
Out[2]:
SoftwareVersion
Python2.7.6 |Anaconda 1.9.1 (x86_64)| (default, Jan 10 2014, 11:23:15) [GCC 4.0.1 (Apple Inc. build 5493)]
IPython1.2.1
OSposix [darwin]
numpy1.8.1
scipy0.13.3
matplotlib1.3.1
sympy0.7.5
pyosc0.3.5b-5294
Tue Apr 15 20:03:49 2014 CEST

In [ ]: