Update of /cvsroot/pure-data/externals/frankenstein
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31920
Modified Files:
common.c common.h
Log Message:
almost ready with common functions for rhythms
Index: common.h
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** common.h 4 Dec 2005 02:03:40 -0000 1.7
--- common.h 5 Dec 2005 12:57:39 -0000 1.8
***************
*** 1,2 ****
--- 1,3 ----
+
// here i put common data structures and functions
***************
*** 89,103 ****
t_rhythm_event *rhythm; // this rhythm
t_rhythm_memory_element *next; // next element of the list
} ;
// a rhythm in memory, each rhythm is :
- // - a main rhythm
// - its probability transition table
// - similar rhythms played
struct t_rhythm_memory_representation
{
- t_rhythm_memory_element *main_rhythm;
t_rhythm_memory_node *transitions;
unsigned short int max_weight;
! t_rhythm_memory_element *similar_rhythms;
} ;
--- 90,108 ----
t_rhythm_event *rhythm; // this rhythm
t_rhythm_memory_element *next; // next element of the list
+ unsigned short int id; // its sub id
} ;
// a rhythm in memory, each rhythm is :
// - its probability transition table
// - similar rhythms played
+ // - each one has its main id and each different played rhythm its sub-id
struct t_rhythm_memory_representation
{
t_rhythm_memory_node *transitions;
unsigned short int max_weight;
! t_rhythm_memory_element *rhythms;
! unsigned short int id; // its main id
! unsigned short int last_sub_id; // last sub assigned
! // I can express a list of representations with this data structure
! t_rhythm_memory_representation *next;
} ;
***************
*** 140,155 ****
// create and initialize this representation, allocate memory for the pointers
! void create_rhythm_memory_representation(t_rhythm_memory_representation **this_rep);
// add a new rhythm in the list of similar rhythms related to one main rhythm
! void add_similar_rhythm(t_rhythm_memory_representation *this_rep, t_rhythm_event *new_rhythm);
! // free the array with pointers and lists
! void free_memory_representation(t_rhythm_memory_representation *this_rep);
// compares this rhythm to this representation
// and tells you how close it is to it
! // TODO !!!!!!!!!!!!!!!!!!
// -------- notes manipulation functions
--- 145,180 ----
// create and initialize this representation, allocate memory for the pointers
! // I must pass its id also
! 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
! unsigned short int add_similar_rhythm(t_rhythm_memory_representation *this_rep, t_rhythm_event *new_rhythm);
! // free the list of representations
! void free_memory_representations(t_rhythm_memory_representation *this_rep);
// compares this rhythm to this representation
// and tells you how close it is to it
! // I return values using pointers
! // the unsigned short and the 2 floats should be already allocated
! void find_similar_rhythm_in_memory(t_rhythm_memory_representation *this_rep,
! t_rhythm_event *src_rhythm, // the src rhythm
! unsigned short int *sub_id, // the sub-id of the closest sub-rhythm
! float *root_closeness, // how much this rhythm is close to the root (1=identical, 0=nothing common)
! float *sub_closeness // how much this rhythm is close to the closest sub-rhythm (1=identical, 0=nothing common)
! );
+ // same as before but search all available representations
+ void find_rhythm_in_memory(t_rhythm_memory_representation *rep_list,
+ t_rhythm_event *src_rhythm, // the src rhythm
+ unsigned short int *id, // the id of the closest rhythm
+ unsigned short int *sub_id, // the sub-id of the closest sub-rhythm
+ float *root_closeness, // how much this rhythm is close to the root (1=identical, 0=nothing common)
+ float *sub_closeness // how much this rhythm is close to the closest sub-rhythm (1=identical, 0=nothing common)
+ );
// -------- notes manipulation functions
Index: common.c
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** common.c 4 Dec 2005 02:03:40 -0000 1.7
--- common.c 5 Dec 2005 12:57:38 -0000 1.8
***************
*** 189,193 ****
// initialize this representation, allocates memory for the pointers
! void create_rhythm_memory_representation(t_rhythm_memory_representation **this_rep)
{
int i;
--- 189,193 ----
// initialize this representation, allocates memory for the pointers
! void create_rhythm_memory_representation(t_rhythm_memory_representation **this_rep, unsigned short int id)
{
int i;
***************
*** 203,212 ****
(*this_rep)->transitions[i].arcs=0;
}
! (*this_rep)->main_rhythm = 0;
! (*this_rep)->similar_rhythms = 0;
}
// add a new rhythm in the list of similar thythms related to one main rhythm
! void add_t_rhythm_memory_element(t_rhythm_memory_representation *this_rep, t_rhythm_event *new_rhythm)
{
t_rhythm_memory_element *curr;
--- 203,214 ----
(*this_rep)->transitions[i].arcs=0;
}
! (*this_rep)->rhythms = 0;
! // the naming variables
! (*this_rep)->id = id; // the main id
! (*this_rep)->last_sub_id = 0; // the sub id
}
// add a new rhythm in the list of similar thythms related to one main rhythm
! unsigned short int add_t_rhythm_memory_element(t_rhythm_memory_representation *this_rep, t_rhythm_event *new_rhythm)
{
t_rhythm_memory_element *curr;
***************
*** 214,218 ****
t_rhythm_event *currEvent;
t_rhythm_memory_arc *currArc, *newArc, *prevArc;
! unsigned short int last;
int i, arcFound;
// creates a new element of the list of similar rhythms
--- 216,220 ----
t_rhythm_event *currEvent;
t_rhythm_memory_arc *currArc, *newArc, *prevArc;
! unsigned short int last, sub_id;
int i, arcFound;
// creates a new element of the list of similar rhythms
***************
*** 220,225 ****
newElement->rhythm = new_rhythm;
newElement->next = 0;
// finds the last element and adds itself
! curr = this_rep->similar_rhythms;
if (curr)
{
--- 222,230 ----
newElement->rhythm = new_rhythm;
newElement->next = 0;
+ sub_id = this_rep->last_sub_id;
+ newElement->id = sub_id;
+ this_rep->last_sub_id++;
// finds the last element and adds itself
! curr = this_rep->rhythms;
if (curr)
{
***************
*** 230,234 ****
} else
{
! this_rep->similar_rhythms = newElement;
}
// now update the transition table..
--- 235,239 ----
} else
{
! this_rep->rhythms = newElement;
}
// now update the transition table..
***************
*** 288,332 ****
currEvent = currEvent->next;
}
}
! void free_memory_representation(t_rhythm_memory_representation *this_rep)
{
int i, maxi;
t_rhythm_memory_element *currElement, *tmpElement;
t_rhythm_memory_arc *currArc, *tmpArc;
! // free the main rhythm
! if (this_rep->main_rhythm)
{
! freeBeats(this_rep->main_rhythm->rhythm);
! free(this_rep->main_rhythm);
! }
! // free the table
! maxi = possible_durations();
! for (i=0; i<maxi; i++)
! {
! currArc = this_rep->transitions[i].arcs;
! while (currArc)
{
! tmpArc = currArc;
! currArc = currArc->next_arc;
! free(tmpArc);
}
}
- free(this_rep->transitions);
! // free the list of similar rhythms
! currElement = this_rep->similar_rhythms;
! while (currElement)
{
! freeBeats(currElement->rhythm);
! tmpElement = currElement;
! currElement = currElement->next;
! free(tmpElement);
}
}
// ------------------- themes manipulation functions
--- 293,394 ----
currEvent = currEvent->next;
}
+ return sub_id;
}
! // free the list of representations
! void free_memory_representations(t_rhythm_memory_representation *this_rep)
{
int i, maxi;
+ t_rhythm_memory_representation *currRep, *oldRep;
t_rhythm_memory_element *currElement, *tmpElement;
t_rhythm_memory_arc *currArc, *tmpArc;
! currRep = this_rep;
! while(currRep)
{
! // free the table
! maxi = possible_durations();
! for (i=0; i<maxi; i++)
! {
! currArc = currRep->transitions[i].arcs;
! while (currArc)
! {
! tmpArc = currArc;
! currArc = currArc->next_arc;
! free(tmpArc);
! }
! }
! free(currRep->transitions);
! // free the list of similar rhythms
! currElement = currRep->rhythms;
! while (currElement)
{
! freeBeats(currElement->rhythm);
! tmpElement = currElement;
! currElement = currElement->next;
! free(tmpElement);
}
+ oldRep = currRep;
+ currRep = currRep->next;
+ free(oldRep);
}
! }
!
! // compares this rhythm to this representation
! // and tells you how close it is to it
! void find_similar_rhythm_in_memory(t_rhythm_memory_representation *this_rep,
! t_rhythm_event *src_rhythm, // the src rhythm
! unsigned short int *sub_id, // the sub-id of the closest sub-rhythm
! float *root_closeness, // how much this rhythm is close to the root (1=identical, 0=nothing common)
! float *sub_closeness // how much this rhythm is close to the closest sub-rhythm (1=identical, 0=nothing common)
! )
! {
! // check that the return values have been allocated
! if ((sub_id==0)||(root_closeness==0)||(sub_closeness==0))
{
! post("error in find_similar_rhythm(): return values not allocated");
! return;
}
+ // look the main table for closeness to the main rhythm
+
+ // TODO
+
+ // 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
+ }
+
+ void find_rhythm_in_memory(t_rhythm_memory_representation *rep_list,
+ t_rhythm_event *src_rhythm, // the src rhythm
+ unsigned short int *id, // the id of the closest rhythm
+ unsigned short int *sub_id, // the sub-id of the closest sub-rhythm
+ float *root_closeness, // how much this rhythm is close to the root (1=identical, 0=nothing common)
+ float *sub_closeness // how much this rhythm is close to the closest sub-rhythm (1=identical, 0=nothing common)
+ )
+ {
+ // 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
}
+
// ------------------- themes manipulation functions