FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   eval? (at least, that was it in flash)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: eval? (at least, that was it in flash)  (Read 260 times)
elbucanero


eval? (at least, that was it in flash)
« on: Apr 22nd, 2004, 7:41pm »

Hey all,
 
I've got a little problem. I've made some sonia samples, named a,w,s and d. The idea is to link em to the keys.
So when i press a, i want to hear sample a.
I'd prefer to do this dynamicly instead of writing an if statement for each key.
 
something like [key].setVolume(1)
 
any ideas?
 
Thanks,Tim
 
JohnG

WWW
Re: eval? (at least, that was it in flash)
« Reply #1 on: Apr 23rd, 2004, 10:44am »

You can't do it that specific way in Java.
 
One way to do it would to be to create an array of samples, say 128 of them:
 
(I don't know the sonia keywords, so I'm guessing here)
 
SoniaSample[] Sounds=new SoniaSample[128];
 
Sounds['a']=LoadSound("whatever");
Sounds['w']=...
etc
 
Then have:
 
if(keypressed)
{
  Sounds[key].setVolume(1);
}
 
In this way the key you press is used as the index into the array of sounds, which works because you can use "key" as an int.
 
However, this method isn't very efficient, you have 124 unused samples sitting around.
 
elbucanero


Re: eval? (at least, that was it in flash)
« Reply #2 on: Apr 23rd, 2004, 11:52am »

I managed to do it without eval
I made a few arrays, one with the keycodes of the keys i want to use, and i combined that with an array that checks if a key is toggled.
 
Great my first real processing thing is done
Cant show you alas, its on my internetless laptop at the moment.
And it really aint that spectacular either
 
Thanks
Tim
 
Pages: 1 

« Previous topic | Next topic »