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

Commit 38ca0f1

Browse files
committed
bela basic example almost fully working…
1 parent 17f4e15 commit 38ca0f1

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

examples/bela/osc-basic/render.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,24 @@ OscReceiver oscReceiver;
3636
OscSender oscSender;
3737
int localPort = 8888;
3838
int remotePort = 9999;
39-
const char* remoteIp = "127.0.0.1";
39+
const char* remoteIp = "192.168.7.1";
4040

4141
// parse messages received by the OSC receiver
4242
// msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
4343
bool handshakeReceived;
4444
void on_receive(oscpkt::Message* msg, void* arg)
4545
{
46-
if(msg->match("/bela/osc-setup-reply"))
46+
if(msg->match("/osc-setup-reply"))
4747
handshakeReceived = true;
48-
else if(msg->match("/bela/osc-test")){
48+
else if(msg->match("/osc-test")){
4949
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();
50+
// float floatArg;
51+
msg->match("/osc-test").popInt32(intArg).isOkNoMoreArgs();
52+
printf("%i\n",intArg);
53+
// msg->match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs();
54+
// int intArg;
55+
// printf("received a message with int %i and float %f\n", intArg, floatArg);
56+
// oscSender.newMessage("/osc-acknowledge").add(intArg).add(4.2f).add(std::string("OSC message received")).send();
5457
}
5558
}
5659

@@ -61,9 +64,9 @@ bool setup(BelaContext *context, void *userData)
6164

6265
// the following code sends an OSC message to address /osc-setup
6366
// then waits 1 second for a reply on /osc-setup-reply
64-
oscSender.newMessage("/bela/osc-setup").send();
67+
oscSender.newMessage("/osc-setup").send();
6568
int count = 0;
66-
int timeoutCount = 10;
69+
int timeoutCount = 5;
6770
printf("Waiting for handshake ....\n");
6871
while(!handshakeReceived && ++count != timeoutCount)
6972
{

examples/bela/osc-basic/server.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,44 @@
55
Intelligent Instruments Lab 2022
66
"""
77

8-
from iipyper import OSC, run
8+
from iipyper import OSC, run, repeat
99

10-
def main(host="127.0.0.1", port=9999, checkpoint=None):
10+
def main(host="192.168.7.1", port=9999):
11+
1112
osc = OSC(host, port)
12-
osc.create_client('bela', port=8888)
13+
osc.create_client("bela", host="192.168.7.2", port=8888)
14+
1315
connected = False
1416
count = 0
1517

16-
@osc.kwargs('/bela/*')
18+
@osc.kwargs("/*")
1719
def _(address, **kw):
1820
"""
1921
Handle OSC messages from Bela
2022
"""
2123
print(f"{address} {kw}")
2224

23-
address = address.split("/")
24-
cmd = address[2]
25-
26-
if cmd=="osc-setup":
25+
if address=="/osc-setup":
26+
nonlocal connected
2727
connected = True
28-
osc("bela", "osc-setup-reply", "")
28+
print("Bela connected!")
29+
osc("bela", "/osc-setup-reply")
2930

30-
elif cmd=="osc-acknowledge":
31-
print(f"Bela: test acknowledged: {kw}")
31+
elif address=="/osc-acknowledge":
32+
print(f"Bela acknowledged osc-test: {kw}")
3233

3334
else:
34-
print(f"Bela: Unrecognised OSC {address} with {kw}")
35+
print(f"Unrecognised OSC {address} with {kw}")
3536

36-
if connected=True:
37-
osc("bela", "osc-test", [count++, 3.14])
37+
@repeat(1)
38+
def _():
39+
nonlocal connected
40+
nonlocal count
41+
if connected==True:
42+
osc("bela", "/osc-test", count)
43+
count=count+1
44+
else:
45+
print("Waiting for Bela to connect...")
3846

3947
if __name__=='__main__':
4048
run(main)

0 commit comments

Comments
 (0)