diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/argument.c | 119 | ||||
-rw-r--r-- | src/crossfade~.c | 137 | ||||
-rw-r--r-- | src/increment.c | 151 | ||||
-rw-r--r-- | src/iterate.c | 105 | ||||
-rw-r--r-- | src/listUnfold.c | 88 | ||||
-rw-r--r-- | src/path.c | 252 | ||||
-rw-r--r-- | src/streamMinMax.c | 107 | ||||
-rw-r--r-- | src/wrapper.c | 81 |
8 files changed, 1040 insertions, 0 deletions
diff --git a/src/argument.c b/src/argument.c new file mode 100644 index 0000000..0c7df4b --- /dev/null +++ b/src/argument.c @@ -0,0 +1,119 @@ +/* + * argument.c + * + * Copyright 2009 Thomas O Fredericks <tom@hp> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "tof.h" + +t_class *argument_class; + +typedef struct argument +{ + t_object x_ob; + //t_canvas * x_canvas; + t_outlet* x_outlet; + t_atom x_a; + int has_value; +} t_argument; + +static void argument_bang(t_argument *x) +{ + + if (x->has_value) { + if ( IS_A_SYMBOL(&(x->x_a),0) ) { + outlet_symbol(x->x_outlet,atom_getsymbol(&(x->x_a))); + } else { + outlet_float(x->x_outlet,atom_getfloat(&(x->x_a))); + } + } + + +} + + +static void argument_free(t_argument *x) { + + //freebytes(x->x_a, sizeof(t_atom)); +} + + +//static void *argument_new(t_floatarg level) +static void *argument_new(t_symbol *s, int argc, t_atom *argv) +{ + t_argument *x = (t_argument *)pd_new(argument_class); + + + t_canvas *canvas=tof_get_canvas(); + + x->x_outlet = outlet_new(&x->x_ob, &s_list); + //x->x_a = (t_atom *)getbytes(sizeof(t_atom)); + + x->has_value = 0; + int i = 0; + + // Check argument i and default value + if ( argc >= 1 && IS_A_FLOAT(argv,0) ) { + i = atom_getfloat(argv); + } + + // Get the canvas' arguments + int ac; + t_atom *av; + tof_get_canvas_arguments(canvas,&ac, &av); + + + // Check arguments + + if ( i == 0) { //Is the argument index 0? + // Get the dollar zero + SETSYMBOL(&(x->x_a),tof_get_dollar(canvas,gensym("$0"))); + x->has_value = 1; + } else { + //if ( ac >= i ) { + if ( argc > 1 ) { //Is there a default argument? + //Are the parent and default arguments the same type? + if ( ac >= i && (av+(i-1))->a_type == (argv+1)->a_type) { + x->x_a = av[i-1]; //Use the parent value + } else { + x->x_a = argv[1]; //Use the default value + } + x->has_value = 1; + } else { //No default argument, so no type check + if ( ac >= i ) { //Are there enough parent arguments? + x->x_a = av[i-1]; //Use the parent value + x->has_value = 1; + } + } + + //} + } + + return (void *)x; +} + +void argument_setup(void) +{ + + argument_class = class_new(gensym("argument"), + (t_newmethod)argument_new, (t_method)argument_free, + sizeof(t_argument), CLASS_DEFAULT, A_GIMME,0); + class_addbang(argument_class, argument_bang); + +} + diff --git a/src/crossfade~.c b/src/crossfade~.c new file mode 100644 index 0000000..75cd9b6 --- /dev/null +++ b/src/crossfade~.c @@ -0,0 +1,137 @@ +#include "m_pd.h" + +//Create one input for each channel + + + +static t_class *crossfade_tilde_class; + +typedef struct _crossfade_tilde { + t_object x_obj; + t_float mix; //The mix value (0: input 1, 1:input2) + int n_in; + int channels; + t_sample **in; + int n_out; + t_sample **out; + t_sample f; + t_sample* buffer; //Input frame buffer: one sample of every input +} t_crossfade_tilde; + + + +// Perform +static t_int *crossfade_tilde_perform(t_int *w) +{ + + t_crossfade_tilde *x = (t_crossfade_tilde *)(w[1]); + int n = (int)(w[2]); + + if (x->mix < 0) x->mix = 0; + if (x->mix > 1) x->mix = 1; + t_float inv_mix = 1-x->mix; + + + + int i; + int j; + t_sample* out; + + + for ( j =0; j < n; j++) { + + // Copy one sample of all the inputs + for ( i=0; i < x->n_in;i++ ) { + x->buffer[i] = (t_sample) x->in[i][j]; + } + + for ( i=0; i < x->channels;i++ ) { + + out = (t_sample *)(x->out[i]); + out[j] = (x->buffer[i] * inv_mix) + (x->buffer[i+x->channels] * x->mix) ; + } + } + + + + return (w+3); + +} + + +// Annouce signal inputs and outputs to the DSP chain +static void crossfade_tilde_dsp(t_crossfade_tilde *x, t_signal **sp) +{ + + int n; + t_sample **dummy=x->in; + for(n=0;n<x->n_in;n++)*dummy++=sp[n]->s_vec; + + dummy=x->out; + for(n=0;n<x->n_out;n++)*dummy++=sp[n+x->n_in]->s_vec; + + + dsp_add(crossfade_tilde_perform, 2, x, sp[0]->s_n); + +} + +static void crossfade_tilde_free( t_crossfade_tilde *x) { + + freebytes(x->in, x->n_in * sizeof(t_sample *)); + freebytes(x->out, x->n_out * sizeof(t_sample *)); + + freebytes(x->buffer,x->n_in * sizeof( * x->buffer)); +} + +static void *crossfade_tilde_new(t_floatarg f) +{ + t_crossfade_tilde *x = (t_crossfade_tilde *)pd_new(crossfade_tilde_class); + + + x->channels = (int) f; + if ( x->channels < 1 ) x->channels = 2; + + + + x->n_in = x->channels * 2; + x->in = (t_sample **)getbytes(x->n_in * sizeof(t_sample *)); + int i=x->n_in; + while(i--)x->in[i]=0; + + x->n_out = x->channels; + x->out = (t_sample **)getbytes(x->n_in * sizeof(t_sample *)); + i=x->n_out; + while(i--)x->out[i]=0; + + + x->buffer = getbytes(x->n_in * sizeof( * x->buffer)); + + + + for (i=0; i < x->n_in - 1; i++) { + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + } + + for (i=0; i < x->n_out; i++) { + outlet_new(&x->x_obj, &s_signal); + } + + + floatinlet_new (&x->x_obj, &x->mix); + + + return (void *)x; +} + + void crossfade_tilde_setup(void) { + + crossfade_tilde_class = class_new(gensym("crossfade~"), + (t_newmethod)crossfade_tilde_new, + (t_method)crossfade_tilde_free, sizeof(t_crossfade_tilde), + 0, A_DEFFLOAT, 0); + + class_addmethod(crossfade_tilde_class, + (t_method)crossfade_tilde_dsp, gensym("dsp"), 0); + // class_addmethod(crossfade_tilde_class, nullfn, gensym("signal"), 0); + CLASS_MAINSIGNALIN(crossfade_tilde_class, t_crossfade_tilde, f); +} diff --git a/src/increment.c b/src/increment.c new file mode 100644 index 0000000..25e7924 --- /dev/null +++ b/src/increment.c @@ -0,0 +1,151 @@ +#include "m_pd.h" + +static t_class *increment_class; + +typedef struct _increment { + t_object x_obj; + int reset; + t_float value; + t_float inc; + t_outlet* outlet1; + t_float start; + //t_outlet* outlet2; +} t_increment; + + +static void increment_bang(t_increment *x) +{ + + if ( x->reset) { + x->reset = 0; + } else { + x->value = x->value + x->inc; + } + outlet_float(x->outlet1,x->value); + + + +} +/* +static void increment_float(t_increment *x, t_float f) +{ + x->inc = f; + increment_bang(x); +} +*/ + +static void increment_step(t_increment *x, t_float f) +{ + x->inc = f; + +} + +static void increment_reset(t_increment *x) +{ + + //post("before"); + // post("start:%d",(int)x->start); + // post("value:%d",(int)x->value); + + x->value = x->start; + x->reset = 1; + + // post("after"); + //post("start:%d",(int)x->start); + //post("value:%d",(int)x->value); +} + +static void increment_set(t_increment *x, t_float f) +{ + + + + x->value = f; + x->start = f; + x->reset = 1; + + + +} + + + + +/* +void increment_list(t_increment *x,t_symbol *s, int argc, t_atom *argv) +{ + + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } + + +} +*/ + +static void increment_free(t_increment *x) +{ + + +} + +void *increment_new(t_symbol *s, int argc, t_atom *argv) +{ + t_increment *x = (t_increment *)pd_new(increment_class); + + x->reset = 1; + x->value = 0; + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->value = atom_getfloat(argv); + x->inc = 1; + } else { + x->value = 0; + x->inc = 1; + } + + x->start = x->value; + + //post("start:%d",(int)x->start); + //post("value:%d",(int)x->value); + + inlet_new(&x->x_obj, &x->x_obj.ob_pd, + gensym("float"), gensym("set")); + + floatinlet_new(&x->x_obj, &x->inc); + + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + //x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void increment_setup(void) { + increment_class = class_new(gensym("increment"), + (t_newmethod)increment_new, + (t_method)increment_free, sizeof(t_increment), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (increment_class, increment_bang); + //class_addfloat (increment_class, increment_float); + class_addmethod(increment_class, + (t_method)increment_set, gensym("set"), + A_DEFFLOAT, 0); + class_addmethod(increment_class, + (t_method)increment_step, gensym("step"), + A_DEFFLOAT, 0); + class_addmethod(increment_class, + (t_method)increment_reset, gensym("reset"), + 0); + + //class_addlist (increment_class, increment_list); + +} diff --git a/src/iterate.c b/src/iterate.c new file mode 100644 index 0000000..8fee7ac --- /dev/null +++ b/src/iterate.c @@ -0,0 +1,105 @@ +#include "m_pd.h" + +static t_class *iterate_class; + +typedef struct _iterate { + t_object x_obj; + + t_float start; + t_float step; + t_int iterating; + t_outlet* outlet1; + //t_outlet* outlet2; +} t_iterate; + + +static void iterate_bang(t_iterate *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} + + +static void iterate_start(t_iterate *x, t_float f) { + + x->start = f; +} + + +static void iterate_step(t_iterate *x, t_float f) { + + x->step = f; +} + +static void iterate_float(t_iterate *x, t_float f) +{ + + if ( f < 0 ) f = 0; + + int i; + t_float value = x->start; + x->iterating = 1; + + for ( i = 0; i < f; i++) { + if ( !(x->iterating) ) break; + + outlet_float(x->outlet1, value); + value = value + x->step; + } + +} + + +static void iterate_free(t_iterate *x) +{ + + +} + +static void *iterate_new(t_symbol *s, int argc, t_atom *argv) +{ + t_iterate *x = (t_iterate *)pd_new(iterate_class); + + x->iterating = 0; + if ( argc >= 2) { + x->start = atom_getfloat(argv); + x->step = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->start = atom_getfloat(argv); + x->step = 1; + } else { + x->start = 0; + x->step = 1; + } + + floatinlet_new(&x->x_obj, &x->start); + floatinlet_new(&x->x_obj, &x->step); + x->outlet1 = outlet_new(&x->x_obj, &s_float); + //x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void iterate_setup(void) { + iterate_class = class_new(gensym("iterate"), + (t_newmethod)iterate_new, + (t_method)iterate_free, sizeof(t_iterate), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (iterate_class, iterate_bang); + class_addfloat (iterate_class, iterate_float); + + class_addmethod(iterate_class, + (t_method)iterate_start, gensym("start"), + A_DEFFLOAT, 0); + + class_addmethod(iterate_class, + (t_method)iterate_step, gensym("step"), + A_DEFFLOAT, 0); + + //class_addlist (iterate_class, iterate_list); + +} diff --git a/src/listUnfold.c b/src/listUnfold.c new file mode 100644 index 0000000..579f645 --- /dev/null +++ b/src/listUnfold.c @@ -0,0 +1,88 @@ +#include "m_pd.h" +#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL) +#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT) + + +static t_class *listUnfold_class; + +typedef struct _listUnfold { + t_object x_obj; + + //t_float start; + //t_float step; + t_int iterating; + t_outlet* outlet1; + t_outlet* outlet2; +} t_listUnfold; + + +void listUnfold_bang(t_listUnfold *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} + + +void listUnfold_anything(t_listUnfold *x, t_symbol* s, int ac, t_atom* av) +{ + int i = 0; + int count = 0; + x->iterating = 1; + + if ( s != &s_list && s != &s_float && s != &s_symbol ) { + outlet_float(x->outlet2,0); + outlet_symbol(x->outlet1,s); + count++; + } + + for ( ; i < ac; i++ ) { + if ( !(x->iterating) ) break; + outlet_float(x->outlet2,count); + count++; + if ( IS_A_FLOAT(av,i) ) { + outlet_float(x->outlet1,atom_getfloat(av+i)); + } else { + outlet_symbol(x->outlet1,atom_getsymbol(av+i)); + } + + } + + +} + + +static void listUnfold_free(t_listUnfold *x) +{ + + +} + +void *listUnfold_new(t_symbol *s, int argc, t_atom *argv) +{ + t_listUnfold *x = (t_listUnfold *)pd_new(listUnfold_class); + + x->iterating = 0; + + + //floatinlet_new(&x->x_obj, &x->start); + //floatinlet_new(&x->x_obj, &x->step); + x->outlet1 = outlet_new(&x->x_obj, &s_list); + x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void listUnfold_setup(void) { + listUnfold_class = class_new(gensym("listUnfold"), + (t_newmethod)listUnfold_new, + (t_method)listUnfold_free, sizeof(t_listUnfold), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (listUnfold_class, listUnfold_bang); + class_addanything (listUnfold_class, listUnfold_anything); + //class_addlist (listUnfold_class, listUnfold_list); + +} diff --git a/src/path.c b/src/path.c new file mode 100644 index 0000000..d0dc7ef --- /dev/null +++ b/src/path.c @@ -0,0 +1,252 @@ + +#include "tof.h" +#define SLASH '/' + +static t_class *path_class; + +typedef struct _path { + t_object x_obj; + //char buffer[MAXPDSTRING]; + t_outlet* outlet1; + //t_canvas* canvas; + t_symbol* dir; + t_symbol* mode; + t_symbol* dirmode; + t_symbol* s_current; + t_symbol* s_relative; +} t_path; + + +// Code from http://www.codeguru.com/cpp/misc/misc/fileanddirectorynaming/article.php/c263#more +static void getRelativeFilename(char* relativeFilename, char *currentDirectory, char *absoluteFilename) +{ + // declarations - put here so this should work in a C compiler + int afMarker = 0, rfMarker = 0; + int cdLen = 0, afLen = 0; + int i = 0; + int levels = 0; + //static char relativeFilename[MAX_FILENAME_LEN+1]; + + cdLen = strlen(currentDirectory); + afLen = strlen(absoluteFilename); + + + // Handle DOS names that are on different drives: + if(currentDirectory[0] != absoluteFilename[0]) + { + // not on the same drive, so only absolute filename will do + strcpy(relativeFilename, absoluteFilename); + return; + } + + // they are on the same drive, find out how much of the current directory + // is in the absolute filename + i = 1;//ABSOLUTE_NAME_START; + while(i < afLen && i < cdLen && currentDirectory[i] == absoluteFilename[i]) + { + i++; + } + + if(i == cdLen && (absoluteFilename[i] == SLASH || absoluteFilename[i-1] == SLASH)) + { + // the whole current directory name is in the file name, + // so we just trim off the current directory name to get the + // current file name. + if(absoluteFilename[i] == SLASH) + { + // a directory name might have a trailing slash but a relative + // file name should not have a leading one... + i++; + } + + strcpy(relativeFilename, &absoluteFilename[i]); + return; + } + + + // The file is not in a child directory of the current directory, so we + // need to step back the appropriate number of parent directories by + // using "..\"s. First find out how many levels deeper we are than the + // common directory + afMarker = i; + levels = 1; + + // count the number of directory levels we have to go up to get to the + // common directory + while(i < cdLen) + { + i++; + if(currentDirectory[i] == SLASH) + { + // make sure it's not a trailing slash + i++; + if(currentDirectory[i] != '\0') + { + levels++; + } + } + } + + // move the absolute filename marker back to the start of the directory name + // that it has stopped in. + while(afMarker > 0 && absoluteFilename[afMarker-1] != SLASH) + { + afMarker--; + } + + + + // add the appropriate number of "..\"s. + rfMarker = 0; + for(i = 0; i < levels; i++) + { + relativeFilename[rfMarker++] = '.'; + relativeFilename[rfMarker++] = '.'; + relativeFilename[rfMarker++] = SLASH; + } + + // copy the rest of the filename into the result string + strcpy(&relativeFilename[rfMarker], &absoluteFilename[afMarker]); + + //return relativeFilename; +} + + +// BANG: output the current root path +static void path_bang(t_path *x) +{ + + outlet_symbol(x->outlet1, x->dir ); + + +} + +static void path_anything(t_path *x, t_symbol *s, int ac, t_atom* av) { + + + + int length = tof_anything_to_string(s,ac,av,tof_buf_temp_a); + t_symbol* result; + + if ( x->mode == x->s_relative ) { + + // TRANSFORM ABSOLUTE PATHS TO RELATIVE PATHS + + // Is this a relative path? + // Checks for a starting / or a : as second character + if ( tof_path_is_absolute(tof_buf_temp_a,length )) { + getRelativeFilename(tof_buf_temp_b,x->dir->s_name,tof_buf_temp_a); + result = gensym(tof_buf_temp_b); + } else { + result = gensym(tof_buf_temp_a); + } + + } else { + + // TRANFORM RELATIVE PATHS TO ABSOLUTE PATHS + + // Is this a relative path? + if ( tof_path_is_absolute(tof_buf_temp_a,length) ) { + result = gensym(tof_buf_temp_a); + } else { + strcpy(tof_buf_temp_b,x->dir->s_name); + strcat(tof_buf_temp_b,tof_buf_temp_a); + result = gensym(tof_buf_temp_b); + } + } + + outlet_symbol(x->outlet1, result); +} + + + + +/* +void path_list(t_path *x,t_symbol *s, int argc, t_atom *argv) +{ + + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } + + +} +*/ + + + + + +static void path_free(t_path *x) +{ + + //binbuf_free(x->binbuf); + +} + +void *path_new(t_symbol *s, int argc, t_atom *argv) +{ + t_path *x = (t_path *)pd_new(path_class); + + + x->s_current = gensym("current"); + x->s_relative = gensym("relative"); + + int i; + t_symbol * mode_temp; + for ( i = 0; i < argc; i++) { + if ( IS_A_SYMBOL(argv,i) ) { + mode_temp = atom_getsymbol(argv+i); + if ( mode_temp == x->s_current ) x->dirmode = x->s_current; + if ( mode_temp == x->s_relative) x->mode = x->s_relative; + } + } + + if ( x->dirmode == x->s_current) { + x->dir = tof_get_dir(tof_get_canvas()); + } else { + x->dir = tof_get_dir(tof_get_root_canvas(tof_get_canvas())); + + } + strcpy(tof_buf_temp_a,x->dir->s_name); + strcat(tof_buf_temp_a,"/"); + x->dir = gensym(tof_buf_temp_a); + + /* + inlet_new(&x->x_obj, &x->x_obj.ob_pd, + gensym("float"), gensym("set")); + + floatinlet_new(&x->x_obj, &x->inc); + */ + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + + + + return (void *)x; +} + +void path_setup(void) { + path_class = class_new(gensym("path"), + (t_newmethod)path_new, + (t_method)path_free, sizeof(t_path), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang(path_class, path_bang); + class_addanything(path_class,path_anything); + + //class_addmethod(path_class, + // (t_method)path_append, gensym("append"), + // A_GIMME, 0); + + //class_addfloat (path_class, path_float); + /*class_addmethod(path_class, + (t_method)path_set, gensym("set"), + A_DEFFLOAT, 0); +*/ + //class_addlist (path_class, path_list); + +} diff --git a/src/streamMinMax.c b/src/streamMinMax.c new file mode 100644 index 0000000..c2fb438 --- /dev/null +++ b/src/streamMinMax.c @@ -0,0 +1,107 @@ +#include "m_pd.h" + +static t_class *streamMinMax_class; + +typedef struct _streamMinMax { + t_object x_obj; + + t_float min; + t_float max; + t_int reset; + //t_outlet *f_out, *b_out; + t_outlet* outlet1; + t_outlet* outlet2; +} t_streamMinMax; + +void streamMinMax_float(t_streamMinMax *x, t_float f) +{ + + if ( x->reset) { + x->min = f; + x->max = f; + x->reset = 0; + } else { + if (f < x->min) x->min = f; + if (f > x->max) x->max = f; + } + + outlet_float(x->outlet1, x->min); + outlet_float(x->outlet2, x->max); +} + +void streamMinMax_bang(t_streamMinMax *x) +{ + //x->i_count = x->i_down; + x->reset = 1; + +} + +void streamMinMax_list(t_streamMinMax *x,t_symbol *s, int argc, t_atom *argv) +{ + + if (argc >= 2) { + float a = atom_getfloat(argv+1); + float b = atom_getfloat(argv); + if (a > b ) { + x->max=a; + x->min=b; + } else { + x->max=b; + x->min=a; + } + x->reset = 0; + } + +} + +static void streamMinMax_free(t_streamMinMax *x) +{ + + +} + +void *streamMinMax_new(t_symbol *s, int argc, t_atom *argv) +{ + t_streamMinMax *x = (t_streamMinMax *)pd_new(streamMinMax_class); + + x->reset = 1; + + streamMinMax_list(x,&s_list,argc,argv); + + + + //inlet_new(&x->x_obj, &x->x_obj.ob_pd, + // gensym("list"), gensym("bound")); + + //floatinlet_new(&x->x_obj, &x->step); + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + x->outlet2 = outlet_new(&x->x_obj, &s_float); + //x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void streamMinMax_setup(void) { + streamMinMax_class = class_new(gensym("streamMinMax"), + (t_newmethod)streamMinMax_new, + (t_method)streamMinMax_free, sizeof(t_streamMinMax), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (streamMinMax_class, streamMinMax_bang); + class_addfloat (streamMinMax_class, streamMinMax_float); + class_addlist (streamMinMax_class, streamMinMax_list); + /* + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_reset, gensym("reset"), 0); + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_set, gensym("set"), + A_DEFFLOAT, 0); + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_bound, gensym("bound"), + A_DEFFLOAT, A_DEFFLOAT, 0); + + class_sethelpsymbol(streamMinMax_class, gensym("help-streamMinMax")); + */ +} diff --git a/src/wrapper.c b/src/wrapper.c new file mode 100644 index 0000000..8d0ec5e --- /dev/null +++ b/src/wrapper.c @@ -0,0 +1,81 @@ +#include "m_pd.h" +#include <math.h> + +static t_class *wrapper_class; + +typedef struct _wrapper { + t_object x_obj; + + t_float min; + t_float max; + //t_int iterating; + t_outlet* outlet1; + //t_outlet* outlet2; +} t_wrapper; + +/* +void wrapper_bang(t_wrapper *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} +*/ + +void wrapper_float(t_wrapper *x, t_float f) +{ + + t_float value = fmod(f - x->min ,x->max - x->min); + if ( value < 0 ) value = value + x->max; + else value = value + x->min; + + outlet_float(x->outlet1, value); + + +} + + + +static void wrapper_free(t_wrapper *x) +{ + + +} + +void *wrapper_new(t_symbol *s, int argc, t_atom *argv) +{ + t_wrapper *x = (t_wrapper *)pd_new(wrapper_class); + + + if ( argc >= 2) { + x->min = atom_getfloat(argv); + x->max = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->min = 0; + x->max = atom_getfloat(argv); + } else { + x->min = 0; + x->max = 1; + } + + floatinlet_new(&x->x_obj, &x->min); + floatinlet_new(&x->x_obj, &x->max); + x->outlet1 = outlet_new(&x->x_obj, &s_float); + + + + return (void *)x; +} + +void wrapper_setup(void) { + wrapper_class = class_new(gensym("wrapper"), + (t_newmethod)wrapper_new, + (t_method)wrapper_free, sizeof(t_wrapper), + CLASS_DEFAULT, + A_GIMME, 0); + + //class_addbang (wrapper_class, wrapper_bang); + class_addfloat (wrapper_class, wrapper_float); + //class_addlist (wrapper_class, wrapper_list); + +} |