From 76430a8935097f4cee5befd550d2dcc043774d19 Mon Sep 17 00:00:00 2001 From: jdl Date: Wed, 26 Feb 2003 22:06:39 +0000 Subject: added split. split incoming symbol at delim svn path=/trunk/externals/cxc/; revision=434 --- ascseq.c | 9 ++- cx.c | 2 + makefile | 4 +- reference/cxc.split.pd | 46 ++++++++++++++ split.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 reference/cxc.split.pd create mode 100644 split.c diff --git a/ascseq.c b/ascseq.c index 1cdc6d5..7213d43 100644 --- a/ascseq.c +++ b/ascseq.c @@ -44,7 +44,7 @@ static void ascseq_tick(t_ascseq *x) } } -void ascseq_anything(t_ascseq *x,t_symbol* s,t_int argc,t_atom* argv) +void ascseq_anything(t_ascseq *x, t_symbol* s, t_int argc, t_atom* argv) { int i = argc; int chr, cnt, len; @@ -82,6 +82,12 @@ void ascseq_anything(t_ascseq *x,t_symbol* s,t_int argc,t_atom* argv) /* } */ } +void ascseq_symbol(t_ascseq *x, t_symbol *s) +{ + t_atom* a; + ascseq_anything(x, s, 0, a); +} + void ascseq_float(t_ascseq *x, t_floatarg f) { int chr, cnt, len; @@ -141,4 +147,5 @@ void ascseq_setup(void) class_addanything(ascseq_class,ascseq_anything); class_addfloat(ascseq_class, ascseq_float); class_addmethod(ascseq_class, (t_method)ascseq_ft1, gensym("ft1"), A_FLOAT, 0); + class_addsymbol(ascseq_class, ascseq_symbol); } diff --git a/cx.c b/cx.c index 5ef642e..a0e305c 100644 --- a/cx.c +++ b/cx.c @@ -34,6 +34,7 @@ void counter_setup(); void reson_setup(); //void serialize_setup(); void prepend_setup(); +void split_setup(); void utime_setup(); // RNG's void random1_setup(); @@ -77,6 +78,7 @@ void cxc_setup(void) reson_setup(); //serialize_setup(); prepend_setup(); + split_setup(); utime_setup(); // RNG's random1_setup(); diff --git a/makefile b/makefile index 2cf292e..8f9c078 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ VERSION = \"$(shell cat VERSION)\" LIBOSC = TARGETS = binshift ascwave ixprint bangfilt bangfilt2 \ - counter reson prepend microtime ascseq \ + counter reson prepend split microtime ascseq \ randomix ENV proc mean sigdelta cx # mean @@ -18,7 +18,7 @@ TARGETS = binshift ascwave ixprint bangfilt bangfilt2 \ LINUXOBJECTS = $(TARGETS:%=%.o) -LINCLUDE = -I. -I../pd-0.35-0/src +LINCLUDE = -I. -I../../pd/src # possible defines # -DPRINTADDRS DEBUG = -DDEBUG -ggdb diff --git a/reference/cxc.split.pd b/reference/cxc.split.pd new file mode 100644 index 0000000..823173b --- /dev/null +++ b/reference/cxc.split.pd @@ -0,0 +1,46 @@ +#N canvas 0 0 576 343 10; +#X msg 142 36 62.116.43.90; +#X obj 143 212 print; +#X obj 145 157 cxc.split .; +#X msg 243 100 set x; +#X msg 300 100 set zwejdgb; +#X msg 176 99 set .; +#X obj 384 260 print; +#X obj 373 214 route bla; +#X obj 268 232 pack f f f f; +#X msg 266 148 bang; +#X msg 268 194 2; +#X msg 298 195 22; +#X msg 320 193 3; +#X msg 346 194 43; +#X obj 267 171 t b b b b; +#X obj 111 277 unpack f f f f; +#X floatatom 111 307 5 0 0 0 - - -; +#X floatatom 153 307 5 0 0 0 - - -; +#X floatatom 194 307 5 0 0 0 - - -; +#X floatatom 233 307 5 0 0 0 - - -; +#X msg 390 168 list 62 118 57 46; +#X msg 278 28 bli.1.vlo.2.3.444; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X connect 2 0 15 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 5 0 2 0; +#X connect 7 1 6 0; +#X connect 8 0 6 0; +#X connect 9 0 14 0; +#X connect 10 0 8 0; +#X connect 11 0 8 1; +#X connect 12 0 8 2; +#X connect 13 0 8 3; +#X connect 14 0 10 0; +#X connect 14 1 11 0; +#X connect 14 2 12 0; +#X connect 14 3 13 0; +#X connect 15 0 16 0; +#X connect 15 1 17 0; +#X connect 15 2 18 0; +#X connect 15 3 19 0; +#X connect 20 0 7 0; +#X connect 21 0 2 0; diff --git a/split.c b/split.c new file mode 100644 index 0000000..69b2ce0 --- /dev/null +++ b/split.c @@ -0,0 +1,166 @@ +#include +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* this is taken from ggee, where the file was hanging around but the object was not + funtional. i keep it here for reference since i dont wnat to fix it over and over ;) + but its not included in the makefile to avoid namespace clash with ggee.prepend + anyhow, i ll just rename it cxc.prepend +*/ + +/* ------------------------ split ----------------------------- */ + +static t_class *split_class; + + +typedef struct _split +{ + t_object x_obj; + t_symbol* x_splitter; +} t_split; + + +void split_symbol(t_split *x, t_symbol *s) +{ + t_atom* a; + split_anything(x, s, 0, a); +} + +void split_anything(t_split *x,t_symbol* s,t_int argc,t_atom* argv) +{ + int i = argc; int j; + t_symbol* cur; + t_atom a_out[256]; + int c_out = 0; + t_atom* a = a_out; + char u[MAXPDSTRING]; char v[MAXPDSTRING]; + u[0] = '\0'; + v[0] = '\0'; + int isnum = 1; + + for(j=0; js_name); j++) { + u[0] = s->s_name[j]; + if(u[0] == x->x_splitter->s_name[0]) { + // post("found split: %d", v); + post("found split: %d", (int)v); +/* if(isnum) */ +/* SETFLOAT(a, (int)v); */ +/* else */ + SETSYMBOL(a, gensym(v)); + a++; c_out++; + // reset stuff + v[0] = '\0'; + isnum = 1; + } else { + if(!(48 <= u[0] <= 57)) { + isnum = 0; + } + strncat(v, u, 1); + } + } + // post("found split: %s", v); + SETSYMBOL(a, gensym(v)); + a++, c_out++; + +/* #if 1 */ +/* // post("sym: %s",s->s_name); */ +/* SETSYMBOL(a,s); */ +/* a++; */ +/* c_out++; */ +/* #endif */ + +/* while (i--) { */ +/* switch( argv->a_type) { */ +/* case A_FLOAT: */ +/* // post("flo: %f",atom_getfloat(argv)); */ +/* SETFLOAT(a,atom_getfloat(argv)); */ +/* a++; */ +/* c_out++; */ +/* break; */ +/* case A_SYMBOL: */ +/* // post("sym: %s",atom_getsymbol(argv)->s_name); */ +/* SETSYMBOL(a,atom_getsymbol(argv)); */ +/* a++; */ +/* c_out++; */ +/* break; */ +/* default: */ +/* post("split.c: unknown type"); */ +/* } */ +/* argv++; */ +/* } */ + + outlet_list(x->x_obj.ob_outlet, &s_list, c_out, (t_atom*)&a_out); + // outlet_anything(x->x_obj.ob_outlet,gensym("list"),c_out,(t_atom*)&a_out); +/* //post("done"); */ +} + +void split_list(t_split *x,t_symbol* s,t_int argc,t_atom* argv) +{ + int i = argc; + t_symbol* cur; + t_atom a_out[256]; + int c_out = 0; + t_atom* a = a_out; + + while (i--) { + switch( argv->a_type) { + case A_FLOAT: + // post("flo: %f",atom_getfloat(argv)); + SETFLOAT(a,atom_getfloat(argv)); + a++; + c_out++; + break; + case A_SYMBOL: + // post("sym: %s",atom_getsymbol(argv)->s_name); + SETSYMBOL(a,atom_getsymbol(argv)); + a++; + c_out++; + break; + default: + post("split.c: unknown type"); + } + argv++; + } + + outlet_anything(x->x_obj.ob_outlet,x->x_splitter,c_out,(t_atom*)&a_out); + //post("done"); +} + +static void *split_new(t_symbol* s) +{ + t_split *x = (t_split *)pd_new(split_class); + outlet_new(&x->x_obj, &s_float); + if (s != &s_) + x->x_splitter = s; + else + x->x_splitter = gensym("cxc.split"); + return (x); +} + +static void split_set(t_split *x, t_symbol *s) +{ + t_symbol *t; + // init temp splitter + char u[1]; u[0] = '\0'; + + if(strlen(s->s_name) > 1) { + // t = gensym((char*)s->s_name[0]); + // post("%d", s->s_name[0]); + strncat(u, s->s_name, 1); + t = gensym(u); + } else + t = s; + x->x_splitter = t; +} + +void split_setup(void) +{ + split_class = class_new(gensym("cxc.split"), (t_newmethod)split_new, 0, + sizeof(t_split), 0,A_DEFSYM,NULL); + class_addlist(split_class, split_list); + class_addanything(split_class,split_anything); + class_addmethod(split_class, (t_method)split_set, gensym("set"), A_SYMBOL, 0); + class_addsymbol(split_class, split_symbol); +} -- cgit v1.2.1