We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there ! I'm trying to create a launchpad with my webcam. I've found few things about how to use my webcam to switch on/off a kind of "virtual button" to play an audio file. And my problem is... I have no idea about how to assign each "virtual button" to an .mp3 file.
I think the problem is between lines 105 and 140... I'm HELPLESS !!
import processing.video.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.signals.*;
Capture cam;
Minim minim;
AudioPlayer player;
// Liste des samples //
AudioSample klaxon2;
AudioSample klaxon3;
AudioSample metro;
// Liste des samples //
AudioOutput out;
PImage img;
// Tracking vidéo //
import processing.video.*;
Capture video;
float txe = 0;
float tye = 0;
float alpha = 0.4;
int taille1 = 70 ;
int taille2 = 80 ;
int rouge = 10;
// Nombre de zones plus UNE !! //
zone_son[] lazone=new zone_son[3];
// Nombre de zones plus UNE !! //
float seuil=20;
boolean p=false;
void setup() {
size(displayWidth, displayHeight);
cam = new Capture(this);
cam.start();
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO);
img = loadImage("Plan.jpg");
// Mes samples
klaxon2 = minim.loadSample("klaxon2.mp3");
klaxon3 = minim.loadSample("klaxon3.mp3");
lazone[0]=new zone_son(80, 0, 80, 80, "C3");
lazone[1]=new zone_son(1200, 0, 80, 80, "klaxon2.mp3");
lazone[2]=new zone_son(80, 600, 80, 80, "klaxon3.mp3");
}
void draw() {
stroke(255);
fill(255);
text("Seuil : "+seuil,10,20);
image(img, 0, 0);
img.resize(width, height);
if (cam.available()) {
// Reads the new frame
cam.read();
scale(-1,1);
translate(-width, 0);
for (int i=0; i< lazone.length;i++) {
lazone[i].teste();
lazone[i].dessine();
lazone[i].joue();
}
}
}
// modifier le seuil avec les touches haut et bas //
void keyPressed(){
if(key==CODED){
if(keyCode==UP){
seuil+=1;
}
if(keyCode==DOWN){
seuil-=1;
}
seuil=constrain(seuil,10,40);
}
}
class zone_son {
int px, py, lx, ly;
String AudioSample;
String note;
boolean survol, joue;
zone_son(int px, int py, int lx, int ly, String AudioSample) {
this.px=px;
this.py=py;
this.lx=lx;
this.ly=ly;
this.AudioSample=AudioSample;
this.note=AudioSample;
survol=false;
joue=false;
}
void joue(){
if (survol==true && joue==false){
klaxon2.trigger();
joue=true;
}
else if (survol==false && joue==true){
joue=false;
}
}
void dessine() {
stroke(255, 0, 50);
if (survol==true){
fill(255, 0, 50);
}
else {
fill(0, 0, 0);
}
ellipse(px,py,lx,ly);
}
void teste() {
int presenceSum = 0;
for (int x=px; x < px+lx; x++) {
for (int y=py;y < py+ly;y++) {
color currColor = cam.pixels[(y*width)+x];
// Extract the red, green, and blue components of the current pixel’s color
int cR = (currColor >> 16) & 0xFF;
int cG = (currColor >> 8) & 0xFF;
int cB = currColor & 0xFF;
presenceSum += cR + cG + cB;
}
}
if (presenceSum/100000.0 > seuil) {
survol=true;
}
else {
survol=false;
}
}
}
void stop()
{
out.close();
minim.stop();
player.close();
klaxon2.close();
klaxon3.close();
super.stop();
}
IF you have any idea, you are welcome, THX.