Processing - Clear stage of video

edited June 2014 in How To...

Hey All,

i'm using Processing and Reactivision to make an interactive table, each symbol plays a video. The problem I have is that when you remove a symbol the video remains and doesn't reset the stage, so when another symbol is added it plays below that video that has already been played. what I basically need to do is, one a symbol is removed the stage resets. Any help would be greatly appreciated. Code below

/*
    TUIO processing demo - part of the reacTIVision project
    http://reactivision.sourceforge.net/

    Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// we need to import the TUIO library
// and declare a TuioProcessing client variable
import TUIO.*;
import java.util.*;
import processing.video.*;
TuioProcessing tuioClient;

// these are some helper variables which are used
// to create scalable graphical feedback
float cursor_size = 15;
float object_size = 0;
float table_size = 760;
float scale_factor = 1;
PFont font;
PImage img;
Movie theMov; 
Movie theMov2;

void setup()
{
  //size(screen.width,screen.height);
  size(720,480);
  noStroke();
  fill(0);
  img = loadImage("isobar.jpeg");
  theMov = new Movie(this, "gibi.mov");
  theMov2 = new Movie(this, "rick.mov");

  loop();
  frameRate(30);
  //noLoop();

  font = createFont("Arial", 18);
  scale_factor = height/table_size;

  // we create an instance of the TuioProcessing client
  // since we add "this" class as an argument the TuioProcessing class expects
  // an implementation of the TUIO callback methods (see below)
  tuioClient  = new TuioProcessing(this);
}

// within the draw method we retrieve a Vector (List) of TuioObject and TuioCursor (polling)
// from the TuioProcessing client and then loop over both lists to draw the graphical feedback.
void draw()
{

  background(247,73,2);
  textFont(font,18*scale_factor);
  float obj_size = object_size*scale_factor; 
  float cur_size = cursor_size*scale_factor; 


  image(theMov, 0, 0);
  image(theMov2, 0, 0);

  Vector tuioObjectList = tuioClient.getTuioObjects();
  for (int i=0;i<tuioObjectList.size();i++) {
     TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
     pushMatrix();
     //translate(tobj.getScreenX(width),tobj.getScreenY(height));
     rotate(tobj.getAngle());
     rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
     popMatrix();
     fill(255);
     text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
   }

   Vector tuioCursorList = tuioClient.getTuioCursors();
   for (int i=0;i<tuioCursorList.size();i++) {
      TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i);
      Vector pointList = tcur.getPath();

      if (pointList.size()>0) {
        //stroke(0,0,255);
        TuioPoint start_point = (TuioPoint)pointList.firstElement();;
        for (int j=0;j<pointList.size();j++) {
           TuioPoint end_point = (TuioPoint)pointList.elementAt(j);
           line(start_point.getScreenX(width),start_point.getScreenY(height),end_point.getScreenX(width),end_point.getScreenY(height));
           start_point = end_point;
        }

        stroke(192,192,192);
        fill(192,192,192);
        ellipse( tcur.getScreenX(width), tcur.getScreenY(height),cur_size,cur_size);
        fill(0);
        text(""+ tcur.getCursorID(),  tcur.getScreenX(width)-5,  tcur.getScreenY(height)+5);
      }
   }

}


// these callback methods are called whenever a TUIO event occurs

// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
  println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());

  if ( tobj.getSymbolID() == 0) {
      theMov.play();
  }
    if ( tobj.getSymbolID() == 5) {
      theMov2.play(); 
}

}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
    if ( tobj.getSymbolID() == 0) {
      theMov.stop();
  } 
    if ( tobj.getSymbolID() == 5) {
      theMov2.stop();
  } 
}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
  println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
          +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
}

// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
  println("add cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
  println("update cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY()
          +" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
}

// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
  println("remove cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");

}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) { 
  redraw();
}

void movieEvent(Movie m) { 
  m.read(); 
}

Answers

  • Answer ✓

    I figured this out, if anyone is interested here's the correct code below :

    /*
        TUIO processing demo - part of the reacTIVision project
        http://reactivision.sourceforge.net/
    
        Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    // we need to import the TUIO library
    // and declare a TuioProcessing client variable
    import TUIO.*;
    import java.util.*;
    import processing.video.*;
    TuioProcessing tuioClient;
    
    // these are some helper variables which are used
    // to create scalable graphical feedback
    float cursor_size = 15;
    float object_size = 0;
    float table_size = 760;
    float scale_factor = 1;
    PFont font;
    PImage img;
    Movie theMov; 
    Movie theMov2;
    PImage bg;
    
    
    
    void setup()
    {
      //size(screen.width,screen.height);
      size(1280,720);
      noStroke();
      fill(0);
      //bg = loadImage("bg.png");
      theMov = new Movie(this, "isobar.mov");
    
      loop();
      frameRate(30);
      //noLoop();
    
      font = createFont("Arial", 18);
      scale_factor = height/table_size;
    
      // we create an instance of the TuioProcessing client
      // since we add "this" class as an argument the TuioProcessing class expects
      // an implementation of the TUIO callback methods (see below)
      tuioClient  = new TuioProcessing(this);
    }
    
    // within the draw method we retrieve a Vector (List) of TuioObject and TuioCursor (polling)
    // from the TuioProcessing client and then loop over both lists to draw the graphical feedback.
    void draw()
    {
    
      //background(bg);
      textFont(font,18*scale_factor);
      float obj_size = object_size*scale_factor; 
    
    
    
      Vector tuioObjectList = tuioClient.getTuioObjects();
      for (int i=0;i<tuioObjectList.size();i++) {
         TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
         pushMatrix();
         //translate(tobj.getScreenX(width),tobj.getScreenY(height));
         rotate(tobj.getAngle());
         rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
         popMatrix();
    
         if (tobj.getSymbolID()==0){
         image(theMov, 0, 0);
         }
    
        if (tobj.getSymbolID()==5){
         image(theMov2, 0, 0);
         }
    
         //fill(255);
         //text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
       }
    
    }
    
    
    // these callback methods are called whenever a TUIO event occurs
    // called when an object is added to the scene
    void addTuioObject(TuioObject tobj) {
      println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());
    
    
          if (tobj.getSymbolID() == 0){
            theMov.play();
          }
    
          if (tobj.getSymbolID() == 5){
            theMov2.play();
          }
    
         if (tobj.getSymbolID()==1){
         text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
         fill(255);
         translate(tobj.getScreenX(width),tobj.getScreenY(height));
         }
    
    }
    
    // called when an object is removed from the scene
    void removeTuioObject(TuioObject tobj) {
      println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
    
        if ( tobj.getSymbolID() == 0) {
          theMov.stop();
        }    
    
            if ( tobj.getSymbolID() == 5) {
          theMov2.stop();
        }
    
    }
    
    // called when an object is moved
    void updateTuioObject (TuioObject tobj) {
      println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
              +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
    }
    
    // called after each message bundle
    // representing the end of an image frame
    void refresh(TuioTime bundleTime) { 
      redraw();
    }
    
    void movieEvent(Movie m) { 
      m.read(); 
    }
    
Sign In or Register to comment.