Var not iterating problem • Use all row values to iterate CSV column with for loop to playNote()

Hello Chrisir, thank you so much for your help. I have found your answers / help in many other google searches concerning questions I run into while coding :slight_smile:

I want to make sure I fully understand your solution, as I am in a learning process right now with Dan Shiffman’s “Learning Processing”. You implemented a timer so that you can keep track of time and control more precisely the speed of iteration at which the values are being feed from the CSV into the sketch? If the timer is true, then parse data from CSV into variables, and then use the changing value of that variable inside playNote(), am I understanding correctly? I have to leave the for loop as well inside the void loadData() ?

I modified the code as you suggested, removed the void loadData() from draw and only left it in its thread in setup, as I understand I want it to load the CSV file, independent of setup and draw, but the console printed the Runtime Error NullPointerException and the prog stops. The line that is highlighted in red is: TableRow row = seisCsv.getRow(i); inside void draw() I tried commenting out the lines of the the for loop that you directed me to put inside void draw(), but it gave me the same error. Here is my attempt at putting the code together. As you can see I am working with CSV data, but my final goal is to parse the data and sonify in realtime, through a realtime server Iris offers. As Dan’s book teaches, I am doing everything in small parts, so as to learn my way through the whole program.

import ddf.minim.Minim;
import ddf.minim.AudioOutput;

Table seisCsv;
AudioOutput out;
float freqValuesLoaded;
TableRow row;
int timer; 
int i;
boolean load=true;

void setup() {
  size(640, 480);
  thread("loadData");
  Minim minim = new Minim(this);
  out = minim.getLineOut();
}
void draw() {

  if (millis()-timer > 1000) {
    timer = millis();
    i++;
    load=true;
  }

  if (load) {
    TableRow row = seisCsv.getRow(i);
    freqValuesLoaded = row.getFloat(0);
    out.playNote(freqValuesLoaded);  // Variable from the loadData() that I need 
    println(freqValuesLoaded);            // to access to hear notes in realtime.
    load = false;
  }
}
void loadData() {
  seisCsv = loadTable("CU.SDDR.1_HOUR_BHZ.ascii_SLIST.csv", "header");
  freqValuesLoaded = 0;
  for (int i = 0; i < seisCsv.getRowCount(); i++) {
    TableRow row = seisCsv.getRow(i);
    freqValuesLoaded = row.getFloat(0);
  }
}

I did this math: as I have 1 HOUR of seismic data, which equals to 144001 time series (values), so In order to play the equivalent of the data as a full hour in sound, I divided 144,001/3600(secs in an hour) and the result is = 40.0, so the iteration has to move 40 fps to play the notes in realtime as they were captured.
Am I doing something wrong in terms of the flow of the program?

2 Likes