# Help with array of mp3 files!

**URL:** <https://discourse.processing.org/t/help-with-array-of-mp3-files/33610>\
**Category:** Libraries\
**Created:** [November 19, 2021, 11:05am UTC](https://discourse.processing.org/t/help-with-array-of-mp3-files/33610 "2021-11-19T11:05:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elisabot](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@Elisabot](https://discourse.processing.org/u/Elisabot)\
**Post date:** [November 19, 2021, 11:05am UTC](https://discourse.processing.org/t/help-with-array-of-mp3-files/33610/1 "2021-11-19T11:05:28Z")

</div>

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;

}

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [November 19, 2021, 12:45pm UTC](https://discourse.processing.org/t/help-with-array-of-mp3-files/33610/2 "2021-11-19T12:45:01Z")

</div>

you probably want to use the [millis](https://processing.org/reference/millis_.html) function and create some variables to hold the current millis and the time of the last change so something like

```auto
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++;
}

```

---

<div class="post-metadata">

**Author:** ![Elisabot](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@Elisabot](https://discourse.processing.org/u/Elisabot)\
**Post date:** [November 19, 2021, 3:00pm UTC](https://discourse.processing.org/t/help-with-array-of-mp3-files/33610/3 "2021-11-19T15:00:48Z")

</div>

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