I have a simple processing question and i was wondering if anyone could help!
in
Contributed Library Questions
•
2 years ago
Im trying to create a program using processing and reactivision and i was wondering if anyone could help.
Basically the first step of the program is to display an image, (which i know how to do) and then i would like to play a sound when i show a fiducial symbol to the web camera (and i have code to that program too.)
What i don't know how to do is to make the pc only display the image until the user presses enter and then go to the program which recognises fiducial symbols and play a sound.
The Code i have is the following :
//This is the code which displays the image :
size(600,600);
PImage b;
b = loadImage("question1.jpg");
image(b, 0, 0);
//This is the code which recognises fiducial symbols and play a sound :
/**
* Sound1.pde
Shows how we can play sounds from within a processing sketch. Some AudioSamples are played using the trigger method.
Whether or not a soundplays is governed by the presence of a corresponding reactivision symbol.
The the frequency with which the sample repears is determined by the angle of the symbol.
Possible extensions:
Use the position of the reactivision symbol to control the volume of the corresponding sound.
*/
import ddf.minim.*;
import TUIO.*;
TuioProcessing tuioClient;
// Map to relate symbol IDs to the sounds they're associated with
HashMap symbolMap = new HashMap();
Minim minim;
PlayThing bd, bass, cym, snare;
class PlayThing{
AudioSample samp;
float period;
float lastTime=0;
boolean playing=false;
PlayThing(AudioSample s, float p){
samp=s;
period=p;
}
void play(){
if(playing){
// check whether it's time to play this sound
float now = millis();
if (now-lastTime>= period){
lastTime=now;
samp.trigger();
}
}
}
}
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
bd = new PlayThing(minim.loadSample("bdhh.aiff"), 1000);
snare = new PlayThing(minim.loadSample("snare.aiff"), 2000);
bass = new PlayThing(minim.loadSample("bass.aiff"), 1000);
cym = new PlayThing(minim.loadSample("cym.aiff"), 2000);
symbolMap.put(0, bd);
symbolMap.put(1, snare);
symbolMap.put(2, bass);
symbolMap.put(3, cym);
tuioClient = new TuioProcessing(this);
}
void draw()
{
background(0);
stroke(255);
bd.play();
snare.play();
bass.play();
cym.play();
}
void stop()
{
// always close Minim audio classes when you are done with them
bd.samp.close();
snare.samp.close();
cym.samp.close();
bass.samp.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) {
int id = tobj.getSymbolID();
if (symbolMap.containsKey(id)){
// start the plaything playing!
((PlayThing)(symbolMap.get(id))).playing=true;
}
}
// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
int id = tobj.getSymbolID();
if (symbolMap.containsKey(id)){
// stop the PayThing playing
((PlayThing)(symbolMap.get(id))).playing=false;
}
}
// called when an object is moved
void updateTuioObject (TuioObject tobj) {
float angle=tobj.getAngle();
float period= 100+(2000* angle / TWO_PI);
int id = tobj.getSymbolID();
if (symbolMap.containsKey(id)){
// change the time period
((PlayThing)(symbolMap.get(id))).period=period;
}
}
// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
}
// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
}
// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
}
// called after each message bundle
// representing the end of an image frame
void refresh(long timestamp) {
//redraw();
}
1