We are about to switch to a new forum software. Until then we have removed the registration on this forum.
i have a csv file with 72 records in it. i want to display just 8 at a time, and when the arrow keys are pressed, RIGHT and LEFT, i want it to show the next 8. The following code works to a degree, but the results seem a bit random, it doesn't show the same result set every time. I should have 8 panes of 9 records. It shows 8 at a time okay, but depending on the LENGTH of the keypress, it skips ahead at different rates. I want it to show 8 different records on right arrow keypress, but it comes up with half the old screen and half new records mostly. How can I control this? Anyone shed some light? (resources down the bottom)
import processing.video.*;
//import ddf.minim.*;
//import ddf.minim.effects.*;
Movie mymovie;
Table myresource;
String Message;
PFont myfont;
int j;
int lines=0;
int count = 9;
int max=0;
void setup() {
size(660, 600);
frameRate(30);
background(0, 0, 102);
myfont = loadFont("DejaVu.vlw");
myresource = loadTable("neilyoung.csv", "header"); //load csv file
//println(myresource.getRowCount() + " total rows in table");
max= myresource.getRowCount();
fillshape(); // draw and colour the rectangle
loadMovie(); //load vid
}
void draw() {
if (mymovie.available() == true) {
mymovie.read();
}
image(mymovie, 200, 20, width/3, height/4); //display video
fill(102, 0, 51);
showRows(lines); //get records
KeyPressed();
}
void KeyPressed(){
float current = mymovie.time();
float entire = mymovie.duration();
if (keyPressed) {
if (key == 'f' || key == 'F') {
mymovie.jump(current + 12); //skip forward 12 seconds
}
else if (key == 'b' || key == 'B') {
mymovie.jump(current - 12); //skip back 12 seconds
}
else if (key == 'e' || key == 'E') {
mymovie.jump(entire); //jump to the end of the video
}
else if (key == 's' || key == 'S') {
mymovie.jump(0); //jump to the start of the video
}
else if (keyCode == RIGHT){
fillshape();
if (lines < (max-count)){
lines++;
//println(lines);
}
showRows(lines);
}
else if (keyCode == LEFT){
fillshape();
if (lines !=0){
lines--;
println(lines);
}
showRows(lines);
}
}
}
void showRows(int lines){
textFont(myfont, 22);
text("Neil Young Albums", 30, 220); //heading
int space = 27;
int countline = 0;
for (j = lines; j<max; j++){
TableRow row = myresource.getRow(j);
countline++;
int yr= row.getInt("year");
String art = row.getString("artist");
String tit = row.getString("title");
textFont(myfont, 16);
Message = str(yr) + " " + art + " " + tit + " ";
text(Message, 30, 250 + countline*space);
if(countline==count){
//println( j);
break;
}
}
}
void loadMovie(){
// Load and play the video
mymovie = new Movie(this, "harvestmoon.mp4");
mymovie.play();
}
void fillshape(){
//refill the orange rectangle where the albums go
fill(204, 102, 0);
rect(20, 180, 620, 400);
}
https://dropbox.com/s/q5shte9jxjtzaq4/DejaVu.vlw?dl=0
https://dropbox.com/s/vahfd41188mpanc/harvestmoon.mp4?dl=0
https://www.dropbox.com/s/7a7yj9b69hufzpx/neilyoung.csv?dl=0
Answers
please help i've only been using processing for 2 weeks!