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

« back to all changes in this revision

Viewing changes to src/step~.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
  step~  : will make a unity step at a desired point in the signal-vector; the second input specifies a 
 
18
  length:       after the so-specified time has elapsed, the step will toggle back to the previous
 
19
  value;
 
20
  the length can be passed as an argument when creating the object
 
21
  with length==1 you might do the dirac~ thing a little bit more complicated
 
22
  with length==0 the output just toggles between 0 and 1 every time you bang the object
 
23
 
 
24
  NOTE : the inlets do NOT specify any times but sample-NUMBERS; there are 64 samples in a signal-vector,
 
25
  each "lasting" for 1/44100 secs.
 
26
*/
 
27
 
 
28
#include "zexy.h"
 
29
 
 
30
/* ------------------------ step~ ----------------------------- */ 
 
31
 
 
32
static t_class *step_class;
 
33
 
 
34
typedef struct _step
 
35
{
 
36
  t_object x_obj;
 
37
  int position;
 
38
  int length;
 
39
 
 
40
  int toggle;
 
41
 
 
42
  int wait4start;
 
43
  int wait4stop;
 
44
} t_step;
 
45
 
 
46
static void step_bang(t_step *x)
 
47
{
 
48
  x->wait4stop = x->length + (x->wait4start = x->position);
 
49
}
 
50
 
 
51
static void step_float(t_step *x, t_float where)
 
52
{
 
53
  x->wait4stop = x->length + 
 
54
    (x->wait4start =
 
55
     (x->position = (where>0)*where)
 
56
     );
 
57
}
 
58
 
 
59
static void step_setlength(t_step *x, t_float arg)
 
60
{
 
61
  x->length = 1 + (arg>0)*arg;
 
62
}
 
63
 
 
64
 
 
65
 
 
66
static t_int *step_perform(t_int *w)
 
67
{
 
68
  t_step *x = (t_step *)(w[1]);
 
69
  t_sample *out = (t_sample *)(w[2]);
 
70
  int n = (int)(w[3]);
 
71
 
 
72
  int toggle = x->toggle;
 
73
 
 
74
  int wait4start = x->wait4start, wait4stop = x->wait4stop;
 
75
 
 
76
  while (n--)
 
77
    {
 
78
      wait4stop--;
 
79
      if (!wait4start--) toggle ^= 1;
 
80
      else if (!wait4stop) toggle ^= 1;
 
81
 
 
82
      *out++ = toggle;          
 
83
    }
 
84
 
 
85
  x->wait4start = wait4start;
 
86
  x->wait4stop = wait4stop;
 
87
 
 
88
  x->toggle = toggle;
 
89
  return (w+4);
 
90
}
 
91
 
 
92
static void step_dsp(t_step *x, t_signal **sp)
 
93
{
 
94
  dsp_add(step_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
 
95
}
 
96
 
 
97
 
 
98
static void step_helper(void)
 
99
{
 
100
  post("%c step~-object :: generates a unity-step", HEARTSYMBOL);
 
101
  post("creation : \"dirac~ [<position> [<length>]]\" : create a rectangular window\n"
 
102
       "\t\t\tat specified position and with specified length (in samples)\n"
 
103
       "inlet1\t: <position>\t: create a rectangular window at new position\n"
 
104
       "\t  'bang'\t: create a rectangular window at specified position\n"
 
105
       "\t  'help'\t: view this\n"
 
106
       "inlet2\t: <length>\t: define new window length ('0' will make a unity-step)\n"
 
107
       "outlet\t: signal~");
 
108
}
 
109
 
 
110
 
 
111
static void *step_new(t_floatarg farg)
 
112
{
 
113
  t_step *x = (t_step *)pd_new(step_class);
 
114
 
 
115
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
 
116
  outlet_new(&x->x_obj, &s_signal);
 
117
 
 
118
  x->position = 0;
 
119
  x->wait4start = x->wait4stop = 0;
 
120
  x->toggle = 1;
 
121
 
 
122
  step_setlength(x, farg);
 
123
 
 
124
  return (x);
 
125
}
 
126
 
 
127
void step_tilde_setup(void)
 
128
{
 
129
  step_class = class_new(gensym("step~"), (t_newmethod)step_new, 0,
 
130
                         sizeof(t_step), 0, A_DEFFLOAT, 0);
 
131
 
 
132
  class_addfloat(step_class, step_float);
 
133
  class_addbang(step_class, step_bang); 
 
134
  class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), A_FLOAT, 0);
 
135
  class_addmethod(step_class, (t_method)step_dsp, gensym("dsp"), 0);
 
136
 
 
137
  class_addmethod(step_class, (t_method)step_helper, gensym("help"), 0);
 
138
 
 
139
  zexy_register("step~");
 
140
}