Update of /cvsroot/pure-data/externals/frankenstein In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21083
Modified Files: GArhythm.c chords_memory.c harmonizer.c rhythms_memory.c Log Message: fixing things
Index: harmonizer.c =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/harmonizer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** harmonizer.c 18 Oct 2005 23:10:53 -0000 1.1 --- harmonizer.c 8 Dec 2005 16:31:10 -0000 1.2 *************** *** 264,268 **** // i go up rnd = rand()/((double)RAND_MAX + 1); ! steps = rnd * 5; // how many step (good notes) will I ignore? note = insertpoint + steps; if (note >= POSSIBLE_NOTES) --- 264,268 ---- // i go up rnd = rand()/((double)RAND_MAX + 1); ! steps = rnd * 5; // how many steps (good notes) will I ignore? note = insertpoint + steps; if (note >= POSSIBLE_NOTES) *************** *** 273,277 **** // i go down rnd = rand()/((double)RAND_MAX + 1); ! steps = rnd * 5; // how many step (good notes) will I ignore? note = insertpoint - steps; if (note < 0) --- 273,277 ---- // i go down rnd = rand()/((double)RAND_MAX + 1); ! steps = rnd * 5; // how many steps (good notes) will I ignore? note = insertpoint - steps; if (note < 0) *************** *** 296,299 **** --- 296,301 ---- { int i, j, tmp, res, last, avgHI, avgLOW; + short int chord_notes[4]; + short int chord_notes_ok[4]; short int transitions[VOICES]; short int directions[VOICES]; *************** *** 435,438 **** --- 437,475 ---- // TODO: is a complete chord? + // does this voicing have all 5 notes? + // first build a table for comparision + for (i=0; i<4; i++) + { + chord_notes[i] = (x->target_notes[i]) % 12; + chord_notes_ok[i] = 0; + } + for (i=0; i<VOICES; i++) + { + tmp = notes[i] % 12; + for (j=0; j<4; j++) + { + if (chord_notes[j] == tmp) + chord_notes_ok[j]++; + } + } + // now in chord_notes_ok i have the number of times each note is present + if (chord_notes_ok[0] == 0) + { + // no fundamental! this is bad!! + res -= 5; + } + if ((chord_notes_ok[0] != 0) && + (chord_notes_ok[2] != 0) && + (chord_notes_ok[3] != 0) && + (chord_notes_ok[4] != 0)) + { + // complete chord! this is good + res += 5; + } + for (j=0; j<4; j++) + { + res -= 2^chord_notes_ok[j]; + } + res += 2*VOICES;
// penalize too many basses *************** *** 452,455 **** --- 489,493 ---- }
+ if (DEBUG_VERBOSE) post("fitness is %i", res);
Index: rhythms_memory.c =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/rhythms_memory.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** rhythms_memory.c 8 Dec 2005 01:29:55 -0000 1.3 --- rhythms_memory.c 8 Dec 2005 16:31:10 -0000 1.4 *************** *** 183,187 **** time_t a; t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class); ! x->l_out = outlet_new(&x->x_obj, "list"); x->seq_initialized = 0; --- 183,187 ---- time_t a; t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class); ! x->l_out = outlet_new(&x->x_obj, &s_list); x->seq_initialized = 0;
Index: GArhythm.c =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/GArhythm.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GArhythm.c 18 Oct 2005 23:10:53 -0000 1.1 --- GArhythm.c 8 Dec 2005 16:31:10 -0000 1.2 *************** *** 42,46 **** float prob_mutation; char last[BUFFER_LENGHT]; ! } t_GArhythm;
--- 42,47 ---- float prob_mutation; char last[BUFFER_LENGHT]; ! int reinsert_src; ! int reinsert_last; } t_GArhythm;
*************** *** 73,76 **** --- 74,144 ---- ); } + + } + + void GArhythm_reinit_pop(t_GArhythm *x) + { + int i, j, vecsize, ntot, tmp, me; + float prob, variatore; + t_garray *arysrc_strum1; + t_garray *arysrc_strum2; + t_garray *arysrc_strum3; + t_garray *arysrc_strum4; + t_float *vecsrc_strum1; + t_float *vecsrc_strum2; + t_float *vecsrc_strum3; + t_float *vecsrc_strum4; + + // load tables + + if (!(arysrc_strum1 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum1, garray_class))) + { + pd_error(x, "%s: no such array", x->x_arrayname_src_strum1->s_name); + } + else if (!garray_getfloatarray(arysrc_strum1, &vecsize, &vecsrc_strum1)) + { + pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum1->s_name); + } + else if (!(arysrc_strum2 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum2, garray_class))) + { + pd_error(x, "%s: no such array", x->x_arrayname_src_strum2->s_name); + } + else if (!garray_getfloatarray(arysrc_strum2, &vecsize, &vecsrc_strum2)) + { + pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum2->s_name); + } + else if (!(arysrc_strum3 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum3, garray_class))) + { + pd_error(x, "%s: no such array", x->x_arrayname_src_strum3->s_name); + } + else if (!garray_getfloatarray(arysrc_strum3, &vecsize, &vecsrc_strum3)) + { + pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum3->s_name); + } + else if (!(arysrc_strum4 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum4, garray_class))) + { + pd_error(x, "%s: no such array", x->x_arrayname_src_strum4->s_name); + } + else if (!garray_getfloatarray(arysrc_strum4, &vecsize, &vecsrc_strum4)) + { + pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum4->s_name); + } + + for (i=0; i<MAX_POPULATION; i++) + { + for (j=0; j<BUFFER_LENGHT; j++) + { + char c = 0x00; + if (vecsrc_strum1[j]) + c = c | 0x01; + if (vecsrc_strum2[j]) + c = c | (0x01 << 1); + if (vecsrc_strum3[j]) + c = c | (0x01 << 2); + if (vecsrc_strum4[j]) + c = c | (0x01 << 3); + x->population[i][j]=c; + } + } }
*************** *** 317,321 **** // uccido a caso REINSERT_SRC elementi e inserisco il ritmo src al loro posto ! for (i=0; i<REINSERT_SRC; i++) { rnd = rand()/((double)RAND_MAX + 1); --- 385,389 ---- // uccido a caso REINSERT_SRC elementi e inserisco il ritmo src al loro posto ! for (i=0; i<x->reinsert_src; i++) { rnd = rand()/((double)RAND_MAX + 1); *************** *** 336,340 **** } // uccido a caso REINSERT_LAST elementi e inserisco il last al loro posto ! for (i=0; i<REINSERT_LAST; i++) { rnd = rand()/((double)RAND_MAX + 1); --- 404,408 ---- } // uccido a caso REINSERT_LAST elementi e inserisco il last al loro posto ! for (i=0; i<x->reinsert_last; i++) { rnd = rand()/((double)RAND_MAX + 1); *************** *** 479,482 **** --- 547,601 ---- }
+ static void GArhythm_reinsert_src_set(t_GArhythm *x, t_floatarg f) + { + if (f>=0) + x->reinsert_src = (int) f; + } + + static void GArhythm_reinsert_last_set(t_GArhythm *x, t_floatarg f) + { + if (f>=0) + x->reinsert_last = (int) f; + } + + static void GArhythm_prob_crossover_set(t_GArhythm *x, t_floatarg f) + { + if (f<=1 && f>=0) + x->prob_crossover = f; + } + + static void GArhythm_prob_mutation_set(t_GArhythm *x, t_floatarg f) + { + if (f<=1 && f>=0) + x->prob_mutation = f; + } + + static void GArhythm_help(t_GArhythm *x) + { + post(""); + post(""); + post("GArhythm"); + post(""); + post("a rhythm generator/variatior that uses co-evolving Genetic Algorithms"); + post("at the moment it only works with 16 step measure, 1 measure rhythms, it needs 4 arrays as input rhythms and outputs its rhythms on 4 arrays"); + post(""); + + post("global usage hints"); + post("you must provide 8 arguments: the first 4 are the names of arrays with src rhythms, the second 4 are names of arrays where GArhythm will put its output"); + post("send a bang each time you want a new population (and a new rhythm) to be evaluated"); + post(""); + post("available commands"); + post("reinit: initialize the population with the content of the src arrays"); + post("variazione float: sets the index of wanted variation between the last proposed rhythm and the next one (from 0 to 1)"); + post("aderenza float: sets the index of wanted closeness between the current src rhythm and proposed one (from 0 to 1)"); + post("riempimento float: set 0 if you want sparse rhythms, 1 if you want a rhythm full of events"); + post("reinsert_src int: how many times the src rhythms will be randomly copied in the population before breeding"); + post("reinsert_last int: how many times the last rhythms will be randomly copied in the population before breeding"); + post("prob_crossover float: sets the crossover probability. default is %f", DEF_PROB_CROSSOVER); + post("prob_mutation float: sets the mutation probability, default is %f", DEF_PROB_MUTATION); + + } + + static void *GArhythm_new(t_symbol *s, int argc, t_atom *argv) { *************** *** 490,493 **** --- 609,614 ---- x->prob_crossover = DEF_PROB_CROSSOVER; x->prob_mutation = DEF_PROB_MUTATION; + x->reinsert_src=REINSERT_SRC; + x->reinsert_last=REINSERT_LAST;
*************** *** 537,539 **** --- 658,666 ---- class_addmethod(GArhythm_class, (t_method)GArhythm_riempimento_set, gensym("riempimento"), A_DEFFLOAT, 0); class_addmethod(GArhythm_class, (t_method)GArhythm_aderenza_set, gensym("aderenza"), A_DEFFLOAT, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_reinit_pop, gensym("reinit"), 0, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_reinsert_src_set, gensym("reinsert_src"), A_DEFFLOAT, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_reinsert_last_set, gensym("reinsert_last"), A_DEFFLOAT, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_prob_crossover_set, gensym("prob_crossover"), A_DEFFLOAT, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_prob_mutation_set, gensym("prob_mutation"), A_DEFFLOAT, 0); + class_addmethod(GArhythm_class, (t_method)GArhythm_help, gensym("help"), 0, 0); }
Index: chords_memory.c =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/chords_memory.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** chords_memory.c 6 Dec 2005 12:08:28 -0000 1.5 --- chords_memory.c 8 Dec 2005 16:31:10 -0000 1.6 *************** *** 100,104 ****
! #define DEBUG 1 // messaggi di debug #define DEBUG_VERBOSE 0 // messaggi di debug
--- 100,104 ----
! #define DEBUG 0 // messaggi di debug #define DEBUG_VERBOSE 0 // messaggi di debug