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

« back to all changes in this revision

Viewing changes to src/packel.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
 
 
18
/* 3108:forum::f�r::uml�ute:2000 */
 
19
 
 
20
/* ------------------------- packel ------------------------------- */
 
21
 
 
22
/*
 
23
  get the nth element of a package
 
24
*/
 
25
 
 
26
#include "zexy.h"
 
27
 
 
28
static t_class *packel_class;
 
29
 
 
30
typedef struct _packel
 
31
{
 
32
  t_object x_obj;
 
33
  t_float *position;
 
34
  int count;
 
35
 
 
36
  t_inlet**x_inlet;
 
37
  t_outlet**x_outlet;
 
38
 
 
39
  int x_warningflag;
 
40
} t_packel;
 
41
 
 
42
 
 
43
static void packel_outelement(t_packel*x, int id, t_symbol*s,int argc, t_atom*argv)
 
44
{
 
45
  t_outlet*out=x->x_outlet[id];
 
46
  int index= x->position[id];
 
47
 
 
48
  if (index) {
 
49
    t_atom *current;
 
50
    int pos = (index < 0)?(argc+index):(index-1);
 
51
 
 
52
    if(argc==0){
 
53
      if (pos==0||pos==-1)outlet_bang(out);
 
54
      return;
 
55
    }
 
56
    
 
57
    if (pos < 0 || pos >= argc)return;
 
58
 
 
59
    current = &(argv[pos]);
 
60
 
 
61
    switch (current->a_type) {
 
62
    case A_NULL:
 
63
      outlet_bang(out);
 
64
    default:
 
65
      outlet_list(out, gensym("list"), 1, current);
 
66
    }
 
67
  } else outlet_list(out, s, argc, argv); 
 
68
}
 
69
 
 
70
static void packel_list(t_packel *x, t_symbol *s, int argc, t_atom *argv)
 
71
{
 
72
  int c=x->count;
 
73
  while(--c>=0) {
 
74
    packel_outelement(x, c, s, argc, argv);
 
75
  }
 
76
}
 
77
 
 
78
static void packel_anything(t_packel *x, t_symbol *s, int argc, t_atom *argv)
 
79
{
 
80
  t_atom *av2 = (t_atom *)getbytes((argc + 1) * sizeof(t_atom));
 
81
  int i;
 
82
 
 
83
  if(x->x_warningflag){
 
84
    pd_error(x, "deprecation warning: you should only use lists for list data");
 
85
    x->x_warningflag=0;
 
86
  }
 
87
 
 
88
  for (i = 0; i < argc; i++)
 
89
    av2[i + 1] = argv[i];
 
90
  SETSYMBOL(av2, s);
 
91
  packel_list(x, gensym("list"), argc+1, av2);
 
92
  freebytes(av2, (argc + 1) * sizeof(t_atom));
 
93
}
 
94
 
 
95
 
 
96
static void packel_free(t_packel *x)
 
97
{
 
98
  int i=0;
 
99
 
 
100
  for(i=0; i<x->count; i++) {
 
101
    if(x->x_inlet &&x->x_inlet [i])inlet_free (x->x_inlet [i]);
 
102
    if(x->x_outlet&&x->x_outlet[i])outlet_free(x->x_outlet[i]);
 
103
  }
 
104
 
 
105
  if(x->position)freebytes(x->position, x->count*sizeof(t_float));
 
106
  if(x->x_inlet) freebytes(x->x_inlet, x->count*sizeof(t_inlet*));
 
107
  if(x->x_outlet)freebytes(x->x_outlet, x->count*sizeof(t_outlet*));
 
108
 
 
109
}
 
110
 
 
111
 
 
112
static void *packel_new(t_symbol*s, int argc, t_atom*argv)
 
113
{
 
114
  t_packel *x = (t_packel *)pd_new(packel_class);
 
115
  
 
116
  x->count=(argc>0)?argc:1;
 
117
 
 
118
  x->position=(t_float*)getbytes(x->count*sizeof(t_float));
 
119
  x->x_inlet=(t_inlet**)getbytes(x->count*sizeof(t_inlet*));
 
120
  x->x_outlet=(t_outlet**)getbytes(x->count*sizeof(t_outlet*));
 
121
 
 
122
  if(argc<1) {
 
123
    x->position[0]=0.f;
 
124
    x->x_inlet[0]=floatinlet_new(&x->x_obj, x->position);
 
125
    x->x_outlet[0]=outlet_new(&x->x_obj, 0);
 
126
  } else {
 
127
    int i=0;
 
128
    for(i=0; i<x->count; i++) {
 
129
      x->position[i]=atom_getfloat(argv+i);
 
130
      x->x_inlet   [i]=floatinlet_new(&x->x_obj, x->position+i);
 
131
      x->x_outlet  [i]=outlet_new(&x->x_obj, 0);
 
132
    }
 
133
  }
 
134
  x->x_warningflag=1;
 
135
 
 
136
 
 
137
  return (x);
 
138
}
 
139
 
 
140
void packel_setup(void)
 
141
{
 
142
  packel_class = class_new(gensym("packel"), 
 
143
                           (t_newmethod)packel_new, (t_method)packel_free, 
 
144
                           sizeof(t_packel), 0,
 
145
                           A_GIMME, 0);
 
146
 
 
147
  class_addlist  (packel_class, packel_list);
 
148
  class_addanything(packel_class, packel_anything);
 
149
 
 
150
  zexy_register("packel");
 
151
}