Help with logic in saving tables

so my last (and working) draw() is the following. Thank you @Chrisir !!

void draw(){
  background(30);
  textSize(32);
  textAlign(CENTER, CENTER);
      
  if(runApp){
    text("Recording", width/2, height/2); 
    
    osc.amp(1);
    osc.play();

    int curTime = millis();
    int timeDiff = curTime - startTime;

    boolean saveThis = false; // tells the sketch to save  
    
    if (timeDiff < recTime) {      
      osc.freq(freqList[0]);
      indexForFileNames = 0;
    } else if (timeDiff >= recTime && timeDiff < recTime*2) {
      if (indexForFileNames == 0) saveThis = true;
      osc.freq(freqList[1]);
      indexForFileNames = 1;
    } else if (timeDiff >= recTime*2 && timeDiff < recTime*3) {
      if (indexForFileNames==1) saveThis = true;
      osc.freq(freqList[2]);
      indexForFileNames = 2;
    } else if (timeDiff >= recTime*3 && timeDiff < recTime*4) {
      if (indexForFileNames==2) saveThis = true;
      osc.freq(freqList[3]);
      indexForFileNames = 3;
    } else if (timeDiff >= recTime*4 && timeDiff < recTime*5) {
      if (indexForFileNames == 3) saveThis = true;
      osc.freq(freqList[4]);
      indexForFileNames = 4;
    } else if (timeDiff >= recTime*5 && timeDiff < recTime*6) {
      if (indexForFileNames == 4) saveThis = true;
      osc.freq(freqList[5]);
      indexForFileNames = 5;
    } else{
      if (indexForFileNames == 5) saveThis = true;
      indexForFileNames = 6;
    }
    
    // save
    if (saveThis && (indexForFileNames > 0)) {
      saveTable(table, fileNames[indexForFileNames-1] + ".csv");
      saveThis = false;

      if(indexForFileNames == 6){
        runApp = false;
        exit();
      }
        
    }
           
  }else
    text("Idle", width/2, height/2); 

}
3 Likes