Hey guys, I'm doing something similar with reactable. Using a marker to produce sound. But i'm facing a problem of not able to loop sound and also pausing them when i take the marker off.. :/ could any of you help me solve this problem? thanks a lot!
Here is my code.. Sorry for the uber long code.
Here is my code.. Sorry for the uber long code.
- import ddf.minim.spi.*;
- import ddf.minim.signals.*;
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- import ddf.minim.ugens.*;
- import ddf.minim.effects.*;
- //import vialab.SMT.*;
- /*
- 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
- */
- import java.util.*;
- // we need to import the TUIO library
- // and declare a TuioProcessing client variable
- import TUIO.*;
- TuioProcessing tuioClient;
- //TuioProcessing tuioClient = new TuioProcessing(this);
- // these are some helper variables which are used
- // to create scalable graphical feedback
- float cursor_size = 15;
- float object_size = 60;
- float table_size = 760;
- float scale_factor = 1;
- PFont font;
- float x=0;
- float y=5;
- float c=200;
- float angle=0.0;
- //int d=0;
- //int t=1;
- //int siz=500;
- //int c=1;
- int rabbit = 150;
- int mice = 170;
- int goat = 200;
- int d=0;
- int t=1;
- int m=30/50;
- int happySound = 0;
- int sadSound = 0;
- int mysteriousSound = 0;
- int comfortableSound = 0;
- int curiousSound = 0;
- int lazySound = 0;
- int lostSound = 0;
- int specialSound = 0;
- int awesomeSound = 0;
- int x1= 0, y1 = 0;
- int orbitWith =300;
- int orbitHeight =300;
- int planetHeight = 50;
- int planetWith = 50;
- float planetAngle = 0;
- float inc = TWO_PI/360.0;
- boolean firstPlayThrough = false;//variable to check if song has played through the first time
- boolean sadPlayThrough = false;
- //BurstOfCircles circles;
- HashMap symbolMap = new HashMap();
- AudioPlayer mysterious;
- AudioPlayer happy;
- AudioPlayer awesome;
- AudioPlayer comfortable;
- AudioPlayer curious;
- AudioPlayer lazy;
- AudioPlayer lost;
- AudioPlayer sad;
- AudioPlayer special;
- Minim minim; //audio context
- void setup()
- {
- size(1024, 768);
- minim = new Minim(this);
- mysterious = minim.loadFile("mysterious.wav", 512);
- happy = minim.loadFile("happy.wav", 512);
- awesome = minim.loadFile("awesome.wav", 512);
- comfortable = minim.loadFile("comfortable.wav", 512);
- curious = minim.loadFile("curious.wav", 512);
- lazy = minim.loadFile("lazy.wav", 512);
- lost = minim.loadFile("lost.wav", 512);
- sad = minim.loadFile("sad.wav", 512);
- special = minim.loadFile("special.wav", 512);
- //circles = new BurstOfCircles();
- noStroke();
- fill(0);
- //background(0);
- smooth();
- //loop();
- frameRate(30);
- //noLoop();
- //hint(ENABLE_NATIVE_S);
- 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(0);
- textFont(font, 18*scale_factor);
- float obj_size = object_size*scale_factor;
- float cur_size = cursor_size*scale_factor;
- // sad.setGain(-80.0);
- // mysterious.play();
- // snare.play();
- // bass.play();
- // cym.play();
- //happy.play();
- // happy.setGain(-80.0);
- Vector tuioObjectList = tuioClient.getTuioObjects();
- for (int i=0;i<tuioObjectList.size();i++) {
- TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
- int FID = tobj.getSymbolID();
- float ANG = tobj.getAngle();
- // println("angle "+ tobj.getAngle());
- if (FID==1)
- {
- if (ANG>=0)
- {
- noStroke();
- fill(229, 93, 142, 30);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), goat, goat);
- goat = goat + 2;
- if (goat>300)
- {
- goat = 50;
- }
- fill(229, 93, 142, 50);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), mice, mice);
- mice = mice + 2;
- if (mice>300)
- {
- mice = 50;
- }
- fill(229, 93, 142, 100);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 50;
- }
- // happy.play();
- // happy.setGain(0.0);
- }
- if (ANG>1)
- {
- noStroke();
- fill(229, 93, 142, 50);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), goat, goat);
- goat = goat + 2;
- if (goat>300)
- {
- goat = 50;
- }
- fill(229, 93, 142, 70);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), mice, mice);
- mice = mice + 2;
- if (mice>300)
- {
- mice = 50;
- }
- fill(229, 93, 142, 120);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 50;
- }
- // happy.play();
- // happy.setGain(-15.0);
- }
- if (ANG>2)
- {
- noStroke();
- fill(229, 93, 142, 70);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), goat, goat);
- goat = goat + 2;
- if (goat>300)
- {
- goat = 50;
- }
- fill(229, 93, 142, 90);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), mice, mice);
- mice = mice + 2;
- if (mice>300)
- {
- mice = 50;
- }
- fill(229, 93, 142, 140);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 50;
- }
- // happy.play();
- // happy.setGain(-30.0);
- }
- if (ANG>3)
- {
- noStroke();
- fill(229, 93, 142, 30);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), goat, goat);
- goat = goat + 2;
- if (goat>300)
- {
- goat = 50;
- }
- fill(229, 93, 142, 50);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), mice, mice);
- mice = mice + 2;
- if (mice>300)
- {
- mice = 50;
- }
- fill(229, 93, 142, 100);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 50;
- }
- // happy.play();
- // happy.setGain(0.0);
- }
- happy.play();
- happy.setGain(0.0);
- firstPlayThrough = true;
- }
- if (FID==2)
- {
- ellipseMode(CENTER);
- noStroke();
- //pink
- fill(237, 26, 80, 180);
- ellipse(tobj.getScreenX(width)+100, tobj.getScreenY(height)+100, 80-d, 80-d);
- //yellow big back
- fill(255, 244, 83, 180);
- ellipse(tobj.getScreenX(width)+50, tobj.getScreenY(height)+50, 200-d, 200-d);
- //redish purple small behind center orange
- fill(169, 15, 43, 180);
- ellipse(tobj.getScreenX(width)-60, tobj.getScreenY(height)-60, 20+d, 20+d);
- //small yellow behind orange
- fill(255, 208, 61, 180);
- ellipse(tobj.getScreenX(width)-50, tobj.getScreenY(height)+70, 70-d, 70-d);
- //red between yellow and clack
- fill(193, 26, 27, 180);
- ellipse(tobj.getScreenX(width)-50, tobj.getScreenY(height)-30, 30+d, 30+d);
- //orange back
- fill(240, 73, 62, 180);
- int s=120+d;
- ellipse(tobj.getScreenX(width)-80, tobj.getScreenY(height), s, s);
- //yellow big right bottom
- fill(255, 208, 61, 180);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height)-30, 150+d, 150+d);
- //yellow right bottom front
- fill(255, 244, 83, 180);
- ellipse(tobj.getScreenX(width)-30, tobj.getScreenY(height), 70-d, 70-d);
- //pink
- fill(237, 26, 80, 180);
- ellipse(tobj.getScreenX(width)+100, tobj.getScreenY(height)+50, 80+d, 80+d);
- //orange behind red front
- fill(246, 134, 31, 180);
- ellipse(tobj.getScreenX(width)-10, tobj.getScreenY(height)-80, 30+d, 30+d);
- //red front
- fill(181, 23, 24, 180);
- ellipse(tobj.getScreenX(width)+80, tobj.getScreenY(height)-80, 170-d, 170-d);
- d=d+t;
- if (d==50|| d==0)
- {
- t=t*-1;
- }
- if (ANG>=0)
- {
- sad.play();
- sad.setGain(0.0);
- }
- if (ANG>1)
- {
- sad.play();
- sad.setGain(-20.0);
- }
- if (ANG>2)
- {
- sad.play();
- sad.setGain(-40.0);
- }
- sadPlayThrough = true;
- }
- if (FID==3)
- {
- fill(0, 1, 60, 20);
- noStroke();
- rect(0, 0, tobj.getScreenX(width), tobj.getScreenY(height));
- fill(66, 83, 140, 100);
- stroke(255, 40);
- //angle=angle+0.03;
- translate(50, 25);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rotate(angle);
- strokeWeight(.5);
- ellipse(tobj.getScreenX(width)-50, (tobj.getScreenY(height))-100, 50, 50);
- fill(178, 167, 224, 200);
- ellipse(tobj.getScreenX(width), (tobj.getScreenY(height)), 50, 50);
- fill(231, 101, 123, 100);
- ellipse((tobj.getScreenX(width))-100, tobj.getScreenY(height)-50, 50, 50);
- fill(244, 210, 191, 200);
- ellipse((tobj.getScreenX(width)), tobj.getScreenY(height), 50, 50);
- y+=10;
- if (y>tobj.getScreenY(height))
- {
- y=-tobj.getScreenY(height);
- }
- if (ANG>=0)
- {
- lost.play();
- lost.setGain(0.0);
- }
- if (ANG>1)
- {
- lost.play();
- lost.setGain(-20.0);
- }
- if (ANG>2)
- {
- lost.play();
- lost.setGain(-40.0);
- }
- lostSound = 1;
- }
- if (FID==4)
- {
- noStroke();
- fill (20, 40, 90, 20);
- for (int e = 20; e <= tobj.getScreenX(width); e+=30) {
- float w = random (e) -30;
- float h = w;
- ellipse (tobj.getScreenX(width), tobj.getScreenY(height) - 20, w, h);
- };
- for (int e = 20; e <= tobj.getScreenX(width); e+=10) {
- float w = random (e) -20;
- float h = w;
- ellipse (tobj.getScreenX(width), tobj.getScreenY(height) + 10, w, h);
- };
- fill(90, 15, 100, 60);
- for (int e = 20; e <=tobj.getScreenX(width); e+=40) {
- float w = random (e) -90;
- float h = w;
- ellipse (tobj.getScreenX(width), tobj.getScreenY(height) - 30, w, h);
- };
- fill(255, 120, 90, 30);
- for (int f = 20; f <=tobj.getScreenX(width); f+=40) {
- float w = random (f) -20;
- float h = w;
- ellipse (tobj.getScreenX(width), tobj.getScreenY(height)- 30, w, h);
- };
- if (ANG>=0)
- {
- curious.play();
- curious.setGain(0.0);
- }
- if (ANG>1)
- {
- curious.play();
- curious.setGain(-20.0);
- }
- if (ANG>2)
- {
- curious.play();
- curious.setGain(-40.0);
- }
- curiousSound = 1;
- }
- if (FID==5)
- {
- if (ANG>=0)
- {
- comfortable.play();
- comfortable.setGain(0.0);
- }
- if (ANG>1)
- {
- comfortable.play();
- comfortable.setGain(-20.0);
- }
- if (ANG>2)
- {
- comfortable.play();
- comfortable.setGain(-40.0);
- }
- comfortableSound = 1;
- }
- if (FID==6)
- {
- color orbitGreen = color(54, 224, 52, 50);
- color planetBlue = color(22.0, 34, 165, 200);
- color black = color(0, 0, 0);
- int planetX = tobj.getScreenX(width);
- int planetY = tobj.getScreenY(height);
- x1 = tobj.getScreenX(width);
- y1 = tobj.getScreenY(height);
- noStroke();
- fill(orbitGreen);
- ellipse(x1, y1, orbitWith+5, orbitWith+5);
- noStroke();
- fill(black);
- ellipse(x1, y1, orbitWith, orbitWith);
- planetAngle += inc;
- if (planetAngle == TWO_PI)
- {
- planetAngle = 0;
- }
- planetY = (int)(sin(planetAngle)*(orbitWith/2));
- planetX = (int)(cos(planetAngle)*(orbitWith/2));
- fill(planetBlue);
- ellipse(planetX+x1, planetY+y1, planetWith, planetWith);
- if (ANG>=0)
- {
- lazy.play();
- lazy.setGain(0.0);
- }
- if (ANG>1)
- {
- lazy.play();
- lazy.setGain(-20.0);
- }
- if (ANG>2)
- {
- lazy.play();
- lazy.setGain(-40.0);
- }
- lazySound = 1;
- }
- if (FID==7)
- {
- noStroke();
- fill(204, 102, 0, 100);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 0;
- }
- if (ANG>=0)
- {
- special.play();
- special.setGain(0.0);
- }
- if (ANG>1)
- {
- special.play();
- special.setGain(-20.0);
- }
- if (ANG>2)
- {
- special.play();
- special.setGain(-40.0);
- }
- specialSound = 1;
- }
- if (FID==8)
- {
- noStroke();
- fill(253, 206, 0, 100);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), rabbit, rabbit);
- rabbit = rabbit + 2;
- if (rabbit>300)
- {
- rabbit = 0;
- }
- if (ANG>=0)
- {
- awesome.play();
- awesome.setGain(0.0);
- }
- if (ANG>1)
- {
- awesome.play();
- awesome.setGain(-20.0);
- }
- if (ANG>2)
- {
- awesome.play();
- awesome.setGain(-40.0);
- }
- awesomeSound = 1;
- }
- if (FID==9)
- {
- x+=10;
- noStroke();
- fill(0, 102, 204, 100);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x, x);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x-80, x-80);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x-160, x-160);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x-240, x-240);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x-320, x-320);
- ellipse(tobj.getScreenX(width), tobj.getScreenY(height), x-400, x-400);
- if (x>=200)
- {
- x=-50;
- }
- if (ANG>=0)
- {
- mysterious.play();
- mysterious.setGain(0.0);
- }
- if (ANG>1)
- {
- mysterious.play();
- mysterious.setGain(-20.0);
- }
- if (ANG>2)
- {
- mysterious.play();
- mysterious.setGain(-40.0);
- }
- mysteriousSound = 1;
- }
- //ellipse(tobj.getScreenX(width),tobj.getScreenY(height), siz-d,siz-d);
- //d=d+t;
- //ellipse(tobj.getScreenX(width),tobj.getScreenY(height), 300, 300);
- stroke(0);
- fill(0, 0, 0, 50);
- 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, 102, 204, 150);
- // 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);
- // }
- // }
- }
- void stop()
- {
- mysterious.close();
- happy.close();
- awesome.close();
- comfortable.close();
- curious.close();
- lazy.close();
- lost.close();
- sad.close();
- special.close();
- minim.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.getSymbolID()+" ("+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.getSymbolID()+" ("+tobj.getSessionID()+")");
- if (firstPlayThrough = false) {
- happy.pause();
- }
- if (sadPlayThrough = false) {
- sad.pause();
- }
- }
- // 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();
- }
1