From ed932acb5860bf8b9296169676499562a55d139e Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Mon, 6 Sep 2004 20:20:36 +0000 Subject: checking in version 0.38test5. Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010 --- pd/src/x_time.c | 254 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 131 insertions(+), 123 deletions(-) (limited to 'pd/src/x_time.c') diff --git a/pd/src/x_time.c b/pd/src/x_time.c index 2ea17fd3..70285455 100644 --- a/pd/src/x_time.c +++ b/pd/src/x_time.c @@ -61,12 +61,12 @@ static void *delay_new(t_floatarg f) static void delay_setup(void) { delay_class = class_new(gensym("delay"), (t_newmethod)delay_new, - (t_method)delay_free, sizeof(t_delay), 0, A_DEFFLOAT, 0); + (t_method)delay_free, sizeof(t_delay), 0, A_DEFFLOAT, 0); class_addcreator((t_newmethod)delay_new, gensym("del"), A_DEFFLOAT, 0); class_addbang(delay_class, delay_bang); class_addmethod(delay_class, (t_method)delay_stop, gensym("stop"), 0); class_addmethod(delay_class, (t_method)delay_ft1, - gensym("ft1"), A_FLOAT, 0); + gensym("ft1"), A_FLOAT, 0); class_addfloat(delay_class, (t_method)delay_float); } @@ -130,11 +130,11 @@ static void *metro_new(t_floatarg f) static void metro_setup(void) { metro_class = class_new(gensym("metro"), (t_newmethod)metro_new, - (t_method)metro_free, sizeof(t_metro), 0, A_DEFFLOAT, 0); + (t_method)metro_free, sizeof(t_metro), 0, A_DEFFLOAT, 0); class_addbang(metro_class, metro_bang); class_addmethod(metro_class, (t_method)metro_stop, gensym("stop"), 0); class_addmethod(metro_class, (t_method)metro_ft1, gensym("ft1"), - A_FLOAT, 0); + A_FLOAT, 0); class_addfloat(metro_class, (t_method)metro_float); } @@ -161,15 +161,15 @@ static void line_tick(t_line *x) double msectogo = - clock_gettimesince(x->x_targettime); if (msectogo < 1E-9) { - outlet_float(x->x_obj.ob_outlet, x->x_targetval); + outlet_float(x->x_obj.ob_outlet, x->x_targetval); } else { - outlet_float(x->x_obj.ob_outlet, - x->x_setval + x->x_1overtimediff * (timenow - x->x_prevtime) - * (x->x_targetval - x->x_setval)); - clock_delay(x->x_clock, - (x->x_grain > msectogo ? msectogo : x->x_grain)); + outlet_float(x->x_obj.ob_outlet, + x->x_setval + x->x_1overtimediff * (timenow - x->x_prevtime) + * (x->x_targetval - x->x_setval)); + clock_delay(x->x_clock, + (x->x_grain > msectogo ? msectogo : x->x_grain)); } } @@ -178,25 +178,25 @@ static void line_float(t_line *x, t_float f) double timenow = clock_getsystime(); if (x->x_gotinlet && x->x_in1val > 0) { - if (timenow > x->x_targettime) x->x_setval = x->x_targetval; - else x->x_setval = x->x_setval + x->x_1overtimediff * - (timenow - x->x_prevtime) - * (x->x_targetval - x->x_setval); - x->x_prevtime = timenow; - x->x_targettime = clock_getsystimeafter(x->x_in1val); - x->x_targetval = f; - line_tick(x); - x->x_gotinlet = 0; - x->x_1overtimediff = 1./ (x->x_targettime - timenow); - clock_delay(x->x_clock, - (x->x_grain > x->x_in1val ? x->x_in1val : x->x_grain)); + if (timenow > x->x_targettime) x->x_setval = x->x_targetval; + else x->x_setval = x->x_setval + x->x_1overtimediff * + (timenow - x->x_prevtime) + * (x->x_targetval - x->x_setval); + x->x_prevtime = timenow; + x->x_targettime = clock_getsystimeafter(x->x_in1val); + x->x_targetval = f; + line_tick(x); + x->x_gotinlet = 0; + x->x_1overtimediff = 1./ (x->x_targettime - timenow); + clock_delay(x->x_clock, + (x->x_grain > x->x_in1val ? x->x_in1val : x->x_grain)); } else { - clock_unset(x->x_clock); - x->x_targetval = x->x_setval = f; - outlet_float(x->x_obj.ob_outlet, f); + clock_unset(x->x_clock); + x->x_targetval = x->x_setval = f; + outlet_float(x->x_obj.ob_outlet, f); } x->x_gotinlet = 0; } @@ -213,6 +213,12 @@ static void line_stop(t_line *x) clock_unset(x->x_clock); } +static void line_set(t_line *x, t_floatarg f) +{ + clock_unset(x->x_clock); + x->x_targetval = x->x_setval = f; +} + static void line_free(t_line *x) { clock_free(x->x_clock); @@ -236,11 +242,13 @@ static void *line_new(t_floatarg f, t_floatarg grain) static void line_setup(void) { line_class = class_new(gensym("line"), (t_newmethod)line_new, - (t_method)line_free, sizeof(t_line), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_method)line_free, sizeof(t_line), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(line_class, (t_method)line_ft1, - gensym("ft1"), A_FLOAT, 0); + gensym("ft1"), A_FLOAT, 0); class_addmethod(line_class, (t_method)line_stop, - gensym("stop"), 0); + gensym("stop"), 0); + class_addmethod(line_class, (t_method)line_set, + gensym("set"), A_FLOAT, 0); class_addfloat(line_class, (t_method)line_float); } @@ -275,7 +283,7 @@ static void *timer_new(t_floatarg f) static void timer_setup(void) { timer_class = class_new(gensym("timer"), (t_newmethod)timer_new, 0, - sizeof(t_timer), 0, A_DEFFLOAT, 0); + sizeof(t_timer), 0, A_DEFFLOAT, 0); class_addbang(timer_class, timer_bang); class_addmethod(timer_class, (t_method)timer_bang2, gensym("bang2"), 0); } @@ -291,7 +299,7 @@ typedef struct _hang struct _hang *h_next; struct _pipe *h_owner; t_gpointer *h_gp; - union word h_vec[1]; /* not the actual number. */ + union word h_vec[1]; /* not the actual number. */ } t_hang; typedef struct pipeout @@ -322,68 +330,68 @@ static void *pipe_new(t_symbol *s, int argc, t_atom *argv) float deltime; if (argc) { - if (argv[argc-1].a_type != A_FLOAT) - { - char stupid[80]; - atom_string(&argv[argc-1], stupid, 79); - post("pipe: %s: bad time delay value", stupid); - deltime = 0; - } - else deltime = argv[argc-1].a_w.w_float; - argc--; + if (argv[argc-1].a_type != A_FLOAT) + { + char stupid[80]; + atom_string(&argv[argc-1], stupid, 79); + post("pipe: %s: bad time delay value", stupid); + deltime = 0; + } + else deltime = argv[argc-1].a_w.w_float; + argc--; } else deltime = 0; if (!argc) { - argv = &defarg; - argc = 1; - SETFLOAT(&defarg, 0); + argv = &defarg; + argc = 1; + SETFLOAT(&defarg, 0); } x->x_n = argc; vec = x->x_vec = (t_pipeout *)getbytes(argc * sizeof(*x->x_vec)); for (i = argc, ap = argv; i--; ap++) - if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p') - nptr++; + if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p') + nptr++; gp = x->x_gp = (t_gpointer *)t_getbytes(nptr * sizeof (*gp)); x->x_nptr = nptr; for (i = 0, vp = vec, ap = argv; i < argc; i++, ap++, vp++) { - if (ap->a_type == A_FLOAT) - { - vp->p_atom = *ap; - vp->p_outlet = outlet_new(&x->x_obj, &s_float); - if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float); - } - else if (ap->a_type == A_SYMBOL) - { - char c = *ap->a_w.w_symbol->s_name; - if (c == 's') - { - SETSYMBOL(&vp->p_atom, &s_symbol); - vp->p_outlet = outlet_new(&x->x_obj, &s_symbol); - if (i) symbolinlet_new(&x->x_obj, &vp->p_atom.a_w.w_symbol); - } - else if (c == 'p') - { - vp->p_atom.a_type = A_POINTER; - vp->p_atom.a_w.w_gpointer = gp; - gpointer_init(gp); - vp->p_outlet = outlet_new(&x->x_obj, &s_pointer); - if (i) pointerinlet_new(&x->x_obj, gp); - gp++; - } - else - { - if (c != 'f') error("pack: %s: bad type", - ap->a_w.w_symbol->s_name); - SETFLOAT(&vp->p_atom, 0); - vp->p_outlet = outlet_new(&x->x_obj, &s_float); - if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float); - } - } + if (ap->a_type == A_FLOAT) + { + vp->p_atom = *ap; + vp->p_outlet = outlet_new(&x->x_obj, &s_float); + if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float); + } + else if (ap->a_type == A_SYMBOL) + { + char c = *ap->a_w.w_symbol->s_name; + if (c == 's') + { + SETSYMBOL(&vp->p_atom, &s_symbol); + vp->p_outlet = outlet_new(&x->x_obj, &s_symbol); + if (i) symbolinlet_new(&x->x_obj, &vp->p_atom.a_w.w_symbol); + } + else if (c == 'p') + { + vp->p_atom.a_type = A_POINTER; + vp->p_atom.a_w.w_gpointer = gp; + gpointer_init(gp); + vp->p_outlet = outlet_new(&x->x_obj, &s_pointer); + if (i) pointerinlet_new(&x->x_obj, gp); + gp++; + } + else + { + if (c != 'f') error("pack: %s: bad type", + ap->a_w.w_symbol->s_name); + SETFLOAT(&vp->p_atom, 0); + vp->p_outlet = outlet_new(&x->x_obj, &s_float); + if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float); + } + } } floatinlet_new(&x->x_obj, &x->x_deltime); x->x_hang = 0; @@ -397,7 +405,7 @@ static void hang_free(t_hang *h) t_gpointer *gp; int i; for (gp = h->h_gp, i = x->x_nptr; i--; gp++) - gpointer_unset(gp); + gpointer_unset(gp); freebytes(h->h_gp, x->x_nptr * sizeof(*h->h_gp)); clock_free(h->h_clock); freebytes(h, sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec)); @@ -413,25 +421,25 @@ static void hang_tick(t_hang *h) if (x->x_hang == h) x->x_hang = h->h_next; else for (h2 = x->x_hang; h3 = h2->h_next; h2 = h3) { - if (h3 == h) - { - h2->h_next = h3->h_next; - break; - } + if (h3 == h) + { + h2->h_next = h3->h_next; + break; + } } for (i = x->x_n, p = x->x_vec + (x->x_n - 1), w = h->h_vec + (x->x_n - 1); - i--; p--, w--) + i--; p--, w--) { - switch (p->p_atom.a_type) - { - case A_FLOAT: outlet_float(p->p_outlet, w->w_float); break; - case A_SYMBOL: outlet_symbol(p->p_outlet, w->w_symbol); break; - case A_POINTER: - if (gpointer_check(w->w_gpointer, 1)) - outlet_pointer(p->p_outlet, w->w_gpointer); - else post("pipe: stale pointer"); - break; - } + switch (p->p_atom.a_type) + { + case A_FLOAT: outlet_float(p->p_outlet, w->w_float); break; + case A_SYMBOL: outlet_symbol(p->p_outlet, w->w_symbol); break; + case A_POINTER: + if (gpointer_check(w->w_gpointer, 1)) + outlet_pointer(p->p_outlet, w->w_gpointer); + else post("pipe: stale pointer"); + break; + } } hang_free(h); } @@ -439,7 +447,7 @@ static void hang_tick(t_hang *h) static void pipe_list(t_pipe *x, t_symbol *s, int ac, t_atom *av) { t_hang *h = (t_hang *) - getbytes(sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec)); + getbytes(sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec)); t_gpointer *gp, *gp2; t_pipeout *p; int i, n = x->x_n; @@ -448,34 +456,34 @@ static void pipe_list(t_pipe *x, t_symbol *s, int ac, t_atom *av) h->h_gp = (t_gpointer *)getbytes(x->x_nptr * sizeof(t_gpointer)); if (ac > n) ac = n; for (i = 0, gp = x->x_gp, p = x->x_vec, ap = av; i < ac; - i++, p++, ap++) + i++, p++, ap++) { - switch (p->p_atom.a_type) - { - case A_FLOAT: p->p_atom.a_w.w_float = atom_getfloat(ap); break; - case A_SYMBOL: p->p_atom.a_w.w_symbol = atom_getsymbol(ap); break; - case A_POINTER: - gpointer_unset(gp); - if (ap->a_type != A_POINTER) - post("pipe: bad pointer"); - else - { - *gp = *(ap->a_w.w_gpointer); - if (gp->gp_stub) gp->gp_stub->gs_refcount++; - } - gp++; - } + switch (p->p_atom.a_type) + { + case A_FLOAT: p->p_atom.a_w.w_float = atom_getfloat(ap); break; + case A_SYMBOL: p->p_atom.a_w.w_symbol = atom_getsymbol(ap); break; + case A_POINTER: + gpointer_unset(gp); + if (ap->a_type != A_POINTER) + post("pipe: bad pointer"); + else + { + *gp = *(ap->a_w.w_gpointer); + if (gp->gp_stub) gp->gp_stub->gs_refcount++; + } + gp++; + } } for (i = 0, gp = x->x_gp, gp2 = h->h_gp, p = x->x_vec, w = h->h_vec; - i < n; i++, p++, w++) + i < n; i++, p++, w++) { - if (p->p_atom.a_type == A_POINTER) - { - if (gp->gp_stub) gp->gp_stub->gs_refcount++; - w->w_gpointer = gp2; - *gp2++ = *gp++; - } - else *w = p->p_atom.a_w; + if (p->p_atom.a_type == A_POINTER) + { + if (gp->gp_stub) gp->gp_stub->gs_refcount++; + w->w_gpointer = gp2; + *gp2++ = *gp++; + } + else *w = p->p_atom.a_w; } h->h_next = x->x_hang; x->x_hang = h; @@ -494,16 +502,16 @@ static void pipe_clear(t_pipe *x) t_hang *hang; while (hang = x->x_hang) { - x->x_hang = hang->h_next; - hang_free(hang); + x->x_hang = hang->h_next; + hang_free(hang); } } static void pipe_setup(void) { pipe_class = class_new(gensym("pipe"), - (t_newmethod)pipe_new, (t_method)pipe_clear, - sizeof(t_pipe), 0, A_GIMME, 0); + (t_newmethod)pipe_new, (t_method)pipe_clear, + sizeof(t_pipe), 0, A_GIMME, 0); class_addlist(pipe_class, pipe_list); class_addmethod(pipe_class, (t_method)pipe_flush, gensym("flush"), 0); class_addmethod(pipe_class, (t_method)pipe_clear, gensym("clear"), 0); -- cgit v1.2.1