aboutsummaryrefslogtreecommitdiff
path: root/src/listUnfold.c
blob: 579f645826b940a911341cade8104bc922e420e8 (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
#include "m_pd.h"
#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)


static t_class *listUnfold_class;

typedef struct _listUnfold {
  t_object  x_obj;

  //t_float start;
  //t_float step;
   t_int iterating;
  t_outlet* outlet1;
  t_outlet* outlet2;
} t_listUnfold;


void listUnfold_bang(t_listUnfold *x)
{
  //x->i_count = x->i_down;
  x->iterating = 0;
  
}


void listUnfold_anything(t_listUnfold *x, t_symbol* s, int ac, t_atom* av)
{
	int i = 0;
	int count = 0;
    x->iterating = 1;
	 
	if ( s != &s_list && s != &s_float && s != &s_symbol ) {
		outlet_float(x->outlet2,0);
		outlet_symbol(x->outlet1,s);
		count++;
	}
	
	for ( ; i < ac; i++ ) {
		if ( !(x->iterating) ) break;
		outlet_float(x->outlet2,count);
		count++;
		if ( IS_A_FLOAT(av,i) ) {
			outlet_float(x->outlet1,atom_getfloat(av+i));
		} else {
			outlet_symbol(x->outlet1,atom_getsymbol(av+i));
		}
		
	}
	  
	
}


static void listUnfold_free(t_listUnfold *x)
{
		
    
}

void *listUnfold_new(t_symbol *s, int argc, t_atom *argv)
{
  t_listUnfold *x = (t_listUnfold *)pd_new(listUnfold_class);
  
  x->iterating = 0;
 
  
  //floatinlet_new(&x->x_obj, &x->start);
  //floatinlet_new(&x->x_obj, &x->step);
  x->outlet1 = outlet_new(&x->x_obj, &s_list);
  x->outlet2 = outlet_new(&x->x_obj, &s_float);


  return (void *)x;
}

void listUnfold_setup(void) {
  listUnfold_class = class_new(gensym("listUnfold"),
        (t_newmethod)listUnfold_new,
        (t_method)listUnfold_free, sizeof(t_listUnfold),
        CLASS_DEFAULT, 
        A_GIMME, 0);

  class_addbang  (listUnfold_class, listUnfold_bang);
  class_addanything (listUnfold_class, listUnfold_anything);
  //class_addlist (listUnfold_class, listUnfold_list);
  
}