From 486e5ff7ebf4ed0fe1089ac73643c8dbca9b838a Mon Sep 17 00:00:00 2001 From: musil Date: Fri, 8 Jul 2005 02:13:24 +0000 Subject: dos-return svn path=/trunk/externals/iemlib/; revision=3301 --- src/iemlib2/speedlim.c | 214 ++++++++++++++++++++++++------------------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'src/iemlib2/speedlim.c') diff --git a/src/iemlib2/speedlim.c b/src/iemlib2/speedlim.c index 7b91860..40ad092 100644 --- a/src/iemlib2/speedlim.c +++ b/src/iemlib2/speedlim.c @@ -1,107 +1,107 @@ -/* For information on usage and redistribution, and for a DISCLAIMER OF ALL -* WARRANTIES, see the file, "LICENSE.txt," in this distribution. - -iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */ - -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -#include "m_pd.h" -#include "iemlib.h" -#include -#include -#include - -/* ----------------------- speedlim -------------------------- */ -/* -- reduces the flow of float-messages to one message per -- */ -/* ----------------- initial argument time in ms ------------- */ - -static t_class *speedlim_class; - -typedef struct _speedlim -{ - t_object x_obj; - t_clock *x_clock; - float x_delay; - int x_output_is_locked; - int x_there_was_n_event; - float x_curval; - float x_lastout; -} t_speedlim; - -static void speedlim_stop(t_speedlim *x) -{ - x->x_output_is_locked = 0; - x->x_there_was_n_event = 0; - clock_unset(x->x_clock); -} - -static void speedlim_tick(t_speedlim *x) -{ - if(x->x_there_was_n_event) - { - x->x_output_is_locked = 1; - x->x_there_was_n_event = 0; - outlet_float(x->x_obj.ob_outlet, x->x_curval); - clock_delay(x->x_clock, x->x_delay); - } - else - { - x->x_output_is_locked = 0; - x->x_there_was_n_event = 0; - } -} - -static void speedlim_float(t_speedlim *x, t_float val) -{ - x->x_curval = val; - if(!x->x_output_is_locked) - { - x->x_output_is_locked = 1; - x->x_there_was_n_event = 0; - outlet_float(x->x_obj.ob_outlet, x->x_curval); - clock_delay(x->x_clock, x->x_delay); - } - else - x->x_there_was_n_event = 1; -} - -static void speedlim_ft1(t_speedlim *x, t_float delay) -{ - if(delay < 0.0) - delay = 0.0; - x->x_delay = delay; -} - -static void speedlim_free(t_speedlim *x) -{ - clock_free(x->x_clock); -} - -static void *speedlim_new(t_float delay) -{ - t_speedlim *x = (t_speedlim *)pd_new(speedlim_class); - - if(delay < 0.0) - delay = 0.0; - x->x_delay = delay; - x->x_curval = 0.0f; - x->x_output_is_locked = 0; - x->x_there_was_n_event = 0; - x->x_clock = clock_new(x, (t_method)speedlim_tick); - outlet_new(&x->x_obj, &s_float); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); - return (x); -} - -void speedlim_setup(void) -{ - speedlim_class = class_new(gensym("speedlim"), (t_newmethod)speedlim_new, - (t_method)speedlim_free, sizeof(t_speedlim), 0, A_DEFFLOAT, 0); - class_addmethod(speedlim_class, (t_method)speedlim_stop, gensym("stop"), 0); - class_addfloat(speedlim_class, (t_method)speedlim_float); - class_addmethod(speedlim_class, (t_method)speedlim_ft1, gensym("ft1"), A_FLOAT, 0); - class_sethelpsymbol(speedlim_class, gensym("iemhelp/help-speedlim")); -} +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include +#include +#include + +/* ----------------------- speedlim -------------------------- */ +/* -- reduces the flow of float-messages to one message per -- */ +/* ----------------- initial argument time in ms ------------- */ + +static t_class *speedlim_class; + +typedef struct _speedlim +{ + t_object x_obj; + t_clock *x_clock; + float x_delay; + int x_output_is_locked; + int x_there_was_n_event; + float x_curval; + float x_lastout; +} t_speedlim; + +static void speedlim_stop(t_speedlim *x) +{ + x->x_output_is_locked = 0; + x->x_there_was_n_event = 0; + clock_unset(x->x_clock); +} + +static void speedlim_tick(t_speedlim *x) +{ + if(x->x_there_was_n_event) + { + x->x_output_is_locked = 1; + x->x_there_was_n_event = 0; + outlet_float(x->x_obj.ob_outlet, x->x_curval); + clock_delay(x->x_clock, x->x_delay); + } + else + { + x->x_output_is_locked = 0; + x->x_there_was_n_event = 0; + } +} + +static void speedlim_float(t_speedlim *x, t_float val) +{ + x->x_curval = val; + if(!x->x_output_is_locked) + { + x->x_output_is_locked = 1; + x->x_there_was_n_event = 0; + outlet_float(x->x_obj.ob_outlet, x->x_curval); + clock_delay(x->x_clock, x->x_delay); + } + else + x->x_there_was_n_event = 1; +} + +static void speedlim_ft1(t_speedlim *x, t_float delay) +{ + if(delay < 0.0) + delay = 0.0; + x->x_delay = delay; +} + +static void speedlim_free(t_speedlim *x) +{ + clock_free(x->x_clock); +} + +static void *speedlim_new(t_float delay) +{ + t_speedlim *x = (t_speedlim *)pd_new(speedlim_class); + + if(delay < 0.0) + delay = 0.0; + x->x_delay = delay; + x->x_curval = 0.0f; + x->x_output_is_locked = 0; + x->x_there_was_n_event = 0; + x->x_clock = clock_new(x, (t_method)speedlim_tick); + outlet_new(&x->x_obj, &s_float); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + return (x); +} + +void speedlim_setup(void) +{ + speedlim_class = class_new(gensym("speedlim"), (t_newmethod)speedlim_new, + (t_method)speedlim_free, sizeof(t_speedlim), 0, A_DEFFLOAT, 0); + class_addmethod(speedlim_class, (t_method)speedlim_stop, gensym("stop"), 0); + class_addfloat(speedlim_class, (t_method)speedlim_float); + class_addmethod(speedlim_class, (t_method)speedlim_ft1, gensym("ft1"), A_FLOAT, 0); + class_sethelpsymbol(speedlim_class, gensym("iemhelp/help-speedlim")); +} -- cgit v1.2.1