diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2005-12-04 12:44:33 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2005-12-04 12:44:33 +0000 |
commit | 8697b27135365592ebe5d7ced997d424d1239384 (patch) | |
tree | eeb8e9e8b61b4cdf0b074cbf1a86de06e0053567 /src | |
parent | 3de8c76cd0fed62754c0de3e052d78da27672d4b (diff) |
added an "info"-outlet,which bangs when the {lf}ifo is empty
by sending an [info( message, you can query the total number of elements
currently on the stack
svn path=/trunk/externals/zexy/; revision=4129
Diffstat (limited to 'src')
-rw-r--r-- | src/fifop.c | 30 | ||||
-rw-r--r-- | src/lifop.c | 30 |
2 files changed, 56 insertions, 4 deletions
diff --git a/src/fifop.c b/src/fifop.c index 3460223..b9cecb0 100644 --- a/src/fifop.c +++ b/src/fifop.c @@ -44,6 +44,7 @@ typedef struct _fifop_prioritylist { t_fifop_list *fifo_start; t_fifop_list *fifo_end; struct _fifop_prioritylist *next; + unsigned long counter; } t_fifop_prioritylist; typedef struct _fifop @@ -51,6 +52,7 @@ typedef struct _fifop t_object x_obj; t_fifop_prioritylist *fifo_list; t_float priority; /* current priority */ + t_outlet *x_out, *x_infout; } t_fifop; static t_fifop_prioritylist*fifop_genprioritylist(t_fifop*x, t_float priority) @@ -81,6 +83,7 @@ static t_fifop_prioritylist*fifop_genprioritylist(t_fifop*x, t_float priority) result->fifo_start=0; result->fifo_end=0; result->next=0; + result->counter=0; /* insert it into the list of priority lists */ if(dummy==0){ @@ -136,6 +139,7 @@ static int add2fifo(t_fifop_prioritylist*fifoprio, int argc, t_atom *argv) /* and at the same time, it is the last entry */ fifoprio->fifo_end =entry; } + fifoprio->counter++; return 0; } static t_fifop_prioritylist*getFifo(t_fifop_prioritylist*pfifo) @@ -163,12 +167,16 @@ static void fifop_bang(t_fifop *x) int argc=0; if(!(pfifo=getFifo(x->fifo_list))){ + outlet_bang(x->x_infout); return; } if(!(fifo=pfifo->fifo_start)){ + outlet_bang(x->x_infout); return; } + pfifo->counter--; + pfifo->fifo_start=fifo->next; if(0==pfifo->fifo_start){ pfifo->fifo_end=0; @@ -185,12 +193,25 @@ static void fifop_bang(t_fifop *x) freebytes(fifo, sizeof(t_fifop_list)); /* output the list */ - outlet_list(x->x_obj.ob_outlet, &s_list, argc, argv); + outlet_list(x->x_out, &s_list, argc, argv); /* free the list */ freebytes(argv, argc*sizeof(t_atom)); } +static void fifop_query(t_fifop*x) +{ + unsigned long counter=0; + t_fifop_prioritylist*pfifo=x->fifo_list; + while(pfifo!=NULL){ + counter+=pfifo->counter; + pfifo=pfifo->next; + } + + verbose(1, "%d elements in fifo", (int)counter); + + outlet_float(x->x_infout, (t_float)counter); +} static void fifop_free(t_fifop *x) { t_fifop_prioritylist *fifo_list=x->fifo_list; @@ -217,14 +238,18 @@ static void fifop_free(t_fifop *x) freebytes(fifo_list2, sizeof( t_fifop_prioritylist)); } x->fifo_list=0; + + outlet_free(x->x_out); + outlet_free(x->x_infout); } static void *fifop_new(t_symbol *s, int argc, t_atom *argv) { t_fifop *x = (t_fifop *)pd_new(fifop_class); - outlet_new(&x->x_obj, 0); floatinlet_new(&x->x_obj, &x->priority); + x->x_out =outlet_new(&x->x_obj, gensym("list" )); + x->x_infout=outlet_new(&x->x_obj, gensym("float")); x->fifo_list = 0; x->priority=0; @@ -239,6 +264,7 @@ void fifop_setup(void) class_addbang (fifop_class, fifop_bang); class_addlist (fifop_class, fifop_list); + class_addmethod (fifop_class, (t_method)fifop_query, gensym("info"), A_NULL); class_sethelpsymbol(fifop_class, gensym("zexy/fifop")); zexy_register("fifop"); diff --git a/src/lifop.c b/src/lifop.c index ac9ff7e..50df504 100644 --- a/src/lifop.c +++ b/src/lifop.c @@ -43,12 +43,14 @@ typedef struct _lifop_prioritylist { t_float priority; t_lifop_list *lifo_start; struct _lifop_prioritylist *next; + unsigned long counter; } t_lifop_prioritylist; typedef struct _lifop { t_object x_obj; t_lifop_prioritylist *lifo_list; t_float priority; /* current priority */ + t_outlet *x_out, *x_infout; } t_lifop; static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, t_float priority) @@ -76,6 +78,7 @@ static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, t_float priority) result = (t_lifop_prioritylist*)getbytes(sizeof( t_lifop_prioritylist)); result->priority=priority; result->lifo_start=0; + result->counter=0; /* insert it into the list of priority lists */ if(dummy==0){ @@ -119,6 +122,7 @@ static int add2lifo(t_lifop_prioritylist*lifoprio, int argc, t_atom *argv) entry->next=lifoprio->lifo_start; lifoprio->lifo_start=entry; + lifoprio->counter++; return 0; } @@ -147,12 +151,16 @@ static void lifop_bang(t_lifop *x) int argc=0; if(!(plifo=getLifo(x->lifo_list))){ + outlet_bang(x->x_infout); return; } if(!(lifo=plifo->lifo_start)){ + outlet_bang(x->x_infout); return; } + plifo->counter--; + plifo->lifo_start=lifo->next; /* get the list from the entry */ @@ -167,12 +175,25 @@ static void lifop_bang(t_lifop *x) freebytes(lifo, sizeof(t_lifop_list)); /* output the list */ - outlet_list(x->x_obj.ob_outlet, &s_list, argc, argv); + outlet_list(x->x_out, &s_list, argc, argv); /* free the list */ freebytes(argv, argc*sizeof(t_atom)); } +static void lifop_query(t_lifop*x) +{ + unsigned long counter=0; + t_lifop_prioritylist*plifo=x->lifo_list; + while(plifo!=NULL){ + counter+=plifo->counter; + plifo=plifo->next; + } + + verbose(1, "%d elements in lifo", (int)counter); + + outlet_float(x->x_infout, (t_float)counter); +} static void lifop_free(t_lifop *x) { t_lifop_prioritylist *lifo_list=x->lifo_list; @@ -198,14 +219,18 @@ static void lifop_free(t_lifop *x) freebytes(lifo_list2, sizeof( t_lifop_prioritylist)); } x->lifo_list=0; + + outlet_free(x->x_out); + outlet_free(x->x_infout); } static void *lifop_new(t_symbol *s, int argc, t_atom *argv) { t_lifop *x = (t_lifop *)pd_new(lifop_class); - outlet_new(&x->x_obj, 0); floatinlet_new(&x->x_obj, &x->priority); + x->x_out=outlet_new(&x->x_obj, gensym("list")); + x->x_infout=outlet_new(&x->x_obj, gensym("float")); x->lifo_list = 0; x->priority=0; @@ -220,6 +245,7 @@ void lifop_setup(void) class_addbang (lifop_class, lifop_bang); class_addlist (lifop_class, lifop_list); + class_addmethod (lifop_class, (t_method)lifop_query, gensym("info"), A_NULL); class_sethelpsymbol(lifop_class, gensym("zexy/lifop")); zexy_register("lifop"); |