Update of /cvsroot/pure-data/externals/markex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19429
Modified Files: README Added Files: abs~.c average-help.pd average.c change-help.pd change.c counter-help.pd counter.c reson~.c Removed Files: gem_average-help.pd gem_average.c gem_change-help.pd gem_change.c gem_counter-help.pd gem_counter.c Log Message: converted things to fit in with the namespace
--- NEW FILE: abs~.c --- /* * Copyright (c) 1997-1999 Mark Danks. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. */
#include "m_pd.h" #include <math.h>
/* ------------------------- abs~ -------------------------- */ static t_class *abs_class;
typedef struct _abs { t_object x_obj; } t_abs;
static t_int *abs_perform(t_int *w) { //t_abs *x = (t_abs *)(w[1]); t_float *in = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); while (n--) { float f = *in++; if (f < 0) f = -f; *out++ = f; } return (w+5); }
static void abs_dsp(t_abs *x, t_signal **sp) { dsp_add(abs_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); }
static void *abs_new() { t_abs *x = (t_abs *)pd_new(abs_class); outlet_new(&x->x_obj, &s_signal); return (x); }
void abs_tilde_setup(void) { abs_class = class_new(gensym("abs~"), (t_newmethod)abs_new, 0, sizeof(t_abs), 0, A_NULL); class_addmethod(abs_class, (t_method)nullfn, &s_signal, A_NULL); class_addmethod(abs_class, (t_method)abs_dsp, gensym("dsp"), A_NULL); }
--- gem_change.c DELETED ---
--- NEW FILE: average.c --- /* * Copyright (c) 1997-1999 Mark Danks. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. */
#include "m_pd.h"
/* -------------------------- alternate ------------------------------ */
/* instance structure */ static t_class *average_class;
typedef struct _average { t_object x_obj; /* obligatory object header */ int a_total; /* number of numbers to average */ int a_whichNum; /* which number are pointing at */ float a_numbers[100]; /* numbers to average, 100 maximum */ t_outlet *t_out1; /* the outlet */ } t_average;
void average_bang(t_average *x) { float average = 0.0f; int n;
for (n = 0; n < x->a_total; n++) average = average + x->a_numbers[n]; average = average / (float)x->a_total;
outlet_float(x->t_out1, average); }
void average_float(t_average *x, t_floatarg n) { if (x->a_whichNum >= x->a_total) x->a_whichNum = 0; x->a_numbers[x->a_whichNum] = n; x->a_whichNum++; average_bang(x); }
void average_total(t_average *x, t_floatarg n) { x->a_total = (int)n; }
void average_reset(t_average *x, t_floatarg newVal) { int n; for (n=0; n < 100; n ++) x->a_numbers[n] = newVal; }
void average_clear(t_average *x) { int n; for ( n = 0; n < 100; n ++) x->a_numbers[n] = 0.0f; }
void *average_new(t_floatarg f) /* init vals in struc */ { t_average *x = (t_average *)pd_new(average_class); x->t_out1 = outlet_new(&x->x_obj, 0); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); average_clear(x); if (f) x->a_total = (int)f; else x->a_total = 10; x->a_whichNum = 0; return (x); }
void average_setup(void) { average_class = class_new(gensym("average"), (t_newmethod)average_new, 0, sizeof(t_average), 0, A_DEFFLOAT, 0); class_addbang(average_class, (t_method)average_bang); class_addfloat(average_class, (t_method)average_float); class_addmethod(average_class, (t_method)average_total, gensym("fl1"), A_FLOAT, 0); class_addmethod(average_class, (t_method)average_clear, gensym("clear"), A_NULL); class_addmethod(average_class, (t_method)average_reset, gensym("reset"), A_FLOAT, 0);
#if PD_MINOR_VERSION < 37
#endif }
--- gem_counter.c DELETED ---
--- gem_counter-help.pd DELETED ---
--- NEW FILE: average-help.pd --- #N canvas 271 381 600 500 10; #X text 124 68 GEM object; #X obj 123 298 print out1; #X obj 123 220 average; #X floatatom 123 160 0 0 0; #X msg 184 162 bang; #X msg 247 164 reset 5; #X msg 345 168 clear; #X text 89 408 The initial argument is the number to average together. The default is 10 numbers.; #X obj 421 231 average 20; #X text 139 23 [average]; #X text 81 371 [average] together a series of numbers.; #X connect 2 0 1 0; #X connect 3 0 2 0; #X connect 4 0 2 0; #X connect 5 0 2 0; #X connect 6 0 2 0;
--- gem_average.c DELETED ---
--- NEW FILE: counter-help.pd --- #N canvas 597 145 600 590 10; #X text 124 68 GEM object; #X obj 123 298 print out1; #X text 138 23 counter; #X msg 123 97 bang; #X text 58 362 counter counts the number of bangs; #X obj 123 220 counter 0 5; #X msg 319 154 bang; #X text 58 394 The third argument is the direction 1 == up 2 == down 3 == up and down; #X obj 319 297 print out2; #X obj 319 219 counter 0 5 3; #X obj 195 265 print done1; #X obj 405 267 print done2; #X text 58 439 The right outlet sends a bang when the counter rolls over. The bang occurs after the left inlet sends the value.; #X msg 147 129 direction; #X msg 171 154 low value; #X msg 195 182 high value; #X msg 71 176 reset; #X msg 26 177 clear; #X text 58 524 A reset message will set the counter back to the starting value and send the value out the left outlet.; #X text 58 486 A clear message will set the counter back to the starting value.; #X text 331 189 count from 0 to 5 and back down to 0; #X connect 3 0 5 0; #X connect 5 0 1 0; #X connect 5 1 10 0; #X connect 6 0 9 0; #X connect 9 0 8 0; #X connect 9 1 11 0; #X connect 13 0 5 1; #X connect 14 0 5 2; #X connect 15 0 5 3; #X connect 16 0 5 0; #X connect 17 0 5 0;
--- gem_average-help.pd DELETED ---
--- NEW FILE: reson~.c --- /* * Copyright (c) 1997-1999 Mark Danks. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. */
/* Original code by Miller Puckette */ /* a non-interpolating reson filter, not very carefully coded... */ /* 11/29/94 modified to do interpolation - M. Danks */
#include "m_pd.h"
#include <stdlib.h>
#define BUFSIZE 4096
typedef struct resonctl { float c_freq; float c_samprate; float c_feedback; int c_delayinsamps; float c_fraction; int c_phase; float *c_buf; } t_resonctl;
typedef struct sigreson { t_object x_obj; /* header */ t_resonctl *x_ctl; /* pointer to state */ t_resonctl x_cspace; /* garage for state when not in a chain */ } t_sigreson;
/* the DSP routine -- called for every n samples of input */ static t_int *cu_reson(t_int *w) { t_float *in1 = (t_float *)(w[1]); t_float *in2 = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); t_resonctl *x = (t_resonctl *)(w[4]); int n = (int)(w[5]); long i; int writephase = x->c_phase; for (i = 0; i < n; i++) { /* note two tricks: 1. input is read before output * is written, because the routine might be called * in-place; * 2 - a seed of 1E-20 is thrown in to avoid floating * underflow which slows the calculation down. */ int readphase, phase, delayinsamps; float fraction, f, g, freq, freqtemp;
float ftemp; freq = *in2++; freqtemp = (freq < 1 ? 1 : freq); ftemp = x->c_samprate/freqtemp; if (ftemp >= BUFSIZE-1) ftemp = BUFSIZE - 1.f; else if (ftemp < 1.0) ftemp = 1.f; delayinsamps = (int)ftemp; fraction = ftemp - delayinsamps;
readphase = writephase - delayinsamps; phase = readphase & (BUFSIZE-1); f = x->c_buf[phase] + fraction * (x->c_buf[(phase-1)& (BUFSIZE-1)] - x->c_buf[phase]); g = *in1++; *out++ = x->c_buf[(writephase++) & (BUFSIZE-1)] = g + x->c_feedback * f + 1E-20f; } x->c_phase = writephase & (BUFSIZE-1); return (w+6); }
/* sets the reson frequency */
void sigreson_float(t_sigreson *x, t_floatarg f) { float ftemp; x->x_ctl->c_freq = (f < 1 ? 1 : f); ftemp = x->x_ctl->c_samprate/x->x_ctl->c_freq; if (ftemp >= BUFSIZE - 1) ftemp = BUFSIZE - 1.f; else if (ftemp < 1.0) ftemp = 1.f; x->x_ctl->c_delayinsamps = (int)ftemp; x->x_ctl->c_fraction = ftemp - x->x_ctl->c_delayinsamps; }
/* routine which FTS calls to put you on the DSP chain or take you off. */
static void sigreson_dsp(t_sigreson *x, t_signal **sp) { x->x_ctl->c_samprate = sp[0]->s_sr; sigreson_float(x, x->x_ctl->c_freq); dsp_add(cu_reson, 5, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, x->x_ctl, sp[0]->s_n); }
static void sigreson_ft1(t_sigreson *x, t_floatarg f) /* sets feedback */ { if (f > .99999) f = .99999f; else if (f < -.99999) f = -.99999f; x->x_ctl->c_feedback = (float)f; }
static void sigreson_ff(t_sigreson *x) /* cleanup on free */ { free(x->x_ctl->c_buf); }
static t_class *sigreson_class;
void *sigreson_new(t_floatarg f, t_floatarg g) { t_sigreson *x = (t_sigreson *)pd_new(sigreson_class); outlet_new(&x->x_obj, &s_signal);
/* things in "cspace" are things you'll actually use at DSP time */ x->x_cspace.c_phase = 0; if (!(x->x_cspace.c_buf = (float *)malloc(BUFSIZE * sizeof(float)))) { error("buffer alloc failed"); return (0); } x->x_cspace.c_samprate = 44100.f; /* just a plausible default */
/* control block is in the garage at startup */ x->x_ctl = &x->x_cspace; sigreson_float(x, (t_float)f); /* setup params */ sigreson_ft1(x, g); /* make a "float" inlet */ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); return (x); }
void reson_tilde_setup() { sigreson_class = class_new(gensym("reson~"), (t_newmethod)sigreson_new, (t_method)sigreson_ff, sizeof(t_sigreson), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(sigreson_class, (t_method)sigreson_float); class_addmethod(sigreson_class, (t_method)sigreson_ft1, gensym("ft1"), A_FLOAT, 0); class_addmethod(sigreson_class, (t_method)nullfn, &s_signal, A_NULL); class_addmethod(sigreson_class, (t_method)sigreson_dsp, gensym("dsp"), A_NULL); }
--- NEW FILE: change.c --- /* * Copyright (c) 1997-1999 Mark Danks. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. */
#include "m_pd.h"
/* -------------------------- change ------------------------------ */
/* instance structure */
static t_class *change_class;
typedef struct _change { t_object x_obj; /* obligatory object header */ float x_cur; t_outlet *t_out1; /* the outlet */ } t_change;
static void change_float(t_change *x, t_floatarg n) { if (n != x->x_cur) { outlet_float(x->t_out1, n); x->x_cur = n; } }
static void *change_new(void) /* init vals in struc */ { t_change *x = (t_change *)pd_new(change_class); x->x_cur = -1.f; x->t_out1 = outlet_new(&x->x_obj, 0); return(x); }
void change_setup(void) { change_class = class_new(gensym("change"), (t_newmethod)change_new, 0, sizeof(t_change), 0, A_NULL); class_addfloat(change_class, change_float);
#if PD_MINOR_VERSION < 37
#endif }
Index: README =================================================================== RCS file: /cvsroot/pure-data/externals/markex/README,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README 30 Jul 2003 21:52:27 -0000 1.1 --- README 8 Dec 2005 05:24:58 -0000 1.2 *************** *** 9,33 **** proper part of this repository.
- - ------------------------------ - CONFLICTS - ------------------------------ - - These objects have name conflicts with other objects/libs therefore: - - Name Conflicts with - ----------------------------------- - [average] (maxlib) - [counter] (cxc,cyclone) - [change] (pd) - - Since these names have all been taken, these objects have been renamed by - adding "gem_" before the original name. - - - ------------------------------ - OMISSIONS - ------------------------------ - - [reson~] has been left out since it is now part of cxc. - [abs~] has been left out since its now part of creb. --- 9,10 ----
--- NEW FILE: counter.c --- /* * Copyright (c) 1997-1999 Mark Danks. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. */
#include "m_pd.h"
/* -------------------------- counter ------------------------------ */
/* instance structure */ static t_class *counter_class;
typedef struct _counter { t_object x_obj; /* obligatory object header */ int c_current; /* current number */ int c_high; /* highest number */ int c_low; /* lowest number */ int c_updown; /* 0 = going up, 1 = going down */ int c_dir; /* counter dir. 1=up, 2=down, 3=up/down */ t_outlet *t_out1; /* the outlet */ t_outlet *t_out2; /* the outlet */ } t_counter;
void counter_bang(t_counter *x) { int sendBang = 0; switch(x->c_dir) { // count up case 1: x->c_current++; if (x->c_current > x->c_high) x->c_current = x->c_low; else if (x->c_current < x->c_low) x->c_current = x->c_low; else if (x->c_current == x->c_high) sendBang = 1; break; // count down case 2: x->c_current--; if (x->c_current < x->c_low) x->c_current = x->c_high; else if (x->c_current > x->c_high) x->c_current = x->c_high; else if (x->c_current == x->c_low) sendBang = 1; break; // count up and down case 3: // going up if (x->c_updown == 0) { x->c_current++; if (x->c_current > x->c_high) { x->c_current = x->c_high - 1; x->c_updown = 1; } else if (x->c_current < x->c_low) x->c_current = x->c_low; else if (x->c_current == x->c_high) sendBang = 1; } // going down else if (x->c_updown == 1) { x->c_current--; if (x->c_current < x->c_low) { x->c_current = x->c_low + 1; x->c_updown = 0; } else if (x->c_current > x->c_high) x->c_current = x->c_high; else if (x->c_current == x->c_low) sendBang = 1; } else { error("up/down wrong"); return; } break; default: error("dir wrong"); return; } outlet_float(x->t_out1, (float)x->c_current); if (sendBang) outlet_bang(x->t_out2); }
void counter_dir(t_counter *x, t_floatarg n) { if (n == 1 || n == 2 || n == 3) x->c_dir = (int)n; else error("bad dir"); }
void counter_high(t_counter *x, t_floatarg n) { x->c_high = (int)n; }
void counter_low(t_counter *x, t_floatarg n) { x->c_low = (int)n; }
void counter_reset(t_counter *x, t_symbol *s, int argc, t_atom *argv) { if (!argc) { switch(x->c_dir) { case 1: x->c_current = x->c_low; break; case 2: x->c_current = x->c_high; break; case 3: if (x->c_updown == 0) x->c_current = x->c_low; else if (x->c_updown == 1) x->c_current = x->c_high; break; default: return; } } else { switch(argv[0].a_type) { case A_FLOAT : x->c_current = (int)argv[0].a_w.w_float; break; default : error ("counter: reset not float"); break; } } outlet_float(x->t_out1, (float)x->c_current); }
void counter_clear(t_counter *x, t_symbol *s, int argc, t_atom *argv) { if (!argc) { switch(x->c_dir) { case 1: x->c_current = x->c_low - 1; break; case 2: x->c_current = x->c_high + 1; break; case 3: if (x->c_updown == 0) x->c_current = x->c_low - 1; else if (x->c_updown == 1) x->c_current = x->c_high + 1; break; default: break; } } else { switch(argv[0].a_type) { case A_FLOAT : x->c_current = (int)argv[0].a_w.w_float - 1; break; default : error ("counter: reset not float"); break; } } }
void *counter_new(t_floatarg f, t_floatarg g, t_floatarg h) /* init vals in struc */ { t_counter *x = (t_counter *)pd_new(counter_class); x->t_out1 = outlet_new(&x->x_obj, 0); x->t_out2 = outlet_new(&x->x_obj, 0); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl3")); x->c_current = 0; x->c_updown = 0; if (h) { counter_low(x, f); counter_high(x, g); counter_dir(x, h); } else if (g) { x->c_dir = 1; counter_low(x, f); counter_high(x, g); } else if (f) { x->c_dir = x->c_low = 1; counter_high(x, f); } else { x->c_dir = x->c_low = 1; x->c_high = 10; } return (x); }
void counter_setup(void) { counter_class = class_new(gensym("counter"), (t_newmethod)counter_new, 0, sizeof(t_counter), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); class_addbang(counter_class, (t_method)counter_bang); class_addmethod(counter_class, (t_method)counter_dir, gensym("fl1"), A_FLOAT, 0); class_addmethod(counter_class, (t_method)counter_low, gensym("fl2"), A_FLOAT, 0); class_addmethod(counter_class, (t_method)counter_high, gensym("fl3"), A_FLOAT, 0); class_addmethod(counter_class, (t_method)counter_reset, gensym("reset"), A_GIMME, 0); class_addmethod(counter_class, (t_method)counter_clear, gensym("clear"), A_GIMME, 0);
#if PD_MINOR_VERSION < 37
#endif }
--- gem_change-help.pd DELETED ---
--- NEW FILE: change-help.pd --- #N canvas 356 327 600 500 10; #X text 124 68 GEM object; #X obj 123 298 print out1; #X obj 123 219 change; #X msg 123 156 0; #X msg 166 154 1; #X text 138 23 [change]; #X text 58 360 [change] only outputs when the inlet receives a value that is different than the previous value.; #X text 57 404 [change] is very nice for the == and > objects.; #X connect 2 0 1 0; #X connect 3 0 2 0; #X connect 4 0 2 0;