Debian Codegraph @

countund.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /* ------------------------ countund~ -------------------------------------- */
2 /* */
3 /* Count up to a value and then down to zero */
4 /* Written by Yves Degoyon ([email protected]). */
5 /* */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License */
8 /* as published by the Free Software Foundation; either version 2 */
9 /* of the License, or (at your option) any later version. */
10 /* */
11 /* See file LICENSE for further informations on licensing terms. */
12 /* */
13 /* This program is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with this program; if not, write to the Free Software */
20 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* */
22 /* Based on PureData by Miller Puckette and others. */
23 /* */
24 /* ---------------------------------------------------------------------------- */
25
26
27
28 #include <sys/types.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <errno.h>
32 #include <stdlib.h>
33 #include <fcntl.h>
34 #include <sys/stat.h>
35 #ifndef __APPLE__
36 #include <malloc.h>
37 #endif
38 #include <ctype.h>
39 #include <unistd.h>
40 #include <time.h>
41 #include <sys/time.h>
42
43 #include <m_pd.h> /* standard pd stuff */
44
45 static char *countund_version = "countund~: count up to a value and then down to zero : author : [email protected]";
46
47 static t_class *countund_class;
48
49 typedef struct _countund
50 {
51 t_object x_obj;
52 t_int x_limit;
53 t_int x_value;
54 t_int x_up;
55 } t_countund;
56
57 /* clean up */
58 static void countund_free(t_countund *x)
59 {
60 }
61
62 static void *countund_new(t_float flimit)
63 {
64 t_countund *x = (t_countund *)pd_new(countund_class);
65 outlet_new(&x->x_obj, &s_float);
66 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
67 if ( flimit < 0 )
68 {
69 post( "countund~: wrong creation argument" );
70 return NULL;
71 }
72 x->x_limit = (int) flimit;
73 x->x_value = 0;
74 x->x_up = 1;
75 return(x);
76 }
77
78 static void *countund_limit(t_countund* x, t_float flimit)
79 {
80 if ( flimit < 0 )
81 {
82 post( "countund~: wrong count limit" );
83 return;
84 }
85 else
86 {
87 x->x_limit=(int)flimit;
88 }
89 }
90
91 static void *countund_bang(t_countund *x)
92 {
93
94 if ( x->x_up )
95 {
96 x->x_value+=1;
97 if (x->x_value>x->x_limit)
98 {
99 x->x_value=x->x_limit-1;
100 x->x_up=0;
101 }
102 }
103 else
104 {
105 x->x_value-=1;
106 if (x->x_value<0)
107 {
108 x->x_value=1;
109 x->x_up=1;
110 }
111 }
112 outlet_float( x->x_obj.ob_outlet, x->x_value );
113 return;
114 }
115
116 void countund_setup(void)
117 {
118 logpost(NULL, 4, countund_version);
119 countund_class = class_new(gensym("countund"), (t_newmethod)countund_new,
120 (t_method)countund_free,
121 sizeof(t_countund), 0, A_DEFFLOAT, 0);
122 class_addmethod( countund_class, (t_method)countund_bang, &s_bang, 0);
123 class_addmethod( countund_class, (t_method)countund_limit, gensym("limit"), A_FLOAT, 0);
124 }