Simpl Processing Send & Receive

I have been working with the Syphon Library for, which lets one share video streams between applications on a Mac (like an invisible cable).

I have been used to doing it in Quartz Composer and worked to find an acceptable approach in Processing. It seems the trick is to always draw the frames you want to send in via a PGraphics instance. You also must use this in P3D mode.

After running through these processes I came upon this code to bring in a Syphon Client, draw new frames, and then send out via a fresh Syphon Server. Hopefully you can adapt these to your sketches and easily integrate them with other video inputs and outputs.

// "Simpl Syhon Send & Receive"
//
//   Shows how one can receive a Syphon Client, draw new content, 
//   and then sound out as one compiled Syphon Server
//
//     Sketch by Casey of Scalf of www.Sensebellum.com
//
//     Use code apps provided here as a simple Server and Client: https://github.com/Syphon/Simple/releases/download/public-beta-2/Syphon.Demo.Apps.Public.Beta.2.dmg

import codeanticode.syphon.*;

PGraphics canvas;
PImage img;

SyphonClient syphonIn;
SyphonServer syphonOut;

void setup() {
  size(640, 480, P3D);
  smooth();
  canvas = createGraphics(640, 480, P3D);

  // Seek client to draw in frames
  // Takes in any available feed
  syphonIn = new SyphonClient(this);

  //Create server to send the frames out
  syphonOut = new SyphonServer(this, "Simpl Syphon Send");
}

void draw() {
  img = syphonIn.getImage(img);

  canvas.beginDraw();
  canvas.background(0);
  canvas.stroke(127);
  canvas.fill(225, 150);
  canvas.strokeWeight(5);
  // Change image to green with tint() to show change in Syphon Feed
  canvas.tint(0, 255, 127);
  canvas.image(img, 0, 0);
  // Draw new pixels with an ellipse()
  canvas.ellipse(mouseX, mouseY, 50, 50 );
  canvas.endDraw();

  //This actually draws the scene to the screen.
  //Without, there would not be anything in Processing, only in the Syphon Server.
  image(canvas, 0, 0);
  syphonOut.sendImage(canvas);
}
Tagged:

Comments

Sign In or Register to comment.