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 & HelpSyntax Questions › how to execute string
Page Index Toggle Pages: 1
how to execute string (Read 576 times)
how to execute string
Jan 26th, 2009, 9:51pm
 
Hi,

i get a string like "01" (02,03,04...). I would check if file 01.wav exist. Then I would like to start a new Player 01.wav. These commands would I write to a string and then execute. Is this possible in Processing?

Thank you,
Oli
Re: how to execute string
Reply #1 - Jan 26th, 2009, 11:46pm
 
That's not really "executing" a string, but using it.

To check if a file exists:
Code:
boolean DoesFileExist(String fileName)
{
 File f = new File(dataPath(fileName + ".wav"));
 return f.exists();
}

dataPath() returns the path of the file in the data folder of the sketch.
You can do the same to play it.
Re: how to execute string
Reply #2 - Feb 20th, 2009, 6:56am
 
but is it possible to execute a command like eval("string");
Re: how to execute string
Reply #3 - Feb 20th, 2009, 11:58am
 
I didn't write it isn't possible to execute strings, I wrote the explained usage isn't that.
Beside, I don't see an eval() function, you might be mixing with JavaScript or PHP... Smiley
Re: how to execute string
Reply #4 - Feb 21st, 2009, 11:59am
 
Yes shure there is no eval in processing
i just wanted somthing like a self writing programm
where i can generade code on th fly just like in scripting languages.
even if the program would have to write it to a file and execut it.

but i think it is not possible as far as i see whithout lots of conditions, matching up strings and trigering predefined functions whitch all have to be listed.
Re: how to execute string
Reply #5 - Feb 21st, 2009, 12:49pm
 
Java has a number of interpreted languages running on the JVM, from Java-like syntaxes (BeanShell aka. bsh, DynamicJava, etc.) to any exotic language (Kahlua uses the simple syntax of Lua and is very lightweight).
Integration to Processing might not be simple, but is doable, and probably much simpler than doing parsing yourself.

Note that Processing is an example of Java program compiling Java code (after some pre-processing) and running it on the fly.
Re: how to execute string
Reply #6 - Mar 3rd, 2009, 10:03pm
 
Hello PhiLho and meatless. Thank you for your support. Special thanks for the example. But how do I start a new player?

Best Regards,
Oli
Re: how to execute string
Reply #7 - Mar 4th, 2009, 1:29pm
 
check out this
http://processing.org/learning/libraries/loadfile.html

and you will need a library

http://code.compartmental.net/tools/minim/
there are instructions on how to install the library
i haven't checked it but just search for
play sound in Processing you are not the
first one trying this Smiley

i do not have the time to explain step by step but if you still need help, after trying to figure it out, let me know.

if you alrady are playing sounds then just assign a new variable to the file you want to play


 File f_1 = new File(dataPath(fileName1+ ".wav"));
File f_2 = new File(dataPath(fileName2+ ".wav"));


play f_1
and play f_2

or
File f= new File(dataPath(fileName1+ ".wav"));
play f
File f = new File(dataPath(fileName2+ ".wav"));
play f
Page Index Toggle Pages: 1