[chuck-users] removing shreds by name from within chuck
Spencer Salazar
ssalazar at CS.Princeton.EDU
Mon Nov 27 01:46:37 EST 2006
Hi Atte,
ChucK's shred management functionality is still somewhat
underdeveloped at this stage. The full extent of what is possible is
detailed here:
http://chuck.cs.princeton.edu/doc/language/spork.html
But I think this is some interesting functionality that you've
suggested--ChucK could certainly use some more advanced shred
management utilities. Personally Id like to be able to rename
shreds, as I get sick of seeing a bunch of "spork~exp"'s.
However, I think that it is possible to accomplish what you are
trying to do with currently available functionality. Suppose we have
an array of of chuck files that are to be used in this system:
["vocals.ck", "guitar.ck", "bass.ck", "drums.ck" ] @=> string
filenames[];
Lets also have an associative array saying whether or not a file is
running; if it is running, the value of the array will be the shred
number. If not, the value will be 0.
int is_running[1];
E.g. is_running["vocals.ck"] will be 0 to start out with, and then
the shred number once it gets started. A bug in chuck behooves us to
have at least 1 iterative element in the array even if we are only
using the associative part.
Lets initialize the is_running array:
for( 0 => int i; i < filenames.cap(); i++ )
0 => is_running[filenames[i]];
Now, we can write your code from below like this:
if( is_running[filename] )
{
Machine.remove( is_running[filename] );
0 => is_running[filename];
}
else
{
Machine.add( filename ) => is_running[filename];
}
Let me know if this is what you were going for, or if I am completely
off track.
spencer
On Nov 26, 2006, at 3:45 PM, Atte André Jensen wrote:
> Hi
>
> I'm trying to write a little something that'll load/unload files from
> within chuck. I've assigned different filenames to each of the keys
> a-z
> and now when a key is pressed I want to:
>
> if(file_is_running(filename)){
> machine.remove(filename2id(filename));
> } else {
> machine.add(filename);
> }
>
> So basically: how do I figure out if a shred is running with a certain
> filename and how do I get the id? To be clear: This information is
> available in the terminal if I kick chuck with "chuck ^", but I
> want to
> access this information inside chuck...
>
> --
> peace, love & harmony
> Atte
>
> http://www.atte.dk | quintet: http://www.anagrammer.dk
> | compositions: http://www.atte.dk/
> compositions
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
More information about the chuck-users
mailing list