From ed5f9b5db036f8bf420b38d674c9b3b1822b3b7b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 8 Dec 2005 05:24:58 +0000 Subject: converted things to fit in with the namespace svn path=/trunk/externals/markex/; revision=4167 --- README | 23 ------ abs~.c | 52 ++++++++++++ average-help.pd | 18 ++++ average.c | 85 +++++++++++++++++++ change-help.pd | 13 +++ change.c | 48 +++++++++++ counter-help.pd | 33 ++++++++ counter.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gem_average-help.pd | 18 ---- gem_average.c | 85 ------------------- gem_change-help.pd | 13 --- gem_change.c | 48 ----------- gem_counter-help.pd | 33 -------- gem_counter.c | 230 ---------------------------------------------------- reson~.c | 156 +++++++++++++++++++++++++++++++++++ 15 files changed, 635 insertions(+), 450 deletions(-) create mode 100644 abs~.c create mode 100644 average-help.pd create mode 100644 average.c create mode 100644 change-help.pd create mode 100644 change.c create mode 100644 counter-help.pd create mode 100644 counter.c delete mode 100644 gem_average-help.pd delete mode 100644 gem_average.c delete mode 100644 gem_change-help.pd delete mode 100644 gem_change.c delete mode 100644 gem_counter-help.pd delete mode 100644 gem_counter.c create mode 100644 reson~.c diff --git a/README b/README index f72e23b..a8ee8fb 100644 --- a/README +++ b/README @@ -8,26 +8,3 @@ What is here is the entire contents of Gem/src/MarkEx except [hsv2rsb] and the vector lib. Hopefully they will be removed from Gem once they become a 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. diff --git a/abs~.c b/abs~.c new file mode 100644 index 0000000..3078139 --- /dev/null +++ b/abs~.c @@ -0,0 +1,52 @@ +/* + * 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 + +/* ------------------------- 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); +} + diff --git a/average-help.pd b/average-help.pd new file mode 100644 index 0000000..fb923f3 --- /dev/null +++ b/average-help.pd @@ -0,0 +1,18 @@ +#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; diff --git a/average.c b/average.c new file mode 100644 index 0000000..39ac562 --- /dev/null +++ b/average.c @@ -0,0 +1,85 @@ +/* + * 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 +} + diff --git a/change-help.pd b/change-help.pd new file mode 100644 index 0000000..c02ddd1 --- /dev/null +++ b/change-help.pd @@ -0,0 +1,13 @@ +#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; diff --git a/change.c b/change.c new file mode 100644 index 0000000..f42cf37 --- /dev/null +++ b/change.c @@ -0,0 +1,48 @@ +/* + * 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 +} diff --git a/counter-help.pd b/counter-help.pd new file mode 100644 index 0000000..84f276e --- /dev/null +++ b/counter-help.pd @@ -0,0 +1,33 @@ +#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; diff --git a/counter.c b/counter.c new file mode 100644 index 0000000..6bbc81a --- /dev/null +++ b/counter.c @@ -0,0 +1,230 @@ +/* + * 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 +} diff --git a/gem_average-help.pd b/gem_average-help.pd deleted file mode 100644 index fb923f3..0000000 --- a/gem_average-help.pd +++ /dev/null @@ -1,18 +0,0 @@ -#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; diff --git a/gem_average.c b/gem_average.c deleted file mode 100644 index 1a82dcc..0000000 --- a/gem_average.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 *gem_average_class; - -typedef struct _gem_average -{ - t_object x_obj; /* obligatory object header */ - int a_total; /* number of numbers to gem_average */ - int a_whichNum; /* which number are pointing at */ - float a_numbers[100]; /* numbers to gem_average, 100 maximum */ - t_outlet *t_out1; /* the outlet */ -} t_gem_average; - -void gem_average_bang(t_gem_average *x) -{ - float gem_average = 0.0f; - int n; - - for (n = 0; n < x->a_total; n++) gem_average = gem_average + x->a_numbers[n]; - gem_average = gem_average / (float)x->a_total; - - outlet_float(x->t_out1, gem_average); -} - -void gem_average_float(t_gem_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++; - gem_average_bang(x); -} - -void gem_average_total(t_gem_average *x, t_floatarg n) -{ - x->a_total = (int)n; -} - -void gem_average_reset(t_gem_average *x, t_floatarg newVal) -{ - int n; - for (n=0; n < 100; n ++) x->a_numbers[n] = newVal; -} - -void gem_average_clear(t_gem_average *x) -{ - int n; - for ( n = 0; n < 100; n ++) x->a_numbers[n] = 0.0f; -} - -void *gem_average_new(t_floatarg f) /* init vals in struc */ -{ - t_gem_average *x = (t_gem_average *)pd_new(gem_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")); - gem_average_clear(x); - if (f) x->a_total = (int)f; - else x->a_total = 10; - x->a_whichNum = 0; - return (x); -} - -void gem_average_setup(void) -{ - gem_average_class = class_new(gensym("gem_average"), (t_newmethod)gem_average_new, 0, - sizeof(t_gem_average), 0, A_DEFFLOAT, 0); - class_addbang(gem_average_class, (t_method)gem_average_bang); - class_addfloat(gem_average_class, (t_method)gem_average_float); - class_addmethod(gem_average_class, (t_method)gem_average_total, gensym("fl1"), A_FLOAT, 0); - class_addmethod(gem_average_class, (t_method)gem_average_clear, gensym("clear"), A_NULL); - class_addmethod(gem_average_class, (t_method)gem_average_reset, gensym("reset"), A_FLOAT, 0); - - #if PD_MINOR_VERSION < 37 - class_sethelpsymbol(gem_average_class, gensym("gem_average-help.pd")); -#endif -} - diff --git a/gem_change-help.pd b/gem_change-help.pd deleted file mode 100644 index c02ddd1..0000000 --- a/gem_change-help.pd +++ /dev/null @@ -1,13 +0,0 @@ -#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; diff --git a/gem_change.c b/gem_change.c deleted file mode 100644 index dc714ec..0000000 --- a/gem_change.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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" - -/* -------------------------- gem_change ------------------------------ */ - -/* instance structure */ - -static t_class *gem_change_class; - -typedef struct _gem_change -{ - t_object x_obj; /* obligatory object header */ - float x_cur; - t_outlet *t_out1; /* the outlet */ -} t_gem_change; - -static void gem_change_float(t_gem_change *x, t_floatarg n) -{ - if (n != x->x_cur) - { - outlet_float(x->t_out1, n); - x->x_cur = n; - } -} - -static void *gem_change_new(void) /* init vals in struc */ -{ - t_gem_change *x = (t_gem_change *)pd_new(gem_change_class); - x->x_cur = -1.f; - x->t_out1 = outlet_new(&x->x_obj, 0); - return(x); -} - -void gem_change_setup(void) -{ - gem_change_class = class_new(gensym("gem_change"), (t_newmethod)gem_change_new, 0, - sizeof(t_gem_change), 0, A_NULL); - class_addfloat(gem_change_class, gem_change_float); - - #if PD_MINOR_VERSION < 37 - class_sethelpsymbol(gem_change_class, gensym("gem_change-help.pd")); -#endif -} diff --git a/gem_counter-help.pd b/gem_counter-help.pd deleted file mode 100644 index 84f276e..0000000 --- a/gem_counter-help.pd +++ /dev/null @@ -1,33 +0,0 @@ -#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; diff --git a/gem_counter.c b/gem_counter.c deleted file mode 100644 index c3c8236..0000000 --- a/gem_counter.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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" - -/* -------------------------- gem_counter ------------------------------ */ - -/* instance structure */ -static t_class *gem_counter_class; - -typedef struct _gem_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; /* gem_counter dir. 1=up, 2=down, 3=up/down */ - t_outlet *t_out1; /* the outlet */ - t_outlet *t_out2; /* the outlet */ -} t_gem_counter; - -void gem_counter_bang(t_gem_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 gem_counter_dir(t_gem_counter *x, t_floatarg n) -{ - if (n == 1 || n == 2 || n == 3) x->c_dir = (int)n; - else error("bad dir"); -} - -void gem_counter_high(t_gem_counter *x, t_floatarg n) -{ - x->c_high = (int)n; -} - -void gem_counter_low(t_gem_counter *x, t_floatarg n) -{ - x->c_low = (int)n; -} - -void gem_counter_reset(t_gem_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 ("gem_counter: reset not float"); - break; - } - } - outlet_float(x->t_out1, (float)x->c_current); -} - -void gem_counter_clear(t_gem_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 ("gem_counter: reset not float"); - break; - } - } -} - -void *gem_counter_new(t_floatarg f, t_floatarg g, t_floatarg h) /* init vals in struc */ -{ - t_gem_counter *x = (t_gem_counter *)pd_new(gem_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) - { - gem_counter_low(x, f); - gem_counter_high(x, g); - gem_counter_dir(x, h); - } - else if (g) - { - x->c_dir = 1; - gem_counter_low(x, f); - gem_counter_high(x, g); - } - else if (f) - { - x->c_dir = x->c_low = 1; - gem_counter_high(x, f); - } - else - { - x->c_dir = x->c_low = 1; - x->c_high = 10; - } - return (x); -} - -void gem_counter_setup(void) -{ - gem_counter_class = class_new(gensym("gem_counter"), (t_newmethod)gem_counter_new, 0, - sizeof(t_gem_counter), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); - class_addbang(gem_counter_class, (t_method)gem_counter_bang); - class_addmethod(gem_counter_class, (t_method)gem_counter_dir, gensym("fl1"), A_FLOAT, 0); - class_addmethod(gem_counter_class, (t_method)gem_counter_low, gensym("fl2"), A_FLOAT, 0); - class_addmethod(gem_counter_class, (t_method)gem_counter_high, gensym("fl3"), A_FLOAT, 0); - class_addmethod(gem_counter_class, (t_method)gem_counter_reset, gensym("reset"), A_GIMME, 0); - class_addmethod(gem_counter_class, (t_method)gem_counter_clear, gensym("clear"), A_GIMME, 0); - -#if PD_MINOR_VERSION < 37 - class_sethelpsymbol(gem_counter_class, gensym("gem_counter-help.pd")); -#endif -} diff --git a/reson~.c b/reson~.c new file mode 100644 index 0000000..26aa245 --- /dev/null +++ b/reson~.c @@ -0,0 +1,156 @@ +/* + * 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 + +#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); +} + -- cgit v1.2.1