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

« back to all changes in this revision

Viewing changes to src/pack.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
/* 1903:forum::f�r::uml�ute:2005 */
 
3
 
 
4
/*
 
5
 *  mulitplex   :  zpack a specified input to the output
 
6
 *
 
7
 * THINK: should the selector-inlet be the first or the last ???
 
8
 * pros/cons:
 
9
 *  the 1st inlet being the selector is not consistant with pd (hot/cold)
 
10
 *   but as it since the hot inlet is selectable, the whole object is not really consitant
 
11
 *  numbering would have to start with 1 (for the 1st not-leftmost inlet)
 
12
 * if the selector is rightmost this would mean: cold is right(most), hot is (somewhere) left
 
13
 * numbering would be ok
 
14
 *
 
15
 * conclusio: make the selector rightmost
 
16
 *
 
17
 */
 
18
 
 
19
#include "zexy.h"
 
20
#include <stdio.h>
 
21
 
 
22
 
 
23
/* ------------------------- zpack ------------------------------- */
 
24
 
 
25
/*
 
26
  a zpacker
 
27
*/
 
28
 
 
29
static t_class *zpack_class;
 
30
static t_class *zpackproxy_class;
 
31
 
 
32
typedef struct _zpack
 
33
{
 
34
  t_object x_obj;
 
35
  struct _zpackproxy  **x_proxy;
 
36
 
 
37
  t_inlet **in;
 
38
 
 
39
  t_atom*x_argv;
 
40
  int    x_argc;
 
41
} t_zpack;
 
42
 
 
43
 
 
44
typedef struct _zpackproxy
 
45
{
 
46
  t_pd  p_pd;
 
47
  t_zpack    *p_master;
 
48
  int id;
 
49
} t_zpackproxy;
 
50
 
 
51
 
 
52
static void setatom(t_zpack *x, t_atom*from, int to) {
 
53
  x->x_argv[to].a_type=from->a_type;
 
54
  x->x_argv[to].a_w   =from->a_w;
 
55
}
 
56
 
 
57
static void zpack_bang(t_zpack*x) {
 
58
  outlet_list(x->x_obj.ob_outlet, gensym("list"), x->x_argc, x->x_argv);
 
59
}
 
60
 
 
61
static void zpack_list0(t_zpack*x, t_symbol *s, int argc, t_atom *argv) {
 
62
  int i=0;
 
63
  for(i=0; i<argc && i<x->x_argc; i++)
 
64
    setatom(x, argv+i, i);
 
65
  zpack_bang(x);
 
66
}
 
67
 
 
68
static void zpack_list(t_zpackproxy *y, t_symbol *s, int argc, t_atom *argv)
 
69
{
 
70
  if(argc>0)
 
71
    setatom(y->p_master, argv, y->id);
 
72
}
 
73
 
 
74
static void *zpack_new(t_symbol *s, int argc, t_atom *argv)
 
75
{
 
76
  t_zpack *x = (t_zpack *)pd_new(zpack_class);
 
77
  int n =0;
 
78
 
 
79
  x->x_argc = (argc < 1)?2:argc;
 
80
 
 
81
 
 
82
  if(argc<1) {
 
83
    x->x_argv=(t_atom*)getbytes(2*sizeof(t_atom));
 
84
    SETFLOAT(x->x_argv+0, 0.f);
 
85
    SETFLOAT(x->x_argv+1, 0.f);
 
86
  } else {
 
87
    int i=0;
 
88
    x->x_argv=(t_atom*)getbytes(x->x_argc*sizeof(t_atom));
 
89
    for(i=0; i<x->x_argc; i++)
 
90
      setatom(x, argv+i, i);
 
91
  }
 
92
 
 
93
  x->in = (t_inlet **)getbytes(x->x_argc * sizeof(t_inlet *));
 
94
  x->x_proxy = (t_zpackproxy**)getbytes(x->x_argc * sizeof(t_zpackproxy*));
 
95
 
 
96
  x->in[0]     =0;
 
97
  x->x_proxy[0]=0;
 
98
 
 
99
  for (n = 1; n<x->x_argc; n++) {
 
100
    x->x_proxy[n]=(t_zpackproxy*)pd_new(zpackproxy_class);
 
101
    x->x_proxy[n]->p_master = x;
 
102
    x->x_proxy[n]->id=n;
 
103
    x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
 
104
  }
 
105
 
 
106
  outlet_new(&x->x_obj, 0);
 
107
  return (x);
 
108
}
 
109
 
 
110
static void zpack_free(t_zpack*x){
 
111
  const int count = x->x_argc;
 
112
 
 
113
  if(x->in && x->x_proxy){
 
114
    int n=0;
 
115
    for(n=0; n<count; n++){
 
116
      if(x->in[n]){
 
117
        inlet_free(x->in[n]);
 
118
      }
 
119
      x->in[n]=0;
 
120
      if(x->x_proxy[n]){
 
121
        t_zpackproxy *y=x->x_proxy[n];
 
122
        y->p_master=0;
 
123
        y->id=0;
 
124
        pd_free(&y->p_pd);        
 
125
      }
 
126
      x->x_proxy[n]=0;      
 
127
    }
 
128
    freebytes(x->in, x->x_argc * sizeof(t_inlet *));
 
129
    freebytes(x->x_proxy, x->x_argc * sizeof(t_zpackproxy*));
 
130
  }
 
131
}
 
132
 
 
133
void zpack_setup(void)
 
134
{
 
135
  zpack_class = class_new(gensym("zexy/pack"), (t_newmethod)zpack_new,
 
136
                        (t_method)zpack_free, sizeof(t_zpack), 0, A_GIMME,  0);
 
137
#if 0
 
138
  /* oops Pd-0.42 allows us to override built-ins
 
139
   * this is bad as long as the 2 objects are not compatible */
 
140
  class_addcreator((t_newmethod)zpack_new, gensym("pack"), A_GIMME, 0);
 
141
#endif
 
142
  class_addbang(zpack_class, zpack_bang);
 
143
  class_addlist(zpack_class, zpack_list0);
 
144
 
 
145
  zpackproxy_class = class_new(gensym("zpack proxy"), 0, 0,
 
146
                            sizeof(t_zpackproxy),
 
147
                            CLASS_PD | CLASS_NOINLET, 0);
 
148
  class_addlist(zpackproxy_class, zpack_list);
 
149
 
 
150
 
 
151
  zexy_register("pack");
 
152
}
 
153
 
 
154
void pack_setup(void)
 
155
{
 
156
  zpack_setup();
 
157
}
 
158