[minim] Playing an audio sample only once.

Hi, I've got an audio sample to trigger when a key is hit on the keyboard. But if I write the code in this way, it continuously plays during the time I hit the key but I want to trigger the sample only once, doesn't matter how long I hit the key. It seems the thing I need is a stop function but I couldn't figure out how I should write. Thanks.

Sample s;
import ddf.minim.*;
Minim soundengine;

void setup() {
  size(900, 600);
s = new Sample();
soundengine=new Minim(this);
}

void draw() {
  background(30);
  if (keyPressed) {
   kickvisual();
   }

  if (keyPressed) {
    s.play();
  }

void kickvisual() {
  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      cellCollection[i][j].run();
    }
  }
}
}

class Sample {
  AudioSample q1;

  Sample () {
    q1=soundengine.loadSample("kik.wav", 128);
  }
  void play() {
    keyPressed();
  }

  void keyPressed() 
  {
    if ( key == 'Q' ) q1.trigger();
  }
}

Answers

Sign In or Register to comment.