[PD-cvs] externals/frankenstein Makefile, 1.4, 1.5 common.c, 1.9, 1.10 common.h, 1.9, 1.10
dmorelli
morellid at users.sourceforge.net
Tue Dec 6 01:34:09 CET 2005
Update of /cvsroot/pure-data/externals/frankenstein
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10900
Modified Files:
Makefile common.c common.h
Log Message:
finding rhythm functions ready
Index: Makefile
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile 4 Dec 2005 02:03:40 -0000 1.4
--- Makefile 6 Dec 2005 00:34:07 -0000 1.5
***************
*** 2,7 ****
#VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
! #PDPATH="H:\PureData\pd-0.38-3.msw\pd"
! PDPATH="C:\Documents and Settings\Davide\Documenti\personali\pd-0.38-3.msw\pd"
--- 2,7 ----
#VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
! PDPATH="H:\PureData\pd-0.38-3.msw\pd"
! #PDPATH="C:\Documents and Settings\Davide\Documenti\personali\pd-0.38-3.msw\pd"
Index: common.h
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** common.h 5 Dec 2005 18:08:53 -0000 1.9
--- common.h 6 Dec 2005 00:34:07 -0000 1.10
***************
*** 81,84 ****
--- 81,87 ----
static unsigned short int possible_denominators[] = {1,2,3,4,6,8,12,16,18,24,32};
+ // the minimum percentage for a beat to be considered part of the main rhythm
+ #define min_to_be_main_rhythm_beat 0.7
+
// this defines a space for rhythms, variations, transitions and representations
typedef struct t_rhythm_memory_representation t_rhythm_memory_representation;
***************
*** 107,110 ****
--- 110,116 ----
} ;
+ // define a return value to express "rhythm not found in this representation"
+ #define INVALID_RHYTHM 65535
+
// ------------------------------------------------ functions
***************
*** 141,144 ****
--- 147,153 ----
// --- memory representation of rhythms
+ // create an array of nodes (without arcs?) to express the beats in this rhythm (the noteon moments)
+ void create_array_beats(unsigned short int **this_array, t_rhythm_event *currentEvent);
+
// add an arc to this node
void add_t_rhythm_memory_arc(t_rhythm_memory_node *srcNode, unsigned short int dstNode);
***************
*** 148,154 ****
void create_rhythm_memory_representation(t_rhythm_memory_representation **this_rep, unsigned short int id);
- // define a return value to express "rhythm not found in this representation"
- #define INVALID_RHYTHM 65535
-
// add a new rhythm in the list of similar rhythms related to one main rhythm
// the sub id is auto-generated and returned
--- 157,160 ----
Index: common.c
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** common.c 5 Dec 2005 18:08:53 -0000 1.9
--- common.c 6 Dec 2005 00:34:07 -0000 1.10
***************
*** 336,339 ****
--- 336,364 ----
}
+ void create_array_beats(unsigned short int **this_array, t_rhythm_event *currentEvent)
+ {
+ unsigned short int *new_array;
+ t_rhythm_event *curr_event;
+ int i, maxi, startint;
+ maxi = possible_durations();
+ // allocate space for the nodes
+ new_array = (unsigned short int *) malloc(sizeof(unsigned short int) * maxi);
+ // set default values
+ for (i=0; i<maxi; i++)
+ {
+ new_array[i] = 0;
+ }
+ // set the actual data
+ curr_event = currentEvent;
+ while(curr_event)
+ {
+ startint = duration2int(curr_event->start);
+ new_array[startint]=1;
+ curr_event = curr_event->next;
+ }
+ *this_array = new_array;
+
+ }
+
// compares this rhythm to this representation
// and tells you how close it is to it
***************
*** 347,352 ****
t_duration tmp_dur, this_dur;
t_rhythm_event *curr_event;
! float this_weight_float;
! int i, max_i, int_from_dur, this_weight_int;
// check that the return values have been allocated
--- 372,382 ----
t_duration tmp_dur, this_dur;
t_rhythm_event *curr_event;
! float this_weight_float, average_weight, strong_ratio;
! int i, max_i, int_from_dur, this_weight_int, beats, strong_ok, strong_no;
! unsigned short int *src_rhythm_array, *tmp_rhythm_array;
! unsigned short int best_subid, curr_subid;
! float best_closeness, curr_closeness;
! int sub_ok, sub_no;
! t_rhythm_memory_element *possible_rhythms;
// check that the return values have been allocated
***************
*** 357,362 ****
--- 387,401 ----
}
+ max_i = possible_durations();
+ // create an array of bools
+ create_array_beats(&src_rhythm_array, src_rhythm);
+
// look the main table for closeness to the main rhythm
curr_event = src_rhythm;
+ beats=0;
+ strong_ok=0;
+ strong_no=0;
+ strong_ratio=0;
+ average_weight = 0;
while(curr_event)
{
***************
*** 364,384 ****
// get the weight of this beat
this_weight_int = this_rep->transitions[int_from_dur].weight;
! this_weight_float = (float) (((float) this_weight_int)/((float) this_rep->max_weight);
! // TODO
!
curr_event = curr_event->next;
}
-
// for each rhythm in the list
// count the number of identical nodes
// cound thenumber of different nodes
!
! // TODO
// return the better matching rhythm id
// and the closeness floats
! // TODO
}
--- 403,500 ----
// get the weight of this beat
this_weight_int = this_rep->transitions[int_from_dur].weight;
! this_weight_float = (float) ( ((float) this_weight_int) / ((float) this_rep->max_weight));
! average_weight += this_weight_float;
! beats++;
curr_event = curr_event->next;
}
+ // look all the representation's rhythm
+ // looking for strong beats corrispondance
+ for (i=0; i<max_i; i++)
+ {
+ if (this_weight_float > min_to_be_main_rhythm_beat)
+ {
+ this_weight_int = this_rep->transitions[i].weight;
+ this_weight_float = (float) (((float) this_weight_int) / ((float) this_rep->max_weight));
+ // this is a main rhythm beat
+ if (src_rhythm_array[i]>0)
+ {
+ // both playing
+ strong_ok++;
+ } else
+ {
+ // strong beat miss
+ strong_no++;
+ }
+ }
+ }
+
+ // this is the average weight of this rhythm in this representation
+ if (beats==0)
+ {
+ average_weight = 0;
+ } else
+ {
+ average_weight = (float) (average_weight / ((float) beats));
+ }
+ // ratio of corresponding strong beats..
+ // close to 0 = no corrispondance
+ // close to 1 = corrispondance
+ if (strong_no==0)
+ {
+ strong_ratio = 1;
+ } else
+ {
+ strong_ratio = (float) ( ((float) strong_ok) / ((float)strong_no) );
+ }
// for each rhythm in the list
// count the number of identical nodes
// cound thenumber of different nodes
! best_subid = curr_subid = INVALID_RHYTHM;
! best_closeness = curr_closeness = 0;
! possible_rhythms = this_rep->rhythms;
! while(possible_rhythms)
! {
! // create the table of this rhythm
! create_array_beats(&tmp_rhythm_array, possible_rhythms->rhythm);
! sub_ok = sub_no = 0;
! for (i=0; i<max_i; i++)
! {
! if (tmp_rhythm_array[i]>0 && src_rhythm_array[i]>0)
! {
! sub_ok++;
! } else if (tmp_rhythm_array[i]==0 && src_rhythm_array[i]==0)
! {
! // nothing important
! } else
! {
! sub_no++;
! }
! }
! if (sub_no == 0)
! {
! curr_closeness = 1;
! } else
! {
! curr_closeness = (float) ( ((float) sub_ok) / ((float) sub_no) );
! }
! if (curr_closeness > best_closeness)
! {
! best_closeness = curr_closeness;
! best_subid = possible_rhythms->id;
! }
! possible_rhythms = possible_rhythms->next;
! free(tmp_rhythm_array);
! }
// return the better matching rhythm id
// and the closeness floats
! *sub_id = best_subid;
! *sub_closeness = best_closeness;
! *root_closeness = strong_ratio;
!
! // free allocated memory
! free(src_rhythm_array);
}
***************
*** 391,405 ****
)
{
// for each element of the rep_list
! // TODO
!
! // invoke find_similar_rhythm_in_memory
!
! // TODO
!
! // return the cosest representation with its subrhythm and closeness values
- // TODO
}
--- 507,538 ----
)
{
+ unsigned short int best_id, curr_id, best_subid, curr_subid;
+ float best_closeness, curr_closeness, best_sub_closeness, curr_sub_closeness;
+ t_rhythm_memory_representation *this_rep;
+ best_closeness = curr_closeness = best_sub_closeness = curr_sub_closeness = 0;
+ best_id = curr_id = best_subid = curr_subid = INVALID_RHYTHM;
// for each element of the rep_list
+ this_rep = rep_list;
+ while(this_rep)
+ {
+ compare_rhythm_vs_representation(this_rep,
+ src_rhythm,
+ &curr_subid,
+ &curr_closeness,
+ &curr_sub_closeness);
+ if (curr_closeness > best_closeness)
+ {
+ best_closeness = curr_closeness;
+ best_id = this_rep->id;
+ best_sub_closeness = curr_sub_closeness;
+ best_subid = curr_subid;
+ }
+ }
! *id = best_id;
! *sub_id = best_subid;
! *root_closeness = best_closeness;
! *sub_closeness = best_sub_closeness;
}
More information about the Pd-cvs
mailing list