~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/lister.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/* 2305:forum::f�r::uml�ute:2001 */
 
18
 
 
19
 
 
20
#include "zexy.h"
 
21
 
 
22
#ifdef HAVE_ALLOCA_H
 
23
# include <alloca.h>
 
24
#endif
 
25
 
 
26
/* ------------------------- list ------------------------------- */
 
27
 
 
28
/* this is for packages, what "float" is for floats */
 
29
 
 
30
#define LIST_NGETBYTE 100 /* bigger that this we use alloc, not alloca */
 
31
 
 
32
 
 
33
static t_class *mypdlist_class;
 
34
 
 
35
#ifdef HAVE_ALLOCA_H
 
36
# define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)((n) < LIST_NGETBYTE ?  \
 
37
        alloca((n) * sizeof(t_atom)) : getbytes((n) * sizeof(t_atom))))
 
38
# define ATOMS_FREEA(x, n) ( \
 
39
    ((n) < LIST_NGETBYTE || (freebytes((x), (n) * sizeof(t_atom)), 0)))
 
40
#else
 
41
# define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)getbytes((n) * sizeof(t_atom)))
 
42
# define ATOMS_FREEA(x, n) (freebytes((x), (n) * sizeof(t_atom)))
 
43
#endif
 
44
 
 
45
static void atoms_copy(int argc, t_atom *from, t_atom *to)
 
46
{
 
47
  int i;
 
48
  for (i = 0; i < argc; i++)
 
49
    to[i] = from[i];
 
50
}
 
51
 
 
52
 
 
53
static void mypdlist_storelist(t_mypdlist *x, int argc, t_atom *argv)
 
54
{
 
55
  if(x->x_list)freebytes(x->x_list, x->x_n*sizeof(t_atom));
 
56
  x->x_n=argc;
 
57
  x->x_list=(t_atom*)getbytes(x->x_n*sizeof(t_atom));
 
58
 
 
59
  atoms_copy(argc, argv, x->x_list);
 
60
}
 
61
static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
 
62
{
 
63
  mypdlist_storelist(x, argc, argv);
 
64
}
 
65
 
 
66
static void mypdlist_bang(t_mypdlist *x)
 
67
 
68
  int outc=x->x_n;
 
69
  t_atom*outv;
 
70
  ATOMS_ALLOCA(outv, outc);
 
71
  atoms_copy(x->x_n, x->x_list, outv);
 
72
  outlet_list(x->x_obj.ob_outlet, gensym("list"), outc, outv);
 
73
  ATOMS_FREEA(outv, outc);
 
74
}
 
75
 
 
76
 
 
77
static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
 
78
{
 
79
  mypdlist_secondlist(x, s, argc, argv);
 
80
  mypdlist_bang(x);
 
81
}
 
82
 
 
83
 
 
84
static void mypdlist_free(t_mypdlist *x)
 
85
{ freebytes(x->x_list, x->x_n * sizeof(t_atom)); }
 
86
 
 
87
static void *mypdlist_new(t_symbol *s, int argc, t_atom *argv)
 
88
{
 
89
  t_mypdlist *x = (t_mypdlist *)pd_new(mypdlist_class);
 
90
 
 
91
  outlet_new(&x->x_obj, 0);
 
92
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2"));
 
93
 
 
94
  x->x_n = 0;
 
95
  x->x_list = 0;
 
96
 
 
97
  if(argc)
 
98
    mypdlist_secondlist(x, gensym("list"), argc, argv);
 
99
 
 
100
  return (x);
 
101
}
 
102
 
 
103
 
 
104
static void mypdlist_help(t_mypdlist*x)
 
105
{
 
106
  post("\n%c lister\t\t:: basic list storage (use pd>=0.39 for real [list] objects)", HEARTSYMBOL);
 
107
}
 
108
 
 
109
void lister_setup(void)
 
110
{
 
111
  mypdlist_class = class_new(gensym("lister"), (t_newmethod)mypdlist_new, 
 
112
                             (t_method)mypdlist_free, sizeof(t_mypdlist), 0, A_GIMME, 0);
 
113
  /* i don't know how to get this work with name=="list" !!! */
 
114
 
 
115
  class_addcreator((t_newmethod)mypdlist_new, gensym("l"), A_GIMME, 0);
 
116
 
 
117
  class_addbang    (mypdlist_class, mypdlist_bang);
 
118
  class_addlist    (mypdlist_class, mypdlist_list);
 
119
  class_addmethod  (mypdlist_class, (t_method)mypdlist_secondlist, gensym("lst2"), A_GIMME, 0);
 
120
 
 
121
  class_addmethod(mypdlist_class, (t_method)mypdlist_help, gensym("help"), A_NULL);
 
122
  zexy_register("lister");
 
123
}
 
124
void l_setup(void)
 
125
{
 
126
  lister_setup();
 
127
}