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

« back to all changes in this revision

Viewing changes to src/tabminmax.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
/* hack : 2108:forum::f�r::uml�ute:1999 @ iem */
 
18
 
 
19
#include "zexy.h"
 
20
 
 
21
 
 
22
/* =================== tabminmax ====================== */
 
23
 
 
24
static t_class *tabminmax_class;
 
25
 
 
26
typedef struct _tabminmax
 
27
{
 
28
  t_object x_obj;
 
29
  t_outlet*min_out, *max_out;
 
30
  t_symbol *x_arrayname;
 
31
  t_int startindex, stopindex;
 
32
} t_tabminmax;
 
33
 
 
34
static void tabminmax_bang(t_tabminmax *x)
 
35
{
 
36
  t_garray *A;
 
37
  int npoints;
 
38
  zarray_t *vec;
 
39
 
 
40
  if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
 
41
    error("%s: no such array", x->x_arrayname->s_name);
 
42
  else if (!zarray_getarray(A, &npoints, &vec))
 
43
    error("%s: bad template for tabminmax", x->x_arrayname->s_name);
 
44
  else
 
45
    {
 
46
      int n;
 
47
      t_atom atombuf[2];
 
48
      t_float min, max;
 
49
      int mindex, maxdex;
 
50
 
 
51
      int start=x->startindex;
 
52
      int stop =x->stopindex;
 
53
      if(start<0||start>stop)start=0;
 
54
      if(stop<start||stop>npoints)stop=npoints;
 
55
      npoints=stop-start;
 
56
 
 
57
      min=zarray_getfloat(vec, start);
 
58
      max=min;
 
59
 
 
60
      mindex=start;
 
61
      maxdex=start;
 
62
      
 
63
      for (n = 1; n < npoints; n++){
 
64
        t_float val=zarray_getfloat(vec, start+n);
 
65
        if(val<min){
 
66
          mindex=start+n;
 
67
          min=val;
 
68
        }
 
69
        if(val>max){
 
70
          maxdex=start+n;
 
71
          max=val;
 
72
        }
 
73
      }
 
74
      
 
75
      SETFLOAT(atombuf, max);
 
76
      SETFLOAT(atombuf+1, maxdex);
 
77
      outlet_list(x->max_out, &s_list, 2, atombuf);
 
78
      
 
79
      SETFLOAT(atombuf, min);
 
80
      SETFLOAT(atombuf+1, mindex);
 
81
      outlet_list(x->min_out, &s_list, 2, atombuf);
 
82
    }
 
83
}
 
84
 
 
85
static void tabminmax_list(t_tabminmax *x, t_symbol*s,int argc, t_atom*argv)
 
86
{
 
87
  int a,b;
 
88
  ZEXY_USEVAR(s);
 
89
  switch(argc){
 
90
  case 2:
 
91
    a=atom_getint(argv);
 
92
    b=atom_getint(argv+1);
 
93
    x->startindex=(a<b)?a:b;
 
94
    x->stopindex =(a>b)?a:b;
 
95
    tabminmax_bang(x);
 
96
    break;
 
97
  default:
 
98
    error("tabminmax: list must be 2 floats (is %d atoms)", argc);
 
99
  }
 
100
}
 
101
 
 
102
static void tabminmax_set(t_tabminmax *x, t_symbol *s)
 
103
{
 
104
  x->x_arrayname = s;
 
105
}
 
106
 
 
107
static void *tabminmax_new(t_symbol *s)
 
108
{
 
109
  t_tabminmax *x = (t_tabminmax *)pd_new(tabminmax_class);
 
110
  x->x_arrayname = s;
 
111
  x->startindex=0;
 
112
  x->stopindex=-1;
 
113
  x->min_out=outlet_new(&x->x_obj, &s_list);
 
114
  x->max_out=outlet_new(&x->x_obj, &s_list);
 
115
 
 
116
  return (x);
 
117
}
 
118
 
 
119
static void tabminmax_helper(void)
 
120
{
 
121
  post("\n%c tabminmax - object : dumps a table as a package of floats", HEARTSYMBOL);
 
122
  post("'set <table>'\t: read out another table\n"
 
123
       "'bang'\t\t: get min and max of the table\n"
 
124
       "outlet\t\t: table-data as package of floats");
 
125
  post("creation\t: \"tabminmax <table>\"");
 
126
 
 
127
}
 
128
 
 
129
void tabminmax_setup(void)
 
130
{
 
131
  tabminmax_class = class_new(gensym("tabminmax"), (t_newmethod)tabminmax_new,
 
132
                             0, sizeof(t_tabminmax), 0, A_DEFSYM, 0);
 
133
  class_addbang(tabminmax_class, (t_method)tabminmax_bang);
 
134
  class_addlist(tabminmax_class, (t_method)tabminmax_list);
 
135
 
 
136
  class_addmethod(tabminmax_class, (t_method)tabminmax_set, gensym("set"),
 
137
                  A_SYMBOL, 0);
 
138
 
 
139
  class_addmethod(tabminmax_class, (t_method)tabminmax_helper, gensym("help"), 0);
 
140
  zexy_register("tabminmax");
 
141
}