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

Commit 17f4e15

Browse files
committed
examples wip
1 parent 8d263b3 commit 17f4e15

File tree

6 files changed

+217
-2
lines changed

6 files changed

+217
-2
lines changed

examples/bela/osc-basic/render.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
____ _____ _ _
3+
| __ )| ____| | / \
4+
| _ \| _| | | / _ \
5+
| |_) | |___| |___ / ___ \
6+
|____/|_____|_____/_/ \_\
7+
http://bela.io
8+
*/
9+
/**
10+
\example Communication/OSC/render.cpp
11+
12+
Open Sound Control
13+
------------------
14+
15+
This example shows an implementation of OSC (Open Sound Control) which was
16+
developed at UC Berkeley Center for New Music and Audio Technology (CNMAT).
17+
18+
It is designed to be run alongside resources/osc/osc.js.
19+
For the example to work, run in a terminal on the board
20+
```
21+
node /root/Bela/resources/osc/osc.js
22+
```
23+
24+
In `setup()` an OSC message to address `/osc-setup`, it then waits
25+
1 second for a reply on `/osc-setup-reply`.
26+
27+
After that, OSC communication takes place in the on_receive() callback,
28+
which is called every time a new message comes in.
29+
*/
30+
31+
#include <Bela.h>
32+
#include <libraries/OscSender/OscSender.h>
33+
#include <libraries/OscReceiver/OscReceiver.h>
34+
35+
OscReceiver oscReceiver;
36+
OscSender oscSender;
37+
int localPort = 8888;
38+
int remotePort = 9999;
39+
const char* remoteIp = "127.0.0.1";
40+
41+
// parse messages received by the OSC receiver
42+
// msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
43+
bool handshakeReceived;
44+
void on_receive(oscpkt::Message* msg, void* arg)
45+
{
46+
if(msg->match("/bela/osc-setup-reply"))
47+
handshakeReceived = true;
48+
else if(msg->match("/bela/osc-test")){
49+
int intArg;
50+
float floatArg;
51+
msg->match("/bela/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs();
52+
printf("received a message with int %i and float %f\n", intArg, floatArg);
53+
oscSender.newMessage("/bela/osc-acknowledge").add(intArg).add(4.2f).add(std::string("OSC message received")).send();
54+
}
55+
}
56+
57+
bool setup(BelaContext *context, void *userData)
58+
{
59+
oscReceiver.setup(localPort, on_receive);
60+
oscSender.setup(remotePort, remoteIp);
61+
62+
// the following code sends an OSC message to address /osc-setup
63+
// then waits 1 second for a reply on /osc-setup-reply
64+
oscSender.newMessage("/bela/osc-setup").send();
65+
int count = 0;
66+
int timeoutCount = 10;
67+
printf("Waiting for handshake ....\n");
68+
while(!handshakeReceived && ++count != timeoutCount)
69+
{
70+
usleep(100000);
71+
}
72+
if (handshakeReceived) {
73+
printf("handshake received!\n");
74+
} else {
75+
printf("timeout! : did you start the iipyper server? `python server.py`\n");
76+
return false;
77+
}
78+
return true;
79+
}
80+
81+
void render(BelaContext *context, void *userData)
82+
{
83+
84+
}
85+
86+
void cleanup(BelaContext *context, void *userData)
87+
{
88+
89+
}

examples/bela/osc-basic/server.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Authors:
3+
Victor Shepardson
4+
Jack Armitage
5+
Intelligent Instruments Lab 2022
6+
"""
7+
8+
from iipyper import OSC, run
9+
10+
def main(host="127.0.0.1", port=9999, checkpoint=None):
11+
osc = OSC(host, port)
12+
osc.create_client('bela', port=8888)
13+
connected = False
14+
count = 0
15+
16+
@osc.kwargs('/bela/*')
17+
def _(address, **kw):
18+
"""
19+
Handle OSC messages from Bela
20+
"""
21+
print(f"{address} {kw}")
22+
23+
address = address.split("/")
24+
cmd = address[2]
25+
26+
if cmd=="osc-setup":
27+
connected = True
28+
osc("bela", "osc-setup-reply", "")
29+
30+
elif cmd=="osc-acknowledge":
31+
print(f"Bela: test acknowledged: {kw}")
32+
33+
else:
34+
print(f"Bela: Unrecognised OSC {address} with {kw}")
35+
36+
if connected=True:
37+
osc("bela", "osc-test", [count++, 3.14])
38+
39+
if __name__=='__main__':
40+
run(main)

examples/bela/readme.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,23 @@
22

33
Unless otherwise stated, these examples assume a set up of a Bela device connected to a laptop, where the `server.py` is running on the laptop.
44

5-
- `osc-basic`: basic OSC communication with Bela
6-
- ``: ...
5+
## C++
6+
- `cpp-osc-basic`: basic OSC communication with Bela
7+
- `cpp-osc-basic-gui`: basic OSC communication with Bela with a Bela GUI
8+
- `cpp-osc-basic-gui-svelte`: basic OSC communication with Bela with a Svelte GUI
9+
- `cpp-osc-recorder`: record data received from Bela
10+
- `cpp-osc-resonators`: controlling the Resonators library
11+
- `cpp-osc-scope`: controlling the Bela scope
12+
- `cpp-osc-trill`: using Trill sensors
13+
14+
## SuperCollider
15+
- `scd-osc-basic`:
16+
17+
## Pure Data
18+
- `pd-osc-basic`:
19+
20+
## Csound
21+
- `cs-osc-basic`:
22+
23+
## Faust
24+
- `faust-osc-basic`:

examples/tidalcycles/OSCTarget.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Target
2+
:{
3+
iipyTarget = Target {oName = "iipyper",
4+
oAddress = "127.0.0.1",
5+
oHandshake = True,
6+
oPort = 8000,
7+
oBusPort = Just 8001,
8+
oLatency = 0.2,
9+
oWindow = Nothing,
10+
oSchedule = Pre BundleStamp
11+
}
12+
:}
13+
14+
-- OSC Specs
15+
:{
16+
iipyOSCSpecs = [OSC "/path/{path1}/" $ ArgList [("param1", Nothing),
17+
("delta", Just $ VF 0),
18+
("cycle", Just $ VF 0),
19+
("cps", Just $ VF 0)],
20+
OSC "/path/{path2}/" $ ArgList [("param2", Nothing),
21+
("delta", Just $ VF 0),
22+
("cycle", Just $ VF 0),
23+
("cps", Just $ VF 0)]]
24+
:}
25+
26+
-- Parameters
27+
:{
28+
let path1 = pS "path1"
29+
path2 = pS "path2"
30+
param1 = pF "param1"
31+
param2 = pF "param2"
32+
:}
33+
34+
-- OSC Map
35+
iipyOscMap = (iipyTarget, iipyOSCSpecs)

examples/tidalcycles/iipyper.tidal

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
{-
3+
4+
5+
6+
-}
7+
8+
d1
9+
$ path1 "something"
10+
# param1 0.5
11+
12+
d2
13+
$ path2 "something"
14+
# param2 0.5
15+
16+
hush
17+
18+
{-
19+
20+
21+
22+
-}
23+
24+
d1 $ s (cP "bd" "d1pattern")
25+
26+

examples/tidalcycles/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# `iipyper` TidalCycles example
22

3+
## Tidal to `iipyper`
4+
- `OSCTarget.hs`: this allows Tidal to send messages to `iipyper`
35

6+
## `iipyper` to Tidal
7+
- https://tidalcycles.org/docs/configuration/MIDIOSC/osc#controller-input
8+
+ https://github.com/tidalcycles/Tidal/issues/677
9+
10+
## `iipyper` to SuperDirt
411

0 commit comments

Comments
 (0)