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

« back to all changes in this revision

Viewing changes to src/relay.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:2005
 
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
   (c) 2106:forum::f�r::uml�ute:2005
 
19
 
 
20
   "relay" is like "relay" but doesn't change the incoming list
 
21
 
 
22
   example:
 
23
     [foo bar( --> [relay foo] --> [bar(
 
24
     [foo bar( --> [relay foo] --> [foor bar(
 
25
 
 
26
   namings: 
 
27
     direct, channel, relay, steer, guide, ??
 
28
 
 
29
     in the meantime i choose [relay] (as in mail-relay)
 
30
 
 
31
*/
 
32
 
 
33
 
 
34
#include "zexy.h"
 
35
 
 
36
/* -------------------------- relay ------------------------------ */
 
37
 
 
38
static t_class *relay_class;
 
39
 
 
40
typedef struct _relayelement
 
41
{
 
42
    t_word e_w;
 
43
    t_outlet *e_outlet;
 
44
} t_relayelement;
 
45
 
 
46
typedef struct _relay
 
47
{
 
48
    t_object x_obj;
 
49
    t_atomtype x_type;
 
50
    t_int x_nelement;
 
51
    t_relayelement *x_vec;
 
52
    t_outlet *x_rejectout;
 
53
} t_relay;
 
54
 
 
55
static void relay_anything(t_relay *x, t_symbol *sel, int argc, t_atom *argv)
 
56
{
 
57
    t_relayelement *e;
 
58
    int nelement;
 
59
    if (x->x_type == A_SYMBOL) 
 
60
    {
 
61
      for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
62
        if (e->e_w.w_symbol == sel)
 
63
          {
 
64
            outlet_anything(e->e_outlet, sel, argc, argv);
 
65
            return;
 
66
          }
 
67
    }
 
68
    outlet_anything(x->x_rejectout, sel, argc, argv);
 
69
}
 
70
 
 
71
static void relay_list(t_relay *x, t_symbol *sel, int argc, t_atom *argv)
 
72
{
 
73
  t_relayelement *e;
 
74
  int nelement;
 
75
  if (x->x_type == A_FLOAT)
 
76
    {
 
77
      t_float f;
 
78
      if (!argc){
 
79
        outlet_bang(x->x_rejectout);
 
80
        return;
 
81
      }
 
82
      f = atom_getfloat(argv);
 
83
      for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
84
        if (e->e_w.w_float == f)
 
85
          {
 
86
            outlet_anything(e->e_outlet, sel, argc, argv);
 
87
            return;
 
88
          }
 
89
    }
 
90
  else    /* symbol arguments */
 
91
    {
 
92
      if (argc == 0)         /* no args: treat as "bang" */
 
93
        {
 
94
          for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
95
            {
 
96
              if (e->e_w.w_symbol == &s_bang)
 
97
                {
 
98
                  outlet_bang(e->e_outlet);
 
99
                  return;
 
100
                }
 
101
            }
 
102
        }
 
103
      else if (argc>1)
 
104
        {
 
105
          for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
106
            { 
 
107
              if (e->e_w.w_symbol == &s_list)
 
108
                {
 
109
                  outlet_anything(e->e_outlet, sel, argc, argv);
 
110
                  return;
 
111
                }
 
112
            }
 
113
        }
 
114
        else if (argv[0].a_type == A_FLOAT)     /* one float arg */
 
115
        {
 
116
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
117
            {
 
118
                if (e->e_w.w_symbol == &s_float)
 
119
                {
 
120
                    outlet_float(e->e_outlet, argv[0].a_w.w_float);
 
121
                    return;
 
122
                }
 
123
            }
 
124
        }
 
125
        else
 
126
        {
 
127
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
 
128
            {
 
129
                if (e->e_w.w_symbol == &s_symbol)
 
130
                {
 
131
                    outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol);
 
132
                    return;
 
133
                }
 
134
            }
 
135
        }
 
136
    }
 
137
  outlet_list(x->x_rejectout, &s_list, argc, argv);
 
138
}
 
139
 
 
140
 
 
141
static void relay_free(t_relay *x)
 
142
{
 
143
    freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec));
 
144
}
 
145
 
 
146
static void *relay_new(t_symbol *s, int argc, t_atom *argv)
 
147
{
 
148
    int n;
 
149
    t_relayelement *e;
 
150
    t_relay *x = (t_relay *)pd_new(relay_class);
 
151
    t_atom a;
 
152
    ZEXY_USEVAR(s);
 
153
    if (argc == 0)
 
154
    {
 
155
        argc = 1;
 
156
        SETFLOAT(&a, 0);
 
157
        argv = &a;
 
158
    }
 
159
    x->x_type = argv[0].a_type;
 
160
    x->x_nelement = argc;
 
161
    x->x_vec = (t_relayelement *)getbytes(argc * sizeof(*x->x_vec));
 
162
    for (n = 0, e = x->x_vec; n < argc; n++, e++)
 
163
    {
 
164
        e->e_outlet = outlet_new(&x->x_obj, &s_list);
 
165
        if (x->x_type == A_FLOAT)
 
166
            e->e_w.w_float = atom_getfloatarg(n, argc, argv);
 
167
        else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv);
 
168
    }
 
169
    x->x_rejectout = outlet_new(&x->x_obj, &s_list);
 
170
    return (x);
 
171
}
 
172
 
 
173
void relay_setup(void)
 
174
{
 
175
    relay_class = class_new(gensym("relay"), (t_newmethod)relay_new,
 
176
        (t_method)relay_free, sizeof(t_relay), 0, A_GIMME, 0);
 
177
    class_addlist(relay_class, relay_list);
 
178
    class_addanything(relay_class, relay_anything);
 
179
    zexy_register("relay");
 
180
}