Syphon / Processing

Syphon Implementation for Processing
Other
137 stars 33 forks source link

[suggestion] sketch to see all servers #17

Closed clankill3r closed 9 years ago

clankill3r commented 10 years ago

It might be good to have an example to receive all servers (a bit like the Simple Server.app).

It can be easy for quick testing etc. The reason i made it is that processing allows me to do way more then Simple Server.app and sometimes i like to test small things.

Here is a bad example, but good as start.

import codeanticode.syphon.*;
import java.util.Iterator;
import java.util.Map;

PGraphics[] canvas;
SyphonClient[] clients;

int nClients;

void setup() {
  size(400, 400, P2D);
  frameRate(1);

  HashMap<String, String>[] allServers = SyphonClient.listServers();

  int nServers = allServers.length;

  canvas = new PGraphics[nServers];
  clients = new SyphonClient[nServers];

  for (int i = 0; i < allServers.length; i++) {

    String appName = allServers[i].get("AppName");
    String serverName = allServers[i].get("ServerName");

    clients[i] = new SyphonClient(this, appName, serverName);
  }

  nClients = nServers;

}

void draw() {

  background(0);

  int targetIndex =  frameCount % nClients;
  SyphonClient targetClient = clients[targetIndex];

  if (targetClient.available()) {
    canvas[targetIndex] = targetClient.getGraphics(canvas[targetIndex]);
    image(canvas[targetIndex], 0, 0, width, height);  
  }
}
codeanticode commented 9 years ago

put your code in SelectServer example https://github.com/Syphon/Processing/commit/e882e5c02a3add54da6d9fa31b497a13b65a252c

A nice refinement could be to use controlP5 to populate a drop-down list with all servers. If you create a PR with this improvement, I will merge it for the next release :-)

clankill3r commented 9 years ago

I have to many things on my list but I will keep it in mind. I might do it when I need it :)

codeanticode commented 9 years ago

cool, thanks.