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 & HelpSound,  Music Libraries › Ess library filepath question.
Page Index Toggle Pages: 1
Ess library filepath question. (Read 1476 times)
Ess library filepath question.
Mar 4th, 2007, 11:03pm
 


In the Ess library example below the "new channel" instance called myChannel is taking in a file at a set location.(ie. C drive.) Instead of having a set path to a file i am tryin to put in a file instance called by a GUI.everything in the GUI seems fine but when i try change the command path here to a file instance it says "the constructor AudioChannel(File) is undefined" ...does anyone know how to have a file set instead of a path??







// Example by Krister Olsson

import krister.Ess.*;

AudioChannel myChannel;
FFT myFFT;

void setup() {
 size(256,200);

 // start up Ess
 Ess.start(this);

   myChannel=new AudioChannel("C:/counting.aiff");

 // we just want the level, so we pass nothing
 myFFT=new FFT();
 
 // start the sound looping forever
 myChannel.play(Ess.FOREVER);
}

void draw() {
 // set the background color to a shade of blue based on the level
 int bgdColor=(int)(myFFT.getLevel(myChannel)*255);
 
 background(bgdColor,bgdColor,255);
}

// we are done, clean up Ess

public void stop() {
 Ess.stop();
 super.stop();
}









Re: Ess library filepath question.
Reply #1 - Mar 6th, 2007, 11:00pm
 
I haven't used it, but according to the Ess documentation (at http://www.tree-axis.com/Ess/AudioChannel/AudioChannel.html) the AudioChannel(filename) constructor is expecting a String object rather than a File object as its parameter.  If you are starting with a Java File object, you can convert it to String like so:

Code:
   myFile = new File("path/to/file.aiff");
myChannel=new AudioChannel(myFile.toString());

Hope this helps!

-Matt
Re: Ess library filepath question.
Reply #2 - Mar 7th, 2007, 8:46am
 
toString will work, but it's not really ment for getting the Files path. use this:

File myFile;
// myFile = new File( ... );
String myFilePath = myFile.getPath();

here's more:
http://java.sun.com/j2se/1.3/docs/api/java/io/File.html

(java reference is your friend!)

F
Re: Ess library filepath question.
Reply #3 - Mar 7th, 2007, 3:13pm
 
Thanks..i sorted that. Smiley
Re: Ess library filepath question.
Reply #4 - Mar 7th, 2007, 3:17pm
 
getAbsolutePath() will give more consistent results, because getPath() only uses information that's encoded in the File object, meaning that a relative path will still be relative.
Re: Ess library filepath question.
Reply #5 - Mar 7th, 2007, 4:38pm
 
File.toString() and File.getPath() are actually the same thing, according to the Java doc, which says that toString()

Quote:
Returns the pathname string of this abstract pathname. This is just the string returned by the getPath() method.

Ben has a good point; using the absolute path is a good idea.  I'm not sure how GUI.everything works, but presumably it will return a useable path.

Neo_proc: use whatever works!  You've probably already moved on and now we're just babbling to each other about the fine points of Java here.
Re: Ess library filepath question.
Reply #6 - Mar 7th, 2007, 6:52pm
 
as i said..its sorted.
Page Index Toggle Pages: 1