Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | /* code for "obj1" pd class. This takes two messages: floating-point |
2 | numbers, and "rats", and just prints something out for each message. */ | |
3 | ||
4 | #include "m_pd.h" | |
5 | ||
6 | /* the data structure for each copy of "obj1". In this case we | |
7 | on;y need pd's obligatory header (of type t_object). */ | |
8 | typedef struct obj1 | |
9 | { | |
10 | t_object x_ob; | |
11 | } t_obj1; | |
12 | ||
13 | /* this is called back when obj1 gets a "float" message (i.e., a | |
14 | number.) */ | |
15 | void obj1_float(t_obj1 *x, t_floatarg f) | |
16 | { | |
17 | post("obj1: %f", f); | |
18 | } | |
19 | ||
20 | /* this is called when obj1 gets the message, "rats". */ | |
21 | void obj1_rats(t_obj1 *x) | |
22 | { | |
23 | post("obj1: rats"); | |
24 | } | |
25 | ||
26 | /* this is a pointer to the class for "obj1", which is created in the | |
27 | "setup" routine below and used to create new ones in the "new" routine. */ | |
28 | t_class *obj1_class; | |
29 | ||
30 | /* this is called when a new "obj1" object is created. */ | |
31 | void *obj1_new(void) | |
32 | { | |
33 | t_obj1 *x = (t_obj1 *)pd_new(obj1_class); | |
34 | post("obj1_new"); | |
35 | return (void *)x; | |
36 | } | |
37 | ||
38 | /* this is called once at setup time, when this code is loaded into Pd. */ | |
39 | void obj1_setup(void) | |
40 | { | |
41 | post("obj1_setup"); | |
42 | obj1_class = class_new(gensym("obj1"), (t_newmethod)obj1_new, 0, | |
43 | sizeof(t_obj1), 0, 0); | |
44 | class_addmethod(obj1_class, (t_method)obj1_rats, gensym("rats"), 0); | |
45 | class_addfloat(obj1_class, obj1_float); | |
46 | } | |
47 |