File: arraysize.c

package info (click to toggle)
pd-arraysize 0.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 156 kB
  • sloc: makefile: 592; ansic: 33
file content (58 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download | duplicates (5)
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
/* This code is too trivial to have a licence or copyright.

   However it was modeled after arraysize from pixlib,
   http://pix.test.at/pd/pixlib
*/

/*
	arraysize -- report the size of an array
	
	usage: |arraysize <array name>|

	methods: bang, set <array name>
*/

#include <m_pd.h>

static t_class *arraysize_class;

typedef struct _arraysize {
  t_object  x_obj;
  t_symbol *array_name;
} t_arraysize;

void arraysize_set(t_arraysize *x, t_symbol *s)
{
  x->array_name = s;
}

void arraysize_bang(t_arraysize *x)
{
  t_garray *garray;

  if(!(garray = (t_garray *)pd_findbyclass(x->array_name,garray_class))) {
    pd_error(x, "%s: no such table", x->array_name->s_name);
  } else {
    outlet_float(x->x_obj.ob_outlet, garray_npoints(garray));
  }
} 

void *arraysize_new(t_symbol *s)
{
  t_arraysize *x = (t_arraysize *)pd_new(arraysize_class);

  symbolinlet_new(&x->x_obj, &x->array_name);
  outlet_new(&x->x_obj, gensym("float"));

  x->array_name = s;

  return (void *)x;
}

void arraysize_setup(void)
{
  arraysize_class = class_new(gensym("arraysize"), (t_newmethod)arraysize_new, 0, sizeof(t_arraysize), CLASS_DEFAULT, A_DEFSYMBOL, 0);
  
  class_addmethod(arraysize_class,(t_method)arraysize_set,gensym("set"), A_DEFSYMBOL, 0);
  class_addbang(arraysize_class,arraysize_bang);
}