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

« back to all changes in this revision

Viewing changes to src/glue.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
#include "zexy.h"
 
19
#include <string.h>
 
20
 
 
21
 
 
22
/* ------------------------- glue ------------------------------- */
 
23
 
 
24
/* glue 2 lists together (append) */
 
25
 
 
26
static t_class *glue_class;
 
27
 
 
28
typedef struct _zglue
 
29
{
 
30
  t_object x_obj;
 
31
 
 
32
  t_atom *ap2, *ap;
 
33
  t_int n1, n2, n;
 
34
 
 
35
  t_int changed;
 
36
} t_glue;
 
37
 
 
38
static void glue_lst2(t_glue *x, t_symbol *s, int argc, t_atom *argv)
 
39
{
 
40
  ZEXY_USEVAR(s);
 
41
  x->changed = 1;
 
42
  if (x->n2 != argc) {
 
43
    freebytes(x->ap2, x->n2 * sizeof(t_atom));
 
44
    x->n2 = argc;
 
45
    x->ap2 = copybytes(argv, argc * sizeof(t_atom));
 
46
  } else memcpy(x->ap2, argv, argc * sizeof(t_atom));
 
47
}
 
48
 
 
49
static void glue_lst(t_glue *x, t_symbol *s, int argc, t_atom *argv)
 
50
{
 
51
  ZEXY_USEVAR(s);
 
52
  if (x->n != x->n2+argc) {
 
53
    freebytes(x->ap, x->n * sizeof(t_atom));
 
54
    x->n1 = argc;
 
55
    x->n  = x->n1+x->n2;
 
56
    x->ap = (t_atom *)getbytes(sizeof(t_atom)*x->n);
 
57
    memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom));
 
58
  } else if ((x->n1 != argc)||x->changed)memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom));
 
59
 
 
60
  x->n1 = argc;
 
61
  memcpy(x->ap, argv, x->n1*sizeof(t_atom));
 
62
 
 
63
  x->changed=0;
 
64
 
 
65
  outlet_list(x->x_obj.ob_outlet, gensym("list"), x->n, x->ap);
 
66
}
 
67
 
 
68
static void glue_bang(t_glue *x)
 
69
{
 
70
  if (x->changed) {
 
71
    if (x->n1+x->n2 != x->n){
 
72
      t_atom *ap = (t_atom*)getbytes(sizeof(t_atom)*(x->n1+x->n2));
 
73
      memcpy(ap, x->ap, x->n1*sizeof(t_atom));
 
74
      freebytes(x->ap, sizeof(t_atom)*x->n);
 
75
      x->ap=ap;
 
76
      x->n=x->n1+x->n2;
 
77
    }
 
78
    memcpy(x->ap+x->n1, x->ap2, x->n2*sizeof(t_atom));
 
79
    x->changed=0;
 
80
  }
 
81
 
 
82
  outlet_list(x->x_obj.ob_outlet, gensym("list"), x->n, x->ap);
 
83
}
 
84
 
 
85
static void glue_free(t_glue *x)
 
86
{
 
87
  freebytes(x->ap,  sizeof(t_atom)*x->n);
 
88
  freebytes(x->ap2, sizeof(t_atom)*x->n2);
 
89
}
 
90
 
 
91
static void *glue_new(t_symbol *s, int argc, t_atom *argv)
 
92
{
 
93
  t_glue *x = (t_glue *)pd_new(glue_class);
 
94
  ZEXY_USEVAR(s);
 
95
 
 
96
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
 
97
  outlet_new(&x->x_obj, 0);
 
98
  x->n =x->n2  = 0;
 
99
  x->ap=x->ap2 = 0;
 
100
  x->changed   = 0;
 
101
 
 
102
  if (argc)glue_lst2(x, gensym("list"), argc, argv);
 
103
 
 
104
  return (x);
 
105
}
 
106
 
 
107
static void glue_help(t_glue*x)
 
108
{
 
109
  post("\n%c glue\t\t:: glue together 2 lists (like [list append])", HEARTSYMBOL);
 
110
}
 
111
 
 
112
void glue_setup(void)
 
113
{
 
114
  glue_class = class_new(gensym("glue"), (t_newmethod)glue_new, 
 
115
                         (t_method)glue_free, sizeof(t_glue), 0, A_GIMME, 0);
 
116
  class_addlist(glue_class, glue_lst);
 
117
  class_addmethod  (glue_class, (t_method)glue_lst2, gensym(""), A_GIMME, 0);
 
118
  class_addbang(glue_class, glue_bang);
 
119
  class_addmethod  (glue_class, (t_method)glue_help, gensym("help"), 0);
 
120
 
 
121
  zexy_register("glue");
 
122
}