Help with array of mp3 files!

Hi!
I’m creating a proccesing code, that ads a voice to a choir every time the mouse is clicked (soundfiles being played simultaneously), this part works fine. The problem is, that I want to include some sort of timer that checks if the mouse has not been clicked for 15 sec. and then removes a voice if this is true. So in other words, a voice is added everytime someone clicks, BUT a voice is removed every 15 sec that goes by where the mouse has not been clicked.
UPDATE: I got the code to print “one more voice” when its supposed to remove a voice, so i have the time perspective somewhat figured out, but where in the code am i supposed to actually remove a soundfile?

I’m very new to coding, so all help would be appreciated!

This is the code so far:

import processing.sound.*;

// Load a soundfile
//List the mp3-files from your data folder here. There can be as few and as many as you’d like
String [] compositionFiles = {“kor1”,“kor2”,“kor3”,“kor4”};
int numtracks = compositionFiles.length;
int j;
int sec;
//Sound library doesn’t like when volume is at 0, so we set minimum volume to very, very close to 0 instead.
float minVolume = 0.00001;

//Create an array of SoundFiles. This array is a long as the list of files listed above due to the numTracks variable
SoundFile[] sounds = new SoundFile[numtracks];

SoundFile soundfile;

void settings() {
size(800, 600);
for (int i = 0; i < numtracks; i++) {
sounds[i] = new SoundFile(this, compositionFiles[i] + “.mp3”);
}

}

void setup() {

background(255);

for (int i = 0; i < numtracks; i++) {
sounds[i].loop();
sounds[i].amp(minVolume);
}
}

void draw() {

print("J equals: ");
println(j);
println(sec);
println(millis()/1000);
if((sec + 15) == millis()/1000){
println(“One more voice”);
}

}

void mouseClicked() {
if( j < numtracks){
sounds[j].amp(1);
j++;
}else{
for (int i = 0; i < numtracks; i++) {
sounds[i].amp(minVolume);
}
j = 0;
}
sec = millis()/1000;

}

you probably want to use the millis function and create some variables to hold the current millis and the time of the last change so something like

int currentTime;
int timeSinceLastChange;
int trackCount = 0;
void setup() {
  timeSinceLastChange = 0;
  
}

void draw() {
  background(240);
  currentTime = millis();
  if(currentTime - timeSinceLastChange > 10000 && trackCount > 0) {
    trackCount--;
    timeSinceLastChange = currentTime;
  }
  
  float textWidthHalf = textWidth(str(trackCount)) / 2;
  fill(0);
  text(trackCount, width / 2 - textWidthHalf, height / 2);
}

void mouseClicked() {
  trackCount++;
}

Thank you, I’m quite new with coding, so unfortunately I can’t figure out how to incorporate this as a solution :slight_smile: