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 id;
"" => filename;
}
}
class patterns{
200 => static int nb_patterns;
new pattern[nb_patterns] @=> static pattern running_patterns[];
fun void add(string filename){
for(0=>int i; i int id;
id => running_patterns[i].id;
filename => running_patterns[i].filename;
nb_patterns => i;
}
}
}
fun void remove(string filename){
for(0=>int i; i i;
}
}
}
fun int is_running(string filename){
for(0=>int i; i filename;
0 => keycode;
}
fun void print(){
<<>>;
}
}
class key_bindings{
200 => static int max_bindings;
new key_binding[max_bindings] @=> static key_binding key_binding[];
fun static void print(){
for(0=>int i;iint i;i key_binding[i].keycode;
filename => key_binding[i].filename;
max_bindings => i;
}
}
}
fun static void remove_by_keycode(int keycode){
for(0=>int i;iint i;iint i;iint i;i static key_bindings @ key_bindings;
new patterns @=> static patterns @ patterns;
fun static void add_key_binding(int keycode, string filename){
key_bindings.add(keycode, filename);
}
fun static void add_key(string ascii, string filename){
add_key_binding(helpers.ascii2keycode(ascii),filename);
}
fun static void add(string filename){
patterns.add(filename);
}
fun static void print_possible(){
<<<"-- key bindings --">>>;
for(0=>int i;i string filename;
if(filename != ""){
key_bindings.key_binding[i].keycode => int keycode;
helpers.keycode2ascii(keycode) => string ascii;
if(patterns.is_running(filename)){
<<<"+",ascii,filename>>>;
}
else {
<<<" ",ascii,filename>>>;
}
}
}
}
fun static void print_running(){
<<<"-- running patterns --">>>;
for(0=>int i;i string filename;
if(filename != ""){
key_bindings.key_binding[i].keycode => int keycode;
helpers.keycode2ascii(keycode) => string ascii;
if(patterns.is_running(filename)){
<<>>;
}
}
}
}
fun void listen(){
KBHit kb;
while(true){
kb => now;
while(kb.more()){
kb.getchar() => key;
keyin.broadcast();
key_bindings.keycode2filename(key) => string filename;
if(filename != ""){
toggle_load(filename);
} else
// pressing 1 will display running patterns
if (key == 49){
print_running();
}
else
// pressing 2 wll display all keybindings
if (key == 50){
print_possible();
}
}
}
}
fun void toggle_load(string filename){
if(filename != ""){
if(patterns.is_running(filename)){
patterns.remove(filename);
}
else {
patterns.add(filename);
}
print_possible();
}
}
}
keyboardLoader key_load;
key_load.add_key("a","patterns/rhodes.ck");
key_load.add_key("b","patterns/bass_moog_16.ck");
key_load.add_key("c","patterns/hh_ultra.ck");
key_load.add_key("d","patterns/sine_penta_16.ck");
key_load.add_key("e","patterns/bd_deep_4.ck");
key_load.add_key("f","patterns/reverse_noise.ck");
key_load.add_key("g","patterns/sh.ck");
key_load.add_key("h","patterns/laser.ck");
key_load.add_key("i","patterns/moog_melody_random.ck");
key_load.add_key("j","patterns/modulating_sines.ck");
key_load.add_key("k","patterns/noise_perc_16.ck");
key_load.add_key("l","patterns/sandpaper_16.ck");
key_load.add_key("m","patterns/breakbeat_breezing.ck");
key_load.add_key("n","patterns/breakbeat_god_made_me_funky.ck");
key_load.add_key("o","patterns/breakbeat_de_la_soul.ck");
key_load.add_key("p","patterns/breakbeat_substitution.ck");
key_load.add_key("q","patterns/bass_fm_8.ck");
key_load.add_key("r","patterns/bass_tri_random_16.ck");
key_load.add_key("s","patterns/cabassa_16.ck");
key_load.add_key("t","patterns/pad_ob_triad_16.ck");
key_load.add_key("u","patterns/reverse_chord.ck");
spork ~ key_load.listen();
10::ms => now;
key_load.print_possible();
1::week => now;