Skip to content

Commit 4923f0c

Browse files
committed
Add hello world example
1 parent 560d79e commit 4923f0c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/hello-world.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
#-------------------------------------------------------------------------------
4+
# Minimal example of using python-supercollider.
5+
#
6+
# Before running this script, the SC server must be started, and the following
7+
# SynthDef stored:
8+
#
9+
# SynthDef(\sine, { |out = 0, freq = 440.0, gain = 0.0|
10+
# Out.ar(out, SinOsc.ar(freq) * gain.dbamp);
11+
# }).store;
12+
#-------------------------------------------------------------------------------
13+
14+
from supercollider import Server, Synth
15+
import time
16+
17+
#-------------------------------------------------------------------------------
18+
# Create connection to default server on localhost:57110
19+
#-------------------------------------------------------------------------------
20+
server = Server()
21+
22+
#-------------------------------------------------------------------------------
23+
# Create a Synth, set its parameter, query the parameter, and free it.
24+
#-------------------------------------------------------------------------------
25+
synth = Synth(server, "sine", { "freq" : 440.0, "gain" : -36.0 })
26+
print("Created synth")
27+
synth.get("freq", lambda n: print("Frequency: %.1f" % n))
28+
time.sleep(1.0)
29+
synth.free()
30+
print("Freed synth")

0 commit comments

Comments
 (0)