We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › help! how to switch songs
Page Index Toggle Pages: 1
help! how to switch songs? (Read 816 times)
help! how to switch songs?
Feb 9th, 2009, 8:59am
 
hello,
i'm using reacTIVision to activate playing different songs. i got it to successfully play 1 song when it reads the fiducial marker, and i can interrupt the song with another song when i change it to a different marker, which plays but i also get an error. is it in the placement of my stop and plays? i would like to be able to add more songs later as well for the specific markers in the code. thanks!


here's my code:


import tuio.*;
TuioClient tuioClient;

//IMPORT MINIM LIBRARY
import ddf.minim.*;

//AUDIO VARIABLES
Minim minim;
AudioPlayer player;

//Minim minim2;
AudioPlayer player2;


float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;

void setup(){
 size(600,400);
 noStroke();
 fill(0);
 
//LOAD SWEET TUNES
  minim = new Minim(this);
   // load a file, give the AudioPlayer buffers that are 2048 samples long
 player = minim.loadFile("thismustbetheplace(naive melody).mp3", 2048);
 player2 = minim.loadFile("AbsolutelyCuckoo.mp3", 2048);
 
 loop();

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

 tuioClient  = new TuioClient(this);
}

void draw(){
 background(255);
 textFont(font,18*scale_factor);
 float obj_size = object_size*scale_factor;
 float cur_size = cursor_size*scale_factor;

 //GET TUIO OBJECTS
 TuioObject[] tuioObjectList = tuioClient.getTuioObjects();
 for (int i=0; i<tuioObjectList.length; i++) {
   TuioObject tobj = tuioObjectList[i];  
   stroke(0);
   fill(0);
   text(""+tobj.getFiducialID(), tobj.getScreenX(width), tobj.getScreenY(height));
   

   if (tobj.getFiducialID()==0){
     fill(255, 0, 0 );
     rect(0,0, 50, 50);
     
  // play the file/////////////////////////////
    player.play();
 
   }
   
   else
     if (tobj.getFiducialID()==106){
     fill(0, 100);
     rect(40,40, 100, 100);  

  //play another file///////////////////////////////
     player2.play();
     stop();
     
     
   }
   else
     if (tobj.getFiducialID()==87){
     fill(0);
     rect(40,40, 100, 100);
   }
   else
     if (tobj.getFiducialID()==98){
     fill(#cccfff);
     rect(40,40, 100, 100);
   }


 }

 //GET TUIO CURORS
 TuioCursor[] tuioCursorList = tuioClient.getTuioCursors();
 for (int i=0;i<tuioCursorList.length;i++) {
   TuioCursor tcur = tuioCursorList[i];
   TuioPoint[] pointList = tcur.getPath();
   if (pointList.length > 0) {
     stroke(0,0,255);
     TuioPoint start_point = pointList[0];
     for (int j=0;j<pointList.length;j++) {
       TuioPoint end_point = pointList[j];
       // line(start_point.getScreenX(width),start_point.getScreenY(height),end_point.getS
creenX(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.getFingerID(),  tcur.getScreenX(width)-5,  tcur.getScreenY(height)+5);
   }
 }
 ////////////////////////////////////////////////////////////////////////////

} //END DRAW


//STOP MUSIC
void stop(){
 // always close Minim audio classes when you are done with them
 player.close();
 // always stop Minim before exiting
 minim.stop();  
 super.stop();
 
//    player2.close();
//  // always stop Minim before exiting
//  minim2.stop();  
//  super.stop();

}





// 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.getFiducialID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());

}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
 println("remove object "+tobj.getFiducialID()+" ("+tobj.getSessionID()+")");
}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
 println("update object "+tobj.getFiducialID()+" ("+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.getFingerID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
 println("update cursor "+tcur.getFingerID()+" ("+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.getFingerID()+" ("+tcur.getSessionID()+")");
}

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



Page Index Toggle Pages: 1