From f6f29377728c80d1e1c72fdc3f9a113712d737f6 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Wed, 12 May 2010 19:17:15 +0000 Subject: Added to_ and from_ascii_code svn path=/trunk/externals/tof/; revision=13515 --- help/from_ascii_code-help.pd | 29 +++++++++++ help/to_ascii_code-help.pd | 14 ++++++ src/from_ascii_code.c | 111 +++++++++++++++++++++++++++++++++++++++++++ src/to_ascii_code.c | 97 +++++++++++++++++++++++++++++++++++++ test/Makefile | 69 ++++++++++++++------------- test/from_ascii_code-help.pd | 19 -------- test/from_ascii_code.c | 111 ------------------------------------------- test/to_ascii_code-help.pd | 13 ----- test/to_ascii_code.c | 97 ------------------------------------- 9 files changed, 286 insertions(+), 274 deletions(-) create mode 100644 help/from_ascii_code-help.pd create mode 100644 help/to_ascii_code-help.pd create mode 100644 src/from_ascii_code.c create mode 100644 src/to_ascii_code.c delete mode 100644 test/from_ascii_code-help.pd delete mode 100644 test/from_ascii_code.c delete mode 100644 test/to_ascii_code-help.pd delete mode 100644 test/to_ascii_code.c diff --git a/help/from_ascii_code-help.pd b/help/from_ascii_code-help.pd new file mode 100644 index 0000000..341c5bf --- /dev/null +++ b/help/from_ascii_code-help.pd @@ -0,0 +1,29 @@ +#N canvas 1080 84 708 396 10; +#X obj 94 332 print; +#X msg 133 156 43; +#X obj 71 69 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X msg 108 116 32; +#X obj 94 285 tof/from_ascii_code 13; +#X msg 99 94 54; +#X msg 155 197 13; +#X text 64 29 Tags: conversion text symbols; +#X text 64 13 Description: Convert ASCII codes into PD messages; +#X text 134 95 Floats and lists: enter ASCII codes; +#X text 93 68 Bang: output data; +#X text 248 285 Optionnal argument: output data once that ASCII code +is received; +#X msg 121 137 65; +#X text 185 192 Because of [form_ascii_code]'s creation argument \, +the number 13 acts like a bang; +#X msg 161 229 49 50 51 32 52 53 13; +#X msg 143 176 49 50 51 32 52 53; +#X connect 1 0 4 0; +#X connect 2 0 4 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 5 0 4 0; +#X connect 6 0 4 0; +#X connect 12 0 4 0; +#X connect 14 0 4 0; +#X connect 15 0 4 0; diff --git a/help/to_ascii_code-help.pd b/help/to_ascii_code-help.pd new file mode 100644 index 0000000..4d49897 --- /dev/null +++ b/help/to_ascii_code-help.pd @@ -0,0 +1,14 @@ +#N canvas 1427 407 571 202 10; +#X msg 49 60 test; +#X msg 182 61 1234; +#X obj 49 112 tof/to_ascii_code 13; +#X msg 92 60 list abcdef; +#X obj 49 153 print codes; +#X text 54 19 Tags: conversion text symbols; +#X text 55 3 Description: Convert PD messages into ASCII codes; +#X text 188 111 Optionnal argument: append ASCII code (in this case +13 \, a carriage return); +#X connect 0 0 2 0; +#X connect 1 0 2 0; +#X connect 2 0 4 0; +#X connect 3 0 2 0; diff --git a/src/from_ascii_code.c b/src/from_ascii_code.c new file mode 100644 index 0000000..31f5086 --- /dev/null +++ b/src/from_ascii_code.c @@ -0,0 +1,111 @@ +#include "m_pd.h" + +//static char* from_ascii_code_text; +// Common binbuf to all objects +static t_binbuf* from_ascii_code_binbuf; + +typedef struct _from_ascii_code +{ + + t_object x_ob; + int eof_is_set; + int eof; + t_outlet* outlet_left; + //t_outlet* outlet_right; + char* text; + int text_size; + int size; +} t_from_ascii_code; + +static t_class *from_ascii_code_class; + +// Force output even if eof has not been received +static void from_ascii_code_bang(t_from_ascii_code *x) { + + if ( x->size ) { + binbuf_clear(from_ascii_code_binbuf); + binbuf_text(from_ascii_code_binbuf, x->text, x->size); + t_atom *argv = binbuf_getvec(from_ascii_code_binbuf); + int argc = binbuf_getnatom(from_ascii_code_binbuf); + if ( argc) { + if ( (argv->a_type == A_SYMBOL) ) { + outlet_anything(x->outlet_left,atom_getsymbol(argv),argc-1,argv+1); + } else { + outlet_anything(x->outlet_left,&s_list,argc,argv); + } + } + x->size = 0; + } +} + + +static void from_ascii_code_float(t_from_ascii_code *x, t_float f) { + + if ( x->eof_is_set && f == x->eof ) { + from_ascii_code_bang(x); + } else if ( f > 31 && f < 127 ) { + x->text[x->size] = (char) f; + x->size = x->size + 1; + if ( x->size >= x->text_size ) { + + x->text = resizebytes(x->text, x->text_size * sizeof(*(x->text)), + (x->text_size + 100) * sizeof(*(x->text))); + x->text_size = x->text_size + 100; + } + } +} + +static void from_ascii_code_list(t_from_ascii_code *x, t_symbol *s, int argc, t_atom *argv) { + int i; + for ( i=0; i < argc; i++ ) { + if ( ((argv+i)->a_type == A_FLOAT) ) { + from_ascii_code_float(x,atom_getfloat(argv+i)); + } + } +} + +static void from_ascii_code_free(t_from_ascii_code *x) { + + freebytes(x->text,x->text_size*sizeof(*(x->text))); +} + +static void *from_ascii_code_new(t_symbol *s, int ac, t_atom *av) +{ + t_from_ascii_code *x = (t_from_ascii_code *)pd_new(from_ascii_code_class); + + // set eof if eof is set + if ( ac && ((av)->a_type == A_FLOAT)) { + x->eof = (int) atom_getfloat(av); + x->eof_is_set = 1; + } else { + x->eof_is_set = 0; + } + + // create string + x->text_size = 100; + x->text = getbytes(x->text_size*sizeof(*x->text)); + + x->size = 0; + + x->outlet_left = outlet_new(&x->x_ob, &s_list); + //x->outlet_right = outlet_new(&x->x_ob, &s_float); + + return (x); +} + +void from_ascii_code_setup(void) +{ + // create binbuf (no need to ever free) + from_ascii_code_binbuf = binbuf_new(); + + + + from_ascii_code_class = class_new(gensym("from_ascii_code"), + (t_newmethod)from_ascii_code_new, (t_method)from_ascii_code_free, + sizeof(t_from_ascii_code), 0, A_GIMME, 0); + + class_addbang(from_ascii_code_class, from_ascii_code_bang); + class_addfloat(from_ascii_code_class, from_ascii_code_float); + class_addlist(from_ascii_code_class, from_ascii_code_list); + + } diff --git a/src/to_ascii_code.c b/src/to_ascii_code.c new file mode 100644 index 0000000..8aa3155 --- /dev/null +++ b/src/to_ascii_code.c @@ -0,0 +1,97 @@ +#include "m_pd.h" + +// Common string to all objects +static char* to_ascii_code_text; +// Common binbuf to all objects +static t_binbuf* to_ascii_code_binbuf; + +typedef struct _to_ascii_code +{ + + t_object x_ob; + int eof_is_set; + int eof; + t_outlet* outlet_left; + //t_outlet* outlet_right; +} t_to_ascii_code; + +static t_class *to_ascii_code_class; + +static void to_ascii_code_bang(t_to_ascii_code *x) { + // Do nothing +} + + +static void to_ascii_code_anything(t_to_ascii_code *x, t_symbol *s, int ac, t_atom *av) { + + binbuf_clear(to_ascii_code_binbuf); + // Add selector if it is not standard + if ( s != &s_list && s != &s_float && s != &s_symbol && s != &s_) { + t_atom a; + SETSYMBOL(&a, s); + binbuf_add(to_ascii_code_binbuf,1,&a); + } + // Add all the atoms to the binbuf + binbuf_add(to_ascii_code_binbuf, ac, av); + + + + // Get the contents as a text + int size=0; + binbuf_gettext(to_ascii_code_binbuf, &to_ascii_code_text, &size); //void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp); + + // Convert to a list of floats + + t_atom *list_floats = getbytes((size+1)*sizeof(*list_floats)); // Add some space for the eof character + int i; + for ( i=0; i < size; i++ ) { + SETFLOAT(list_floats+i,(t_float)to_ascii_code_text[i]); + } + if ( x->eof_is_set ) { // Append eof if set + SETFLOAT(list_floats+size, x->eof); + //outlet_float(x->outlet_right,size+1); + outlet_list(x->outlet_left,&s_list,size+1,list_floats); + } else { + //outlet_float(x->outlet_right,size); + outlet_list(x->outlet_left,&s_list,size,list_floats); + } + freebytes(list_floats, (size+1)*sizeof(*list_floats)); + +} + + +static void *to_ascii_code_new(t_symbol *s, int ac, t_atom *av) +{ + t_to_ascii_code *x = (t_to_ascii_code *)pd_new(to_ascii_code_class); + + // set eof if eof is set + if ( ac && ((av)->a_type == A_FLOAT)) { + x->eof = (int) atom_getfloat(av); + x->eof_is_set = 1; + } else { + x->eof_is_set = 0; + } + + x->outlet_left = outlet_new(&x->x_ob, &s_list); + //x->outlet_right = outlet_new(&x->x_ob, &s_float); + + return (x); +} + +void to_ascii_code_setup(void) +{ + // create binbuf (no need to ever free) + to_ascii_code_binbuf = binbuf_new(); + + // create text (no need to ever free) + to_ascii_code_text = getbytes(MAXPDSTRING*sizeof(*to_ascii_code_text)); + + to_ascii_code_class = class_new(gensym("to_ascii_code"), + (t_newmethod)to_ascii_code_new, 0, + sizeof(t_to_ascii_code), 0, A_GIMME, 0); + + class_addbang(to_ascii_code_class, to_ascii_code_bang); + class_addanything(to_ascii_code_class, to_ascii_code_anything); + + + } diff --git a/test/Makefile b/test/Makefile index 22929fb..dd9f914 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,36 +1,37 @@ default: -PARAM: param paramDump paramRoute paramFile paramId paramCustom - -current: - echo make class - -clean: - rm -f *.pd_linux *.o - -# ----------------------- LINUX i386 ----------------------- - -#paramL: param.pd_linux - -#patchArguments: patchArguments.pd_linux - -.SUFFIXES: .pd_linux - -PDPATH = ../../../pd - -TOFPATH = ../src - -LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ - -Wall -W -Wshadow -Wstrict-prototypes \ - -Wno-unused -Wno-parentheses -Wno-switch - -LINUXINCLUDE = -I$(PDPATH)/src - -#.pd_linux: .c - -.c: - cc $(LINUXCFLAGS) $(LINUXINCLUDE) -I $(TOFPATH) -o $*.o -c $*.c - ld --export-dynamic -shared -o $*.pd_linux $*.o -lc -lm - strip --strip-unneeded $*.pd_linux - rm $*.o - mv $*.pd_linux ~/pd-externals/tof +PARAM: param paramDump paramRoute paramFile paramId paramCustom + +current: + echo make class + +clean: + rm -f *.pd_linux *.o + +# ----------------------- LINUX i386 ----------------------- + +#paramL: param.pd_linux + +#patchArguments: patchArguments.pd_linux + +.SUFFIXES: .pd_linux + +PDPATH = ../../../pd + +TOFPATH = ../src + +LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I$(PDPATH)/src + +#.pd_linux: .c + +.c: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -I $(TOFPATH) -o $*.o -c $*.c + ld --export-dynamic -shared -o $*.pd_linux $*.o -lc -lm + strip --strip-unneeded $*.pd_linux + rm $*.o + mv $*.pd_linux ~/pd-externals/tof + cp $*-help.pd ~/pd-externals/tof diff --git a/test/from_ascii_code-help.pd b/test/from_ascii_code-help.pd deleted file mode 100644 index 0b4ee06..0000000 --- a/test/from_ascii_code-help.pd +++ /dev/null @@ -1,19 +0,0 @@ -#N canvas 1285 315 450 300 10; -#X obj 107 212 print; -#X msg 93 43 65; -#X msg 139 47 43; -#X obj 190 61 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 --1; -#X msg 52 49 32; -#X obj 107 165 tof/from_ascii_code 13; -#X msg 240 60 49 50 51 32 50 13; -#X msg 280 95 54; -#X msg 282 126 13; -#X connect 1 0 5 0; -#X connect 2 0 5 0; -#X connect 3 0 5 0; -#X connect 4 0 5 0; -#X connect 5 0 0 0; -#X connect 6 0 5 0; -#X connect 7 0 5 0; -#X connect 8 0 5 0; diff --git a/test/from_ascii_code.c b/test/from_ascii_code.c deleted file mode 100644 index 31f5086..0000000 --- a/test/from_ascii_code.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "m_pd.h" - -//static char* from_ascii_code_text; -// Common binbuf to all objects -static t_binbuf* from_ascii_code_binbuf; - -typedef struct _from_ascii_code -{ - - t_object x_ob; - int eof_is_set; - int eof; - t_outlet* outlet_left; - //t_outlet* outlet_right; - char* text; - int text_size; - int size; -} t_from_ascii_code; - -static t_class *from_ascii_code_class; - -// Force output even if eof has not been received -static void from_ascii_code_bang(t_from_ascii_code *x) { - - if ( x->size ) { - binbuf_clear(from_ascii_code_binbuf); - binbuf_text(from_ascii_code_binbuf, x->text, x->size); - t_atom *argv = binbuf_getvec(from_ascii_code_binbuf); - int argc = binbuf_getnatom(from_ascii_code_binbuf); - if ( argc) { - if ( (argv->a_type == A_SYMBOL) ) { - outlet_anything(x->outlet_left,atom_getsymbol(argv),argc-1,argv+1); - } else { - outlet_anything(x->outlet_left,&s_list,argc,argv); - } - } - x->size = 0; - } -} - - -static void from_ascii_code_float(t_from_ascii_code *x, t_float f) { - - if ( x->eof_is_set && f == x->eof ) { - from_ascii_code_bang(x); - } else if ( f > 31 && f < 127 ) { - x->text[x->size] = (char) f; - x->size = x->size + 1; - if ( x->size >= x->text_size ) { - - x->text = resizebytes(x->text, x->text_size * sizeof(*(x->text)), - (x->text_size + 100) * sizeof(*(x->text))); - x->text_size = x->text_size + 100; - } - } -} - -static void from_ascii_code_list(t_from_ascii_code *x, t_symbol *s, int argc, t_atom *argv) { - int i; - for ( i=0; i < argc; i++ ) { - if ( ((argv+i)->a_type == A_FLOAT) ) { - from_ascii_code_float(x,atom_getfloat(argv+i)); - } - } -} - -static void from_ascii_code_free(t_from_ascii_code *x) { - - freebytes(x->text,x->text_size*sizeof(*(x->text))); -} - -static void *from_ascii_code_new(t_symbol *s, int ac, t_atom *av) -{ - t_from_ascii_code *x = (t_from_ascii_code *)pd_new(from_ascii_code_class); - - // set eof if eof is set - if ( ac && ((av)->a_type == A_FLOAT)) { - x->eof = (int) atom_getfloat(av); - x->eof_is_set = 1; - } else { - x->eof_is_set = 0; - } - - // create string - x->text_size = 100; - x->text = getbytes(x->text_size*sizeof(*x->text)); - - x->size = 0; - - x->outlet_left = outlet_new(&x->x_ob, &s_list); - //x->outlet_right = outlet_new(&x->x_ob, &s_float); - - return (x); -} - -void from_ascii_code_setup(void) -{ - // create binbuf (no need to ever free) - from_ascii_code_binbuf = binbuf_new(); - - - - from_ascii_code_class = class_new(gensym("from_ascii_code"), - (t_newmethod)from_ascii_code_new, (t_method)from_ascii_code_free, - sizeof(t_from_ascii_code), 0, A_GIMME, 0); - - class_addbang(from_ascii_code_class, from_ascii_code_bang); - class_addfloat(from_ascii_code_class, from_ascii_code_float); - class_addlist(from_ascii_code_class, from_ascii_code_list); - - } diff --git a/test/to_ascii_code-help.pd b/test/to_ascii_code-help.pd deleted file mode 100644 index 276bd99..0000000 --- a/test/to_ascii_code-help.pd +++ /dev/null @@ -1,13 +0,0 @@ -#N canvas 1371 321 506 219 10; -#X msg 108 32 test; -#X msg 262 34 1234; -#X obj 95 74 tof/to_ascii_code 13; -#X msg 173 36 list abcdef; -#X obj 95 115 print codes; -#X obj 214 115 print length; -#X text 234 73 Optionnal argument: append ascii code; -#X connect 0 0 2 0; -#X connect 1 0 2 0; -#X connect 2 0 4 0; -#X connect 2 1 5 0; -#X connect 3 0 2 0; diff --git a/test/to_ascii_code.c b/test/to_ascii_code.c deleted file mode 100644 index 8aa3155..0000000 --- a/test/to_ascii_code.c +++ /dev/null @@ -1,97 +0,0 @@ -#include "m_pd.h" - -// Common string to all objects -static char* to_ascii_code_text; -// Common binbuf to all objects -static t_binbuf* to_ascii_code_binbuf; - -typedef struct _to_ascii_code -{ - - t_object x_ob; - int eof_is_set; - int eof; - t_outlet* outlet_left; - //t_outlet* outlet_right; -} t_to_ascii_code; - -static t_class *to_ascii_code_class; - -static void to_ascii_code_bang(t_to_ascii_code *x) { - // Do nothing -} - - -static void to_ascii_code_anything(t_to_ascii_code *x, t_symbol *s, int ac, t_atom *av) { - - binbuf_clear(to_ascii_code_binbuf); - // Add selector if it is not standard - if ( s != &s_list && s != &s_float && s != &s_symbol && s != &s_) { - t_atom a; - SETSYMBOL(&a, s); - binbuf_add(to_ascii_code_binbuf,1,&a); - } - // Add all the atoms to the binbuf - binbuf_add(to_ascii_code_binbuf, ac, av); - - - - // Get the contents as a text - int size=0; - binbuf_gettext(to_ascii_code_binbuf, &to_ascii_code_text, &size); //void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp); - - // Convert to a list of floats - - t_atom *list_floats = getbytes((size+1)*sizeof(*list_floats)); // Add some space for the eof character - int i; - for ( i=0; i < size; i++ ) { - SETFLOAT(list_floats+i,(t_float)to_ascii_code_text[i]); - } - if ( x->eof_is_set ) { // Append eof if set - SETFLOAT(list_floats+size, x->eof); - //outlet_float(x->outlet_right,size+1); - outlet_list(x->outlet_left,&s_list,size+1,list_floats); - } else { - //outlet_float(x->outlet_right,size); - outlet_list(x->outlet_left,&s_list,size,list_floats); - } - freebytes(list_floats, (size+1)*sizeof(*list_floats)); - -} - - -static void *to_ascii_code_new(t_symbol *s, int ac, t_atom *av) -{ - t_to_ascii_code *x = (t_to_ascii_code *)pd_new(to_ascii_code_class); - - // set eof if eof is set - if ( ac && ((av)->a_type == A_FLOAT)) { - x->eof = (int) atom_getfloat(av); - x->eof_is_set = 1; - } else { - x->eof_is_set = 0; - } - - x->outlet_left = outlet_new(&x->x_ob, &s_list); - //x->outlet_right = outlet_new(&x->x_ob, &s_float); - - return (x); -} - -void to_ascii_code_setup(void) -{ - // create binbuf (no need to ever free) - to_ascii_code_binbuf = binbuf_new(); - - // create text (no need to ever free) - to_ascii_code_text = getbytes(MAXPDSTRING*sizeof(*to_ascii_code_text)); - - to_ascii_code_class = class_new(gensym("to_ascii_code"), - (t_newmethod)to_ascii_code_new, 0, - sizeof(t_to_ascii_code), 0, A_GIMME, 0); - - class_addbang(to_ascii_code_class, to_ascii_code_bang); - class_addanything(to_ascii_code_class, to_ascii_code_anything); - - - } -- cgit v1.2.1