Lots of questions.
First: the if’s are wrong imo because you need to multiply the >= part as well by 2,3,4,5…
new version:
if (timeDiff < recTime) {
osc.freq(freqList[0]);
} else if (timeDiff >= recTime && timeDiff < recTime*2) {
osc.freq(freqList[1]);
} else if (timeDiff >= recTime*2 && timeDiff < recTime*3) {
osc.freq(freqList[2]);
} else if (timeDiff >= recTime*3 && timeDiff < recTime*4) {
osc.freq(freqList[3]);
} else if (timeDiff >= recTime*4 && timeDiff < recTime*5) {
osc.freq(freqList[4]);
} else if (timeDiff >= recTime*5 && timeDiff < recTime*6) {
osc.freq(freqList[5]);
}
Second: The else is wrong. The else would only be executed after all if’s failed but you want to execute file save after each event. So no else needed.
Wrapping it up
Here is an idea for your filenames using indexForFileNames:
int indexForFileNames=-1;
if (timeDiff < recTime) {
osc.freq(freqList[0]);
indexForFileNames=0;
} else if (timeDiff >= recTime && timeDiff < recTime*2) {
osc.freq(freqList[1]);
indexForFileNames=1;
} else if (timeDiff >= recTime*2 && timeDiff < recTime*3) {
osc.freq(freqList[2]);
indexForFileNames=2;
} else if (timeDiff >= recTime*3 && timeDiff < recTime*4) {
osc.freq(freqList[3]);
indexForFileNames=3;
} else if (timeDiff >= recTime*4 && timeDiff < recTime*5) {
osc.freq(freqList[4]);
indexForFileNames=4;
} else if (timeDiff >= recTime*5 && timeDiff < recTime*6) {
osc.freq(freqList[5]);
indexForFileNames=5;
}
// save
if (indexForFileNames>-1) {
// syntax: saveTable(table, filename)
saveTable(table, fileNames[indexForFileNames];
}
Chrisir