Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 72d24ab

Browse files
committed
Faust examples
1 parent 8df41ab commit 72d24ab

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Authors:
3+
Victor Shepardson
4+
Jack Armitage
5+
Intelligent Instruments Lab 2022
6+
"""
7+
8+
import numpy as np
9+
10+
from iipyper import OSC, run, repeat
11+
12+
def main(port=5511, verbose=False):
13+
14+
osc = OSC(port=port)
15+
osc.create_client("faust", port=5510)
16+
17+
connected = False
18+
19+
# Kisana parameters
20+
master = { "val": -12.0, "min": -60.0, "max": 0.0, "step": 2.0 }
21+
note = { "val": 5, "min": 0, "max": 11, "step": 1 }
22+
timbre = { "val": 0.5, "min": 0.0, "max": 1.0, "step": 0.25 }
23+
24+
@osc.args("/*")
25+
def _(address, *args):
26+
"""
27+
Handle OSC messages from Faust
28+
"""
29+
30+
if address=="/Kisana":
31+
# `osc("faust", "/*", "get")` response
32+
print(f"Kisana interface: {args}")
33+
34+
else:
35+
address = address.split("/")
36+
cmd = address[2]
37+
if cmd=="level":
38+
print(f"Level updated to: {args}")
39+
40+
@repeat(0.5)
41+
def _():
42+
nonlocal connected
43+
if connected==False:
44+
connect()
45+
connected=True
46+
update()
47+
48+
def connect():
49+
nonlocal master
50+
osc("faust", "/*", "get") # discover OSC interface
51+
osc("faust", "/xmit", 1) # turn transmission on
52+
osc("faust", "/Kisana/master", master['val']) # set master gain
53+
print("Kisana connected!")
54+
55+
def update():
56+
nonlocal note, timbre
57+
coin_flip = np.random.choice(a=[True,False], size=2)
58+
59+
if coin_flip[0]==True:
60+
note_step = np.random.randint(-note['step'], note['step']+1)
61+
note['val'] = constrain(note['val'] + note_step, note['min'], note['max'])
62+
osc("faust", "/Kisana/loop38/note", note['val'])
63+
64+
elif coin_flip[1]==True:
65+
timbre_step = np.random.random() * (timbre['step'] * 2 - timbre['step'])
66+
timbre['val'] = constrain(timbre['val'] + timbre_step, timbre['min'], timbre['max'])
67+
osc("faust", "/Kisana/timbre", timbre['val'])
68+
69+
def constrain(val, min_val, max_val):
70+
return min(max_val, max(min_val, val))
71+
72+
if __name__=='__main__':
73+
run(main)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import("stdfaust.lib");
2+
process = no.noise*hslider("level",0,0,1,0.01);

examples/faust/hello-osc/server.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Authors:
3+
Victor Shepardson
4+
Jack Armitage
5+
Intelligent Instruments Lab 2022
6+
"""
7+
8+
import random
9+
10+
from iipyper import OSC, run, repeat
11+
12+
def main(port=5511, verbose=False):
13+
14+
osc = OSC(port=port)
15+
osc.create_client("faust", port=5510)
16+
17+
connected = False
18+
19+
@osc.args("/*")
20+
def _(address, *args):
21+
"""
22+
Handle OSC messages from Faust
23+
"""
24+
25+
if address=="/FaustDSP":
26+
# `osc("faust", "/*", "get")` response
27+
print(f"Faust interface: {args}")
28+
29+
else:
30+
address = address.split("/")
31+
cmd = address[2]
32+
if cmd=="level":
33+
print(f"Level updated to: {args}")
34+
35+
@repeat(1)
36+
def _():
37+
nonlocal connected
38+
if connected==False:
39+
connected=True
40+
osc("faust", "/*", "get") # discover OSC interface
41+
osc("faust", "/xmit", 1) # turn transmission on
42+
osc("faust", "/FaustDSP/level", random.random())
43+
44+
if __name__=='__main__':
45+
run(main)

examples/faust/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `iipyper` Faust examples
2+
3+
Faust OSC documentation references:
4+
- https://faustdoc.grame.fr/manual/osc/
5+
- https://ccrma.stanford.edu/~jos/aspf/Using_FAUST_Open_Sound.html
6+
7+
## Examples
8+
- `hello-osc`: basic example demonsrating OSC send and receive
9+
- `faustlive`: examples corresponding to the [FaustLive Examples](https://github.com/grame-cncm/faustlive/tree/master/Resources/Examples)
10+
+ `harpeautomation`: autoharp with note and timbre parameters

0 commit comments

Comments
 (0)