Skip to content

Commit c3aa1d7

Browse files
committed
get list of servers outside setup
1 parent 9c325f0 commit c3aa1d7

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

examples/SelectServer/SelectServer.pde

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,54 @@ import codeanticode.syphon.*;
22
import java.util.Iterator;
33
import java.util.Map;
44

5-
PGraphics[] canvas;
6-
SyphonClient[] clients;
5+
PGraphics[] canvas = {};
6+
SyphonClient[] clients = {};
77

88
int nClients;
99

1010
void setup() {
1111
size(400, 400, P2D);
1212
frameRate(1);
1313

14-
HashMap<String, String>[] allServers = SyphonClient.listServers();
14+
updateClients();
15+
}
16+
17+
void draw() {
18+
if (clients.length == 0) updateClients();
19+
20+
background(0);
21+
22+
if (0 < nClients) {
23+
int targetIndex = frameCount % nClients;
24+
SyphonClient targetClient = clients[targetIndex];
25+
26+
if (targetClient.newFrame()) {
27+
canvas[targetIndex] = targetClient.getGraphics(canvas[targetIndex]);
28+
image(canvas[targetIndex], 0, 0, width, height);
29+
}
30+
}
31+
}
32+
33+
void keyPressed() {
34+
if (key == ' ') {
35+
updateClients();
36+
}
37+
}
1538

39+
void updateClients() {
40+
HashMap<String, String>[] allServers = SyphonClient.listServers();
41+
println(allServers);
42+
1643
int nServers = allServers.length;
1744

1845
canvas = new PGraphics[nServers];
1946
clients = new SyphonClient[nServers];
2047

21-
2248
for (int i = 0; i < allServers.length; i++) {
23-
2449
String appName = allServers[i].get("AppName");
2550
String serverName = allServers[i].get("ServerName");
26-
2751
clients[i] = new SyphonClient(this, appName, serverName);
2852
}
2953

30-
nClients = nServers;
31-
32-
}
33-
34-
void draw() {
35-
36-
background(0);
37-
38-
int targetIndex = frameCount % nClients;
39-
SyphonClient targetClient = clients[targetIndex];
40-
41-
if (targetClient.newFrame()) {
42-
canvas[targetIndex] = targetClient.getGraphics(canvas[targetIndex]);
43-
image(canvas[targetIndex], 0, 0, width, height);
44-
}
54+
nClients = nServers;
4555
}

0 commit comments

Comments
 (0)