ArrayList problem

Hi there, I'm trying to do a sketch where "notes" (coloured balls) are created sampling an audio source. They should disappear after some time, and they do, but they appear and disappear a few times very quickly before disappearing definately, it's not smooth. I suspect there's something wrong with where I placed the remove(). This is my draw code and a separate method for creating the "notes", so that they appear in their correct frequency band:

ArrayList noteCollection = new ArrayList();

void draw() {  
  colorMode(RGB, 255);

  fft.forward(in.mix);

  filter.run(fft, runMode, bands);

  if ((runMode == 5)) {
    bandFiltering();
    create(); 

    pushMatrix();
    translate(width/2, height/2);
    background(0); 

    for (int i = 0; i < noteCollection.size (); i++) {

      Note note = (Note) noteCollection.get(i);
      note.run();

      if (note.timer == 0) {
        //println("Note removed");
        noteCollection.remove(note);
      }
    }
    popMatrix();
  }
}

void create() {
  pushMatrix();
  translate(width/2, height/2);

  for (int i = 0; i < 3; i++) {
    if (dominantFreq[1][i] > 2 ) {

      //Create a new  note
      int ellipseXMin = -width/2 + i * (width/3);
      int ellipseXMax = -width/2 + (i+1) * (width/3);
      int ellipseX = int(random(ellipseXMin, ellipseXMax));
      Vec3D origin = new Vec3D(ellipseX, 0, 0);

      //println("Note frequency " + dominantFreq[0][i] + " and note amplitude " +  dominantFreq[1][i]);
      //println("Note origin " + origin);

      Note note = new Note(origin, dominantFreq[0][i], dominantFreq[1][i], 10000);
      noteCollection.add(note);
    }
  }  

  popMatrix();
}

Any suggestions? I can't seem to figure this out by myself, anything will be appreciated.

Answers

Sign In or Register to comment.