How do I make sure only 1 audio file is played at a single time?

Im new to processing and im make a installation piece using processing and a makey makey my problem is that when you step on the mat it triggers 3-4 audio files at once.

here is my code currently

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer song1;
AudioPlayer song2;
AudioPlayer song3;
AudioPlayer song4;
AudioPlayer song5;
AudioPlayer song6;
AudioPlayer song7;
AudioPlayer song8;
AudioPlayer song9;
AudioPlayer song10;
float a;

void setup()
{
  background(0);
  size(100, 100);
  minim = new Minim(this);
  song1 = minim.loadFile("song1.mp3");
  song2 = minim.loadFile("song2.mp3");
  song3 = minim.loadFile("song3.mp3");
  song4 = minim.loadFile("song4.mp3");
  song5 = minim.loadFile("song5.mp3");
  song6 = minim.loadFile("song6.mp3");
  song7 = minim.loadFile("song7.mp3");
  song8 = minim.loadFile("song8.mp3");
  song9 = minim.loadFile("song9.mp3");
  song10 = minim.loadFile("song10.mp3");
}

void draw()
{
}
void mousePressed() {
  float a = int(random(9));
  print(a);
  if (a == 0) { 
    song1.play();
    song1.rewind();
  } else if (a == 1) { 
    song2.play();
    song2.rewind();
  } else if (a == 2) { 
    song3.play();
    song3.rewind();
  } else if (a == 3) { 
    song4.play();
    song4.rewind();
  } else if (a == 4) { 
    song5.play();
    song5.rewind();
  } else if (a == 5) { 
    song6.play();
    song6.rewind();
  } else if (a == 6) { 
    song7.play();
    song7.rewind();
  } else if (a == 7) { 
    song8.play();
    song8.rewind();
  } else if (a == 8) { 
    song9.play();
    song9.rewind();
  }else if (a == 9) { 
    song10.play();
    song10.rewind();
  };
}

Answers

Sign In or Register to comment.