processing + PGraphic + syphon

edited January 2018 in Library Questions

Hello all, I hope someone can help me i'm a bit of a newby and I'm really stuck.... I am creating graphics in Processing which I want to be able to layer up with other material using Resolume. I am using Syphon as a source server out of Processing and into Resolume but I can only do it by sending the SCREEN. This obviously includes a background even if I have a transparent one in Processing. I need to be able to pack classes and custom methods into PGraphics and send as Frames only..... agh I don't know what I'm doing... I've tried to follow advise from other posts but I haven't been able to apply them to my own code. PLEASE HELP!!!

`import codeanticode.syphon.*;
import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
// AudioPlayer song;
AudioInput song;
FFT fft;

// Variables that define the "zones" of the spectrum
// For example, for bass, we take only the first 4% of the total spectrum
float specLow = 0.03; // 3%
float specMid = 0.125;  // 12.5%
float specHi = 0.20;   // 20%

// This leaves 64% of the possible spectrum that will not be used. 
// These values ​​are usually too high for the human ear anyway.

// Scoring values ​​for each zone
float scoreLow = 0;
float scoreMid = 0;
float scoreHi = 0;

// Previous value, to soften the reduction
float oldScoreLow = scoreLow;
float oldScoreMid = scoreMid;
float oldScoreHi = scoreHi;

// Softening value
float scoreDecreaseRate = 125;

// Cubes appearing in space
int nbCubes;
Cube[] cubes;
PGraphics canvas;
SyphonServer server;
void setup() { 
  size(1980, 1080, P3D);
  canvas = createGraphics(width, height, P3D);

  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");

//Load the minim library
  minim = new Minim(this);

  //Load song
  // song = minim.loadFile("--");
    //Get live input
  song = minim.getLineIn(Minim.MONO);

  //Create the FFT object to analyze the song
  fft = new FFT(song.bufferSize(), song.sampleRate());
//One cube per frequency band
  nbCubes = (int)(fft.specSize()*specHi*1.25);
  cubes = new Cube[nbCubes];
    //Create all objects
  //Create cubic objects
  for (int i = 0; i < nbCubes; i++) {
   cubes[i] = new Cube(); 

void draw() {
    //Forward the song. One draw () for each "frame" of the song ...

  //Calculation of "scores" (power) for three categories of sound
  //First, save old values
  oldScoreLow = scoreLow;
  oldScoreMid = scoreMid;
  oldScoreHi = scoreHi;

  //Reset values
  scoreLow = 0;
  scoreMid = 0;
  scoreHi = 0;

  //Calculate the new "scores"
  for(int i = 0; i < fft.specSize()*specLow; i++)
    scoreLow += fft.getBand(i);

  for(int i = (int)(fft.specSize()*specLow); i < fft.specSize()*specMid; i++)
    scoreMid += fft.getBand(i);

  for(int i = (int)(fft.specSize()*specMid); i < fft.specSize()*specHi; i++)
    scoreHi += fft.getBand(i);

  //To slow down the descent.
  if (oldScoreLow > scoreLow) {
    scoreLow = oldScoreLow - scoreDecreaseRate;

  if (oldScoreMid > scoreMid) {
    scoreMid = oldScoreMid - scoreDecreaseRate;

  if (oldScoreHi > scoreHi) {
    scoreHi = oldScoreHi - scoreDecreaseRate;

  //Volume for all frequencies at this time, with the highest sounds higher.
  //This allows the animation to go faster for the higher pitched sounds, which is more noticeable
  float scoreGlobal = scoreLow*0.5 + 0.7*scoreMid + 1*scoreHi;

  //Subtle color of background
  // background(scoreLow/100, scoreMid/200, scoreHi/500, 50);

  //Cube for each frequency band
  for(int i = 0; i < nbCubes; i++)
    //Value of the frequency band
    float bandValue = fft.getBand(i);

    //The color is represented as: red for bass, green for medium sounds and blue for high. 
    //The opacity is determined by the volume of the tape and the overall volume.
    cubes[i].display(scoreLow, scoreMid*2, scoreHi*5, bandValue*2, scoreGlobal);
  // canvas.beginDraw();
  // // canvas.background(127);
  // canvas.clear();
  // canvas.lights();
  // canvas.translate(width/2, height/2);
  // canvas.rotateX(frameCount * 0.01);
  // canvas.rotateY(frameCount * 0.01);  
  // canvas.endDraw();
  // image(canvas, 0, 0);
  // server.sendImage(canvas);//I need to send to PGraphics so I can have a transparent background 

//Class for cubes floating in space
class Cube {
  //Z position of spawn and maximum Z position
  float startingZ = -10000;
  float maxZ = 1000;

  //Position values
  float x, y, z;
  float rotX, rotY, rotZ;
  float sumRotX, sumRotY, sumRotZ;

  Cube() {
    //Make the cube appear in a random place
    x = random(0, width);
    y = random(0, height);
    z = random(startingZ, maxZ);

    //Give the cube a random rotation
    rotX = random(0, 1);
    rotY = random(0, 1);
    rotZ = random(0, 1);

  void display(float scoreLow, float scoreMid, float scoreHi, float intensity, float scoreGlobal) {
    //Color selection, opacity determined by intensity (volume of the tape)
    color displayColor = color(scoreLow, scoreMid*2, scoreHi*5, intensity*5);
    fill(displayColor, 255);

    //Color lines, they disappear with the individual intensity of the cube
    color strokeColor = color(255, 150-(20*intensity));
    strokeWeight(0.5 + (scoreGlobal/300));

    //Creating a transformation matrix to perform rotations, enlargements

    translate(x, y, z);

    //Calculation of the rotation according to the intensity for the cube
    sumRotX += intensity*(rotX/1000);
    sumRotY += intensity*(rotY/1000);
    sumRotZ += intensity*(rotZ/1000);

    //Application of the rotation

    //Creation of the box, variable size according to the intensity for the cube

    //Application of the matrix

    //Z displacement
    z+= (1+(intensity/5)+(pow((scoreGlobal/150), 2)));

    //Replace the box at the back when it is no longer visible
    if (z >= maxZ) {
      x = random(0, width);
      y = random(0, height);
      z = startingZ;



Sign In or Register to comment.