From f491b6c244c1ffc5c51eaa94e9f85e35fbdea19b Mon Sep 17 00:00:00 2001 From: Davide Morelli Date: Fri, 2 Dec 2005 12:18:12 +0000 Subject: adding rhythms memory graph svn path=/trunk/externals/frankenstein/; revision=4113 --- common.c | 26 ++++++++++++++++++++++++++ common.h | 32 +++++++++++++++++++------------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/common.c b/common.c index fb5d3fb..4d554ff 100755 --- a/common.c +++ b/common.c @@ -158,6 +158,32 @@ void freeBeats(t_rhythm_event *currentEvent) } +void add_t_rhythm_memory_arc(t_rhythm_memory_node *srcNode, t_rhythm_memory_node *dstNode) +{ + t_rhythm_memory_arc *newArc; + t_rhythm_memory_arc *lastArc; + + // create a new arc + newArc = (t_rhythm_memory_arc *) malloc(sizeof(t_rhythm_memory_arc)); + newArc->to_note = dstNode; + newArc->weight = 1; + // go to the last arc in the list + // and add this arc as the last + lastArc = srcNode->arcs; + if (lastArc) + { + // this is not the first arc + while(lastArc->next_arc) + lastArc = lastArc->next_arc; + lastArc->next_arc = newArc; + } else + { + // this is the first arc + srcNode->arcs = newArc; + } +} + +// ------------------- themes manipulation functions // set the first note of a sequence void setFirstNote(t_note_event **firstEvent, unsigned short int voice, float fduration, t_note note) diff --git a/common.h b/common.h index 4aa6314..f5bc973 100755 --- a/common.h +++ b/common.h @@ -43,25 +43,31 @@ struct t_rhythm_event // rhythms memory graph -/* + // list implementation // this implements a graph that stores the memory of the current rhythm sub-elements // list of links -typedef struct _rhythm_memory_arc -{ - float weight; - struct t_rhythm_memory_node *to_node; // the target of this link (arc) - struct t_rhythm_memory_arc *next_arc; // next link in the list -} t_rhythm_memory_arc; +// the actual implementation will be an array of nodes, each node +typedef struct t_rhythm_memory_arc t_rhythm_memory_arc; +typedef struct t_rhythm_memory_node t_rhythm_memory_node; // graph node -typedef struct _rhythm_memory_node +typedef struct t_rhythm_memory_node { t_duration duration; - struct t_rhythm_memory_arc *arcs; // the list of arcs to other nodes -} t_rhythm_memory_node; -*/ -// with a table -// simpler and most of all non recursive when searching nodes! + t_rhythm_memory_arc *arcs; // the list of arcs to other nodes +} ; +// graph arc +struct t_rhythm_memory_arc +{ + unsigned short int weight; + t_rhythm_memory_node *to_node; // the target of this link (arc) + t_rhythm_memory_arc *next_arc; // next link in the list +} ; +// it will be arranged in a heap list? + +// add an arc to this node +void add_t_rhythm_memory_arc(t_rhythm_memory_node *srcNode, t_rhythm_memory_node *dstNode); + #define num_possible_denominators 11 static unsigned short int possible_denominators[] = {1,2,3,4,6,8,12,16,18,24,32}; -- cgit v1.2.1