Hello there,
I wanted to share my code with you, I feel that there is something crucial that I have not understood keeping me from moving forward, so I ask for your help hoping that somebody shares with me their opinion and points me in the right direction. I am writing a simple synth using the Minim library, I am getting the values from a CSV that looks like this, it has only one column:
"TIMESERIES CU_SDDR_00_BHZ, 144001 samples, 40.00 sps, 2019-07-01T21:51:52.000000, SLIST, INTEGER, Counts"
1681
1613
1608
1663
Since the CSV is heavy, 144,001 lines, I am putting the function loadTable
in a separate thread
. When I do println(freqValuesLoaded)
at the end of the loop in the void loadData()
I can see the values of each row that I need iterating inside the console. But when I call the function in draw, and then right after calling the fund I try to println(freqValuesLoaded)
here, the value stays in the last row of the column. My goal is to use the dynamic, changing value of the global variable freqValuesLoaded
to put it into the playNote() like this playNote(freqValuesLoaded);
so that I can hear the notes changing with the frequency values from the CSV.
What I understood was that if a variable is global (variable scope) I could call the function in Draw, and right after use one of that function’s variables (updated) and since it is after I call the function, the value of the variable that I need would be updated and change in time, but I don’t understand what I am doing wrong.
Another alternative I tried was to make the function a return type, so that it would hand me the value of freqValuesLoaded
, but I was not able to get it to work.
Here is my code:
import ddf.minim.Minim;
import ddf.minim.AudioOutput;
Table seisCsv;
AudioOutput out;
float freqValuesLoaded;
TableRow row;
void setup() {
size(640, 480);
thread("loadData");
Minim minim = new Minim(this);
out = minim.getLineOut();
}
void draw() {
loadData();
out.playNote(freqValuesLoaded); // Variable from the loadData() that I need
println(freqValuesLoaded); // to access to hear notes in realtime.
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);
}
}
Thank you for taking the time of reviewing this.