looping audio counter
in
Core Library Questions
•
1 year ago
I've attached my circles loop and apply to a counter. When you make the 21st click the 1st circle becomes the the new circle, always having no more than 20 onscreen. I want to avoid getting ("ArrayIndexOutOfBoundsException: 20)This works the way i want it to with the visuals. Here are my problems. I want the audio to follow the C counter class so that it will recycle sounds like it does circles. I also have been trying to find out how to make the audio trigger within the circle when the circle refreshes itself and grows big (I tried an "if/else" statement but it didn't seem to work.) Does anyone have some minum advice on how to do either of these?
- import ddf.minim.*;
- Minim minim;
- Blob[] b; //sets amount limit
- AudioPlayer[ ] a;
- int c = 0;
- void setup() {
- size (300, 500);
- minim = new Minim(this);
- a = new AudioPlayer[18];
- a[0] = minim.loadFile("Hobbits.wav");
- a[1] = minim.loadFile("Howard Dean.wav");
- a[2] = minim.loadFile("bigstick.wav");
- a[3] = minim.loadFile("bullshit.wav");
- a[4] = minim.loadFile("Bush.wav");
- a[5] = minim.loadFile("fac.wav");
- a[6] = minim.loadFile("fuck it.wav");
- a[7] = minim.loadFile("gotchya.wav");
- a[8] = minim.loadFile("ilikelakes.wav");
- a[9] = minim.loadFile("jackass.wav");
- a[10] = minim.loadFile("lefthand.wav");
- a[11] = minim.loadFile("lovewithyou.wav");
- a[12] = minim.loadFile("mama.wav");
- a[13] = minim.loadFile("maverick.wav");
- a[14] = minim.loadFile("moon.wav");
- a[15] = minim.loadFile("rouge.wav");
- a[16] = minim.loadFile("sexual.wav");
- a[17] = minim.loadFile("zen.wav");
- b = new Blob[21];//how many appear at once
- for ( int i=0; i < b.length; i ++ ) {
- b[i] = new Blob( random(width), random(height),
- 1, false, i, random (0, 255), random (0, 255), random (0, 255));
- }
- }
- void draw() {
- //frame
- fill( 90, 50 ); // black out last frame
- rect(0, 0, width, height);
- //body
- fill(0);
- beginShape();
- vertex(20, 30);
- bezierVertex( 22, 22, 26, 22, 30, 20);
- vertex(30, 20);//corner1
- vertex(270, 20);
- bezierVertex( 272, 22, 276, 20, 280, 30);
- vertex(280, 30);//corner2
- vertex(280, 470);
- bezierVertex( 279, 472, 275, 479, 270, 480);
- vertex(270, 480);//corner3
- vertex(30, 480);
- vertex(20, 470);//corner4
- endShape(CLOSE);
- for ( int i=0; i < b.length; i ++ ) {//loop for black .function references array from outside local?
- b[i].update(); //go to blob update
- }
- }
- void mousePressed() {
- if (mouseX> 20 && mouseX< 280 && mouseY>20 && mouseY< 480 ||
- mouseX> 9 && mouseX< 61 && mouseY> 459 && mouseY<491) {
- b[c].trigger(mouseX, mouseY);
- if (c == 20) {
- c = 0;
- }
- else {
- c++;
- }
- }
- }
- class Blob { //DEFINE CLASS
- float x, y;
- float big;
- boolean on;
- int num;
- float sp;
- float sp1;
- float sp2;
- Blob( float xTemp, float yTemp, float bigTemp, boolean onTemp,
- int numTemp, float splashTemp, float splash1Temp, float splash2Temp) { //CONSTRUCTOR
- x = xTemp; //makes variables able to function in coding
- y = yTemp;
- big = bigTemp;
- on = onTemp;
- num = numTemp;
- println(num);
- sp = splashTemp;
- sp1 = splash1Temp;
- sp2 = splash2Temp;
- }
- void trigger(int xTemp, int yTemp) {
- this.on = true;
- this.x = xTemp;
- this.y = yTemp;
- println(this);
- a[num].play();
- //a[num].loop();
- }
- void update() { //CLASS FUNCTIONALITY / METHODS
- if (this.on ==true) {
- frameRate (35);
- smooth();
- pushMatrix();
- translate(x, y); //use of variable
- if (big > 70) {
- big = 0;
- }
- big +=1;
- fill(sp, sp1, sp2, 180);
- stroke( 250, 60 );
- ellipse(0, 0, big, big);
- popMatrix();
- }
- fill(90, 90, 90);
- rect (10, 460, 50, 30);
- if (mouseX> 9 && mouseX< 61 && mouseY> 459 && mouseY<491) {
- fill (130, 130, 130);
- rect (10, 460, 50, 30);
- if (mousePressed) {
- fill (200, 200, 200);
- rect (10, 460, 50, 30);
- this.on = false; // only hides circles. DOES NOT reset count
- }
- }
- }
- }
- void stop() {
- // song.close();
- minim.stop();
- super.stop();
- }
- //NOTES
- //1. Make sounds activate with shape size
- //2. Make sounds reset the count when button pressed
- //3. Make array for storing sounds?
- //4, why does button count towards counter?
- //3. use image mask for bezier corner frame
1