We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › keeping track of rotation, loading array from id3
Page Index Toggle Pages: 1
keeping track of rotation, loading array from id3 (Read 1096 times)
keeping track of rotation, loading array from id3
Jun 21st, 2009, 4:39pm
 
Hi - i'm really new to programming and have been studying processing during a short, intense summer session in school.

I may have gotten in over my head with my final project... i'm writing a program that automatically retrieves filenames and id3 info from mp3 files in the data folder, then displays the files as "song" objects onscreen in a "wheel".

pressing the right or left arrow keys rotate the wheel... and hopefully i can keep track of the rotation somehow, and when i click another key, using minim, it will play the "song" object in the lowest lowest position on the wheel, inside the red band. needless to say, it's really shaky right now and unfinished in several areas due to my noob skillz.
i'm using minim library
and
jorge cardoso's id3 library.

a couple of specific questions:
1) using an array i retrieved the filenames from the data folder, but from this, how would i load 3 arrays with id3 info (song,artist,album)for each file?
2) how would i better animate the rotation of the wheel form song object to song object? i'd like to do it where it stops at each object.

any help or comments would be much appreciated!

the comments i put on my code are for my lab partner....

the code:
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import jorgecardoso.processing.id3.*;

PFont f;
float r=180;//<--radius of song wheel.
int a; //<--this will count data files for use in other arrays.
float theta;  //<-- angle for rotating song wheel and songs, used in draw() and Song display()
float theta2; //<--angle of song wheel, used in draw().
float x;
float y;
//float amtLeft;
float amt;//Right;//<--used to increment theta.
float record;//Left;
//float recordRight;
String wrd="Song ";
String title;
String artist;
String album;
float angle;//<--this is the angle of the wheel divided by song objects.        
int count=0;

Song [] songs;//<--This is the Song Object I created.


void setup(){
ID3 id3 = new ID3(this);
frameRate(120);
 size(600,600,P3D);
 f=createFont ("Arial",12,true);//<--I'm not attached to this font/size at all.
           //The visual layout obviously can be developed.
java.io.File folder = new java.io.File(dataPath("")); // look in the data folder
java.io.FilenameFilter mp3Filter = new java.io.FilenameFilter() {// filter returns true if file's extension is .mp3)
 boolean accept(File dir, String name) {
   return name.toLowerCase().endsWith(".mp3");
 }
};
String[] filenames = folder.list(mp3Filter); // list the files in the data folder, passing the filter as parameter

println(filenames.length + " mp3 files in data folder");// get and display the number of mp3 files
for (int i = 0; i < filenames.length; i++) {
 id3.readID3(filenames[i]);
 
 a = i+1; //this specifies # of "Song" objects to create.
 String []titles = new String [a];
 String []artists = new String [a];
 String []albums = new String [a];
 println(filenames[i]);
 println(id3.songTitle);
 
 titles[i]=id3.songTitle;
 artists[i]=id3.artist;
 albums[i]=id3.album;
}
println(a);//so i could see the program was working.
songs = new Song [a];//creates an "a"-length array of "songs"
}

void draw(){
 theta2=PI*2;//a full circle
 angle=theta2/a;//the angle of the wheel between each "song"
 
 background(0);
 fill(255,0,0,153);
 rectMode(CENTER);
 rect(width/2, 3*height/4, width, 60);
 rotateX(.7);  //rotates the X axis to add 3D effect to wheel.
 translate(width/2,height/2);//moves 0,0 to center of the screen.
 rotate(theta); //theta is an angle that increases when key is pressed.
 rotate (angle+(PI/2));// sets up wheel so first song object is at bottom.
 for (int i=0; i<songs.length; i++){
   songs[i] = new Song (i+1);
   songs[i].move();
   songs[i].display();        //the real details are in the object code itself.
   
   count+=1; //for graphics equations of song Class
 
 
}

}
class Song{
 float num;

 Song(int tempNum){//This displays a song number for each song.  
   num=tempNum;      //i+1 is taken from the array to here,
                     // and then used in display function below.
 }
 
 void display(){//we may need to write a "song play" function.
   
   x=r*cos(theta2);//determines cartesian coordinates for x
   y=r*sin(theta2);//determines cartesian coordinates for y
   textFont (f);
   textAlign(CENTER);
   fill(255);
   rotate (-angle);
   pushMatrix();
   translate(x,y);
   rotate(-angle-(PI/2));//so 1st song object is initially at bottom of screen.
   rotate(angle*count+(PI*2/a));//adjusts angle to display "songs" upright.
   rotate(-theta); //adjusts songs accordingly when the wheel rotates.
   text(wrd+int(num),0,0);//displays "song"and song number onscreen at translated 0,0 coordinate.
   
   popMatrix();
 }
   
void move(){
 
 if (key == CODED){
   if (keyCode == LEFT){
       if (record>=angle){
         amt=0;
         
       }else {amt=(2*PI)/(3000*a);
     }
       theta+=amt;
       record+=amt;
       if (keyPressed){
         record=0;}
       }
     if (keyCode == RIGHT){
     if (record<=-angle){
       amt=0;
       
     }else {amt=(2*PI)/(3000*a);
     }
     theta-=amt;
     record-=amt;
     if (keyPressed){
       record=0;}
   }
 } if (theta>2*PI){
 theta=0;
}

}
}


Page Index Toggle Pages: 1