removing shreds by name from within chuck
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
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@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Spencer Salazar wrote:
Let me know if this is what you were going for, or if I am completely off track.
I ended up doing something along the lines of what you described, although quite a bit more elaborate. For instance it's paramount to me that I can get a list of patterns in my keyboard-loader-list along with the ascii code that is used to toggle it and some symbol showing if it's currently running. Basically I can live with what I have for now, and will wait and see what kinds of need functionality makes it's way into chuck in the next few releases before I start a wrapper in python. If possible I prefer a pure chuck solution... Thanks to the inputs! -- peace, love & harmony Atte http://www.atte.dk | quintet: http://www.anagrammer.dk | compositions: http://www.atte.dk/compositions
I ended up doing something along the lines of what you described, although quite a bit more elaborate. For instance it's paramount to me that I can get a list of patterns in my keyboard-loader-list along with the ascii code that is used to toggle it and some symbol showing if it's currently running.
Basically I can live with what I have for now, and will wait and see what kinds of need functionality makes it's way into chuck in the next few releases before I start a wrapper in python. If possible I prefer a pure chuck solution...
Hi, I'm very interested in your experiment: it would be very kind of you to post your code for managing chuck scripts. thanx -- _.|| _. _ _ \/\/(_|||(_|(_ (/_
Wallace wrote:
Hi, I'm very interested in your experiment: it would be very kind of you to post your code for managing chuck scripts.
Here it is. It's chunky, messy, ugly (although I just dressed it up a
bit for display), and what-not :-)
You have to change the key bindings to point to some files you actually
have on your hard drive. Besides that, the only thing to say is that
pressing "1" lists running patterns and "2" lists all key bindings,
those marked with a "+" are the ones running. Pressing a key a-z toggles
the pattern (adds/removes it from the chuck virtual machine) associated
with that key.
--
peace, love & harmony
Atte
http://www.atte.dk | quintet: http://www.anagrammer.dk
| compositions: http://www.atte.dk/compositions
class helpers {
256 => static int nb_chars;
new string[nb_chars] @=> static string char_map[];
"a" => char_map[97];
"b" => char_map[98];
"c" => char_map[99];
"d" => char_map[100];
"e" => char_map[101];
"f" => char_map[102];
"g" => char_map[103];
"h" => char_map[104];
"i" => char_map[105];
"j" => char_map[106];
"k" => char_map[107];
"l" => char_map[108];
"m" => char_map[109];
"n" => char_map[110];
"o" => char_map[111];
"p" => char_map[112];
"q" => char_map[113];
"r" => char_map[114];
"s" => char_map[115];
"t" => char_map[116];
"u" => char_map[117];
"v" => char_map[118];
"w" => char_map[119];
"x" => char_map[120];
"y" => char_map[121];
"z" => char_map[122];
fun static string keycode2ascii(int keycode){
if(keycode < nb_chars){
return char_map[keycode];
}
return "";
}
fun static int ascii2keycode(string ascii){
for(0=>int i; i
Here it is. It's chunky, messy, ugly (although I just dressed it up a bit for display), and what-not :-)
You have to change the key bindings to point to some files you actually have on your hard drive. Besides that, the only thing to say is that pressing "1" lists running patterns and "2" lists all key bindings, those marked with a "+" are the ones running. Pressing a key a-z toggles the pattern (adds/removes it from the chuck virtual machine) associated with that key.
thank you very much!! Your code should be included in chuck examples, I find it very useful: every chucker should have a copy of it :) cu -- _.|| _. _ _ \/\/(_|||(_|(_ (/_
Wallace wrote:
Your code should be included in chuck examples, I find it very useful:
Glad you found it useful. If the maintainers of the examples feel the same, I'd be honored to have it included:-) Maybe if added it would be nice with a small comment at the top, something like: /* keyboardLoader load/unload patterns with keystrokes written by Atte Jensen, 2006 */ -- peace, love & harmony Atte http://www.atte.dk | quintet: http://www.anagrammer.dk | compositions: http://www.atte.dk/compositions
participants (3)
-
Atte André Jensen
-
Spencer Salazar
-
Wallace