Update of /cvsroot/pure-data/externals/frankenstein In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10282
Modified Files: Makefile common.c common.h Log Message: going little further with common functions
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 18 Oct 2005 23:10:53 -0000 1.1 --- Makefile 30 Nov 2005 17:31:33 -0000 1.2 *************** *** 2,12 **** #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"
current: pd_nt distclean
! pd_nt: chord_melo.dll chords_memory.dll harmonizer.dll GArhythm.dll ritmo1.dll
.SUFFIXES: .dll --- 2,12 ---- #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"
current: pd_nt distclean
! pd_nt: chord_melo.dll chords_memory.dll harmonizer.dll GArhythm.dll ritmo1.dll test.dll
.SUFFIXES: .dll *************** *** 23,28 ****
.c.dll: ! cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c ! link /dll /export:$*_setup $*.obj $(PDNTLIB)
--- 23,28 ----
.c.dll: ! cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c common.c $*.c ! link /dll /export:$*_setup $*.obj common.obj $(PDNTLIB)
Index: common.h =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/common.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** common.h 29 Nov 2005 18:04:09 -0000 1.1 --- common.h 30 Nov 2005 17:31:33 -0000 1.2 *************** *** 38,48 **** // data structures
! typedef struct _rhythm_event { unsigned short int voice; t_duration duration; ! struct t_rhythm_event *previous; // this is a list, link to the previous element ! struct t_rhythm_event *next; // this is a list, link to the next element ! } t_rhythm_event;
// rhythms memory graph --- 38,49 ---- // data structures
! typedef struct t_rhythm_event t_rhythm_event; ! struct t_rhythm_event { unsigned short int voice; t_duration duration; ! t_rhythm_event *previous; // this is a list, link to the previous element ! t_rhythm_event *next; // this is a list, link to the next element ! };
// rhythms memory graph *************** *** 68,75 **** // simpler and most of all non recursive when searching nodes! #define num_possible_denominators 11 ! unsigned short int possible_denominators[] = {1,2,3,4,6,8,12,16,18,24,32}; // functions needed to fill and use the memory table t_duration int2duration(int n); unsigned short int duration2int(t_duration dur); int possible_durations();
--- 69,83 ---- // simpler and most of all non recursive when searching nodes! #define num_possible_denominators 11 ! static unsigned short int possible_denominators[] = {1,2,3,4,6,8,12,16,18,24,32}; ! // functions needed to fill and use the memory table + + // converts from integer to duration: used to know this table index + // what corresponds in terms of duration t_duration int2duration(int n); + // converts from duration to integer: used to know this duration + // what corresponds in terms table index unsigned short int duration2int(t_duration dur); + // tells you how many durations there are int possible_durations();
*************** *** 80,81 **** --- 88,103 ---- // - from a (voice, duration) representation to (voice, start, duration) and viceversa
+ // converts from float (0-1) to duration. it performs quantization + t_duration float2duration(float fduration); + + // converts from numerator/denominator to a float (0-1) + float duration2float(t_duration duration); + + // set the first beat of a sequence + void setFirstBeat(t_rhythm_event **firstEvent, unsigned short int voice, float fduration); + + //adds a beat at the end of this list + void concatenateBeat(t_rhythm_event *currentEvent, unsigned short int voice, float fduration); + + // used to free the memory allocated by this list + void freeBeats(t_rhythm_event *currentEvent); \ No newline at end of file
Index: common.c =================================================================== RCS file: /cvsroot/pure-data/externals/frankenstein/common.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** common.c 29 Nov 2005 18:04:08 -0000 1.1 --- common.c 30 Nov 2005 17:31:33 -0000 1.2 *************** *** 2,20 **** #include "common.h"
t_duration int2duration(int n) { t_duration dur; ! int curr, i, j, ok; curr=0; ok=0; for (i=0; i<num_possible_denominators; i++) { ! for (j=0; j<i; j++) { if (curr==n) { dur.numerator=j; ! dur.denominator=i; ! j=i; i=num_possible_denominators; ok=1; --- 2,26 ---- #include "common.h"
+ #include <math.h> + #include <stdlib.h> + + #include "m_pd.h" // to post errors and debug messages + t_duration int2duration(int n) { t_duration dur; ! int curr, i, j, ok, currden; curr=0; ok=0; for (i=0; i<num_possible_denominators; i++) { ! currden = possible_denominators[i]; ! for (j=0; j<currden; j++) { if (curr==n) { dur.numerator=j; ! dur.denominator=currden; ! j=currden; i=num_possible_denominators; ok=1; *************** *** 61,63 **** --- 67,159 ---- ris += 1; return ris; + } + + t_duration float2duration(float fduration) + { + float minDiff, currfduration, currDiff; + int i, maxi; + t_duration currDur, bestDur; + + bestDur.numerator=1; + bestDur.denominator=1; + minDiff = 1; + maxi = possible_durations(); + for (i=0; i<maxi; i++) + { + // post("i=%i", i); + currDur = int2duration(i); + // post("currDur=%i/%i", currDur.numerator, currDur.denominator); + currfduration = duration2float(currDur); + // post("currfduration=%f", currfduration); + currDiff = (float) fabs(fduration - currfduration); + if (currDiff<=minDiff) + { + minDiff = currDiff; + bestDur = currDur; + } + } + return bestDur; + } + + float duration2float(t_duration duration) + { + return (float) (((float)duration.numerator) / ((float)duration.denominator)); + } + + void setFirstBeat(t_rhythm_event **firstEvent, unsigned short int voice, float fduration) + { + t_duration res; + t_rhythm_event *newElement; + // convert from float to duration + res = float2duration(fduration); + // allocate a new element of the list + newElement = malloc(sizeof(t_rhythm_event)); + // set the pointers + newElement->previous = 0; + newElement->next = 0; + newElement->voice=voice; + newElement->duration.numerator = res.numerator; + newElement->duration.denominator = res.denominator; + *firstEvent = newElement; + } + + void concatenateBeat(t_rhythm_event *currentEvent, unsigned short int voice, float fduration) + { + t_duration res; + t_rhythm_event *newElement, *lastElement; + lastElement = currentEvent; + while(lastElement->next) + lastElement = lastElement->next; + // convert from float to duration + res = float2duration(fduration); + // allocate a new element of the list + newElement = (t_rhythm_event *) malloc(sizeof(t_rhythm_event)); + // set the pointers + newElement->previous = lastElement; + newElement->next = 0; + lastElement->next = newElement; + newElement->voice=voice; + newElement->duration.numerator = res.numerator; + newElement->duration.denominator = res.denominator; + + } + + void freeBeats(t_rhythm_event *currentEvent) + { + t_rhythm_event *prev; + t_rhythm_event *next; + + // go to the first element of the list + while(currentEvent->previous) + currentEvent = currentEvent->previous; + + // now free each element + next=currentEvent->next; + do + { + prev = currentEvent; + next = currentEvent->next; + free(currentEvent); + } while(next); + } \ No newline at end of file