From 577ac6e80ff4f436fbd054291ed7dddbc31bd49a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 18 May 2004 21:33:33 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1738, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/iemlib/; revision=1739 --- src/iemlib2/speedlim.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/iemlib2/speedlim.c (limited to 'src/iemlib2/speedlim.c') diff --git a/src/iemlib2/speedlim.c b/src/iemlib2/speedlim.c new file mode 100644 index 0000000..023835a --- /dev/null +++ b/src/iemlib2/speedlim.c @@ -0,0 +1,107 @@ +/* Copyright (c) 1997-2003 Miller Puckette. +* 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 (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include +#include +#include +#include + +/* ------------------------ speedlim ---------------------------- */ +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