aboutsummaryrefslogtreecommitdiff
path: root/prepend.c
blob: bc6313aa3ec6e25c93eee1c44fd5c8ae4f931664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <m_pd.h>
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif

/* this is taken from ggee, where the file was hanging around but the object was not
   funtional. i keep it here for reference since i dont wnat to fix it over and over ;)
   but its not included in the makefile to avoid namespace clash with ggee.prepend
   anyhow, i ll just rename it cxc.prepend
*/

/* ------------------------ prepend ----------------------------- */

static t_class *prepend_class;


typedef struct _prepend
{
     t_object x_obj;
     t_symbol* x_s;
} t_prepend;


void prepend_anything(t_prepend *x,t_symbol* s,t_int argc,t_atom* argv)
{
     int i = argc;
     t_symbol* cur;
     t_atom a_out[256];
     int    c_out = 0;
     t_atom* a = a_out;

#if 1
     //     post("sym: %s",s->s_name);
     SETSYMBOL(a,s);
     a++;
     c_out++;
#endif

     while (i--) {
       switch( argv->a_type) {
       case A_FLOAT:
	 //	 post("flo: %f",atom_getfloat(argv));
	 SETFLOAT(a,atom_getfloat(argv));
	 a++;
	 c_out++;
	 break;
       case A_SYMBOL:
	 //	 post("sym: %s",atom_getsymbol(argv)->s_name);
	 SETSYMBOL(a,atom_getsymbol(argv));
	 a++;
	 c_out++;
	 break;
       default:
	 post("prepend.c: unknown type");
       }
       argv++;
     }
     
     outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out);
     //post("done");
}

void prepend_list(t_prepend *x,t_symbol* s,t_int argc,t_atom* argv)
{
     int i = argc;
     t_symbol* cur;
     t_atom a_out[256];
     int    c_out = 0;
     t_atom* a = a_out;

     while (i--) {
       switch( argv->a_type) {
       case A_FLOAT:
	 //	 post("flo: %f",atom_getfloat(argv));
	 SETFLOAT(a,atom_getfloat(argv));
	 a++;
	 c_out++;
	 break;
       case A_SYMBOL:
	 //	 post("sym: %s",atom_getsymbol(argv)->s_name);
	 SETSYMBOL(a,atom_getsymbol(argv));
	 a++;
	 c_out++;
	 break;
       default:
	 post("prepend.c: unknown type");
       }
       argv++;
     }
     
     outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out);
     //post("done");
}

static void *prepend_new(t_symbol* s)
{
    t_prepend *x = (t_prepend *)pd_new(prepend_class);
    outlet_new(&x->x_obj, &s_float);
    if (s != &s_)
	 x->x_s = s;
    else
	 x->x_s = gensym("cxc.prepend");
    return (x);
}

static void prepend_set(t_prepend *x, t_symbol *s)
{
  x->x_s = s;
}

void prepend_setup(void)
{
    prepend_class = class_new(gensym("cxc.prepend"), (t_newmethod)prepend_new, 0,
				sizeof(t_prepend), 0,A_DEFSYM,NULL);
    class_addlist(prepend_class, prepend_list);
    class_addanything(prepend_class,prepend_anything);
    class_addmethod(prepend_class, (t_method)prepend_set, gensym("set"), A_SYMBOL, 0);
}