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

« back to all changes in this revision

Viewing changes to src/multiplex.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   :  multiplex 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
/* ------------------------- mux ------------------------------- */
 
24
 
 
25
/*
 
26
  a multiplexer
 
27
*/
 
28
 
 
29
static t_class *mux_class;
 
30
static t_class *muxproxy_class;
 
31
 
 
32
typedef struct _mux
 
33
{
 
34
  t_object x_obj;
 
35
  struct _muxproxy  **x_proxy;
 
36
 
 
37
  int i_count;
 
38
  int i_selected;
 
39
  t_inlet **in;
 
40
} t_mux;
 
41
 
 
42
 
 
43
typedef struct _muxproxy
 
44
{
 
45
  t_pd  p_pd;
 
46
  t_mux    *p_master;
 
47
  int id;
 
48
} t_muxproxy;
 
49
 
 
50
static void mux_select(t_mux *x, t_float f)
 
51
{
 
52
  x->i_selected=f;
 
53
}
 
54
 
 
55
static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, t_atom *argv)
 
56
{
 
57
  t_mux*x=y->p_master;
 
58
  if(y->id==x->i_selected)
 
59
    outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
 
60
}
 
61
 
 
62
static void *mux_new(t_symbol *s, int argc, t_atom *argv)
 
63
{
 
64
  int n = (argc < 2)?2:argc;
 
65
  t_mux *x = (t_mux *)pd_new(mux_class);
 
66
 
 
67
  x->i_selected=0;
 
68
  x->i_count = n;
 
69
  x->in = (t_inlet **)getbytes(x->i_count * sizeof(t_inlet *));
 
70
  x->x_proxy = (t_muxproxy**)getbytes(x->i_count * sizeof(t_muxproxy*));
 
71
 
 
72
  for (n = 0; n<x->i_count; n++) {
 
73
    x->x_proxy[n]=(t_muxproxy*)pd_new(muxproxy_class);
 
74
    x->x_proxy[n]->p_master = x;
 
75
    x->x_proxy[n]->id=n;
 
76
    x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
 
77
  }
 
78
 
 
79
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym(""));
 
80
 
 
81
  outlet_new(&x->x_obj, 0);
 
82
  return (x);
 
83
}
 
84
 
 
85
static void mux_free(t_mux*x){
 
86
  const int count = x->i_count;
 
87
 
 
88
  if(x->in && x->x_proxy){
 
89
    int n=0;
 
90
    for(n=0; n<count; n++){
 
91
      if(x->in[n]){
 
92
        inlet_free(x->in[n]);
 
93
      }
 
94
      x->in[n]=0;
 
95
      if(x->x_proxy[n]){
 
96
        t_muxproxy *y=x->x_proxy[n];
 
97
        y->p_master=0;
 
98
        y->id=0;
 
99
        pd_free(&y->p_pd);        
 
100
      }
 
101
      x->x_proxy[n]=0;      
 
102
    }
 
103
    freebytes(x->in, x->i_count * sizeof(t_inlet *));
 
104
    freebytes(x->x_proxy, x->i_count * sizeof(t_muxproxy*));
 
105
  }
 
106
  
 
107
  /* pd_free(&y->p_pd); */
 
108
}
 
109
 
 
110
void multiplex_setup(void)
 
111
{
 
112
  mux_class = class_new(gensym("multiplex"), (t_newmethod)mux_new,
 
113
                        (t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME,  0);
 
114
  class_addcreator((t_newmethod)mux_new, gensym("mux"), A_GIMME, 0);
 
115
 
 
116
  class_addmethod   (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, 0);
 
117
 
 
118
  muxproxy_class = class_new(0, 0, 0,
 
119
                            sizeof(t_muxproxy),
 
120
                            CLASS_PD | CLASS_NOINLET, 0);
 
121
  class_addanything(muxproxy_class, mux_anything);
 
122
 
 
123
 
 
124
  zexy_register("multiplex");
 
125
}
 
126
 
 
127
void mux_setup(void)
 
128
{
 
129
  multiplex_setup();
 
130
}
 
131