From c1419b43ea354fa04360450ae4f64612df065099 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 14 Nov 2005 21:59:09 +0000 Subject: these pragmas are only used for MSVC, not MinGW or Cygwin, therefore changing the define from NT to _MSC_VER svn path=/trunk/externals/ggee/; revision=3903 --- control/concat.c | 118 +++++----- control/constant.c | 122 +++++----- control/inv.c | 154 ++++++------- control/prepend.c | 152 ++++++------ control/qread.c | 258 ++++++++++----------- control/rl.c | 162 ++++++------- control/rtout.c | 82 +++---- control/serial_bird.c | 530 +++++++++++++++++++++--------------------- control/serial_ms.c | 240 +++++++++---------- control/serial_mt.c | 154 ++++++------- control/serialize.c | 116 +++++----- control/shell.c | 624 +++++++++++++++++++++++++------------------------- control/sinh.c | 108 ++++----- control/sl.c | 148 ++++++------ control/stripdir.c | 96 ++++---- control/unserialize.c | 114 ++++----- control/unwonk.c | 238 +++++++++---------- 17 files changed, 1708 insertions(+), 1708 deletions(-) (limited to 'control') diff --git a/control/concat.c b/control/concat.c index 2a8cc16..575f998 100755 --- a/control/concat.c +++ b/control/concat.c @@ -1,59 +1,59 @@ -/* (C) Guenter Geiger */ - - -#include -#include - -/* ------------------------ concat ----------------------------- */ - -#define MAX_ELEMENTS 256 - -static t_class *concat_class; - - -typedef struct _concat -{ - t_object x_obj; - t_symbol* x_sym; -} t_concat; - -static char tsym[2048]; - -void concat_float(t_concat *x,t_float f) -{ - sprintf(tsym,"%g",f); - strcat(tsym,x->x_sym->s_name); - - outlet_symbol(x->x_obj.ob_outlet,gensym(tsym)); -} - -void concat_symbol(t_concat *x,t_symbol* s) -{ - strcpy(tsym,s->s_name); - strcat(tsym,x->x_sym->s_name); - - outlet_symbol(x->x_obj.ob_outlet,gensym(tsym)); -} - - -static void *concat_new(t_symbol* s) -{ - t_concat *x = (t_concat *)pd_new(concat_class); - outlet_new(&x->x_obj,&s_float); - symbolinlet_new(&x->x_obj, &x->x_sym); - x->x_sym = s; - *tsym = 0; - return (x); -} - - - -void concat_setup(void) -{ - concat_class = class_new(gensym("concat"), (t_newmethod)concat_new, 0, - sizeof(t_concat),0, A_DEFSYM,0); - class_addsymbol(concat_class,concat_symbol); - class_addfloat(concat_class,concat_float); -} - - +/* (C) Guenter Geiger */ + + +#include +#include + +/* ------------------------ concat ----------------------------- */ + +#define MAX_ELEMENTS 256 + +static t_class *concat_class; + + +typedef struct _concat +{ + t_object x_obj; + t_symbol* x_sym; +} t_concat; + +static char tsym[2048]; + +void concat_float(t_concat *x,t_float f) +{ + sprintf(tsym,"%g",f); + strcat(tsym,x->x_sym->s_name); + + outlet_symbol(x->x_obj.ob_outlet,gensym(tsym)); +} + +void concat_symbol(t_concat *x,t_symbol* s) +{ + strcpy(tsym,s->s_name); + strcat(tsym,x->x_sym->s_name); + + outlet_symbol(x->x_obj.ob_outlet,gensym(tsym)); +} + + +static void *concat_new(t_symbol* s) +{ + t_concat *x = (t_concat *)pd_new(concat_class); + outlet_new(&x->x_obj,&s_float); + symbolinlet_new(&x->x_obj, &x->x_sym); + x->x_sym = s; + *tsym = 0; + return (x); +} + + + +void concat_setup(void) +{ + concat_class = class_new(gensym("concat"), (t_newmethod)concat_new, 0, + sizeof(t_concat),0, A_DEFSYM,0); + class_addsymbol(concat_class,concat_symbol); + class_addfloat(concat_class,concat_float); +} + + diff --git a/control/constant.c b/control/constant.c index 7e8ccfa..877326b 100755 --- a/control/constant.c +++ b/control/constant.c @@ -1,61 +1,61 @@ -/* (C) Guenter Geiger */ - - -#include -#include -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -/* ------------------------ constant ----------------------------- */ -#ifndef M_PI -#define M_PI 3.141593f -#endif - -static t_class *constant_class; - - -typedef struct _constant -{ - t_object x_obj; - t_float x_constant; -} t_constant; - - -void constant_bang(t_constant *x) -{ - outlet_float(x->x_obj.ob_outlet, x->x_constant); -} - -static void *constant_new(t_symbol* s) -{ - t_constant *x = (t_constant *)pd_new(constant_class); - - if (s == &s_) - x->x_constant = M_PI; - - if (!strcmp(s->s_name,"PI")) - x->x_constant = M_PI; - - if (!strcmp(s->s_name,"TWOPI")) - x->x_constant = 2*M_PI; - - if (!strcmp(s->s_name,"e")) - x->x_constant = exp(1.0); - - - - outlet_new(&x->x_obj, &s_float); - return (x); -} - -void constant_setup(void) -{ - constant_class = class_new(gensym("constant"), (t_newmethod)constant_new, 0, - sizeof(t_constant), 0,0); - class_addbang(constant_class,constant_bang); -} - - +/* (C) Guenter Geiger */ + + +#include +#include +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ constant ----------------------------- */ +#ifndef M_PI +#define M_PI 3.141593f +#endif + +static t_class *constant_class; + + +typedef struct _constant +{ + t_object x_obj; + t_float x_constant; +} t_constant; + + +void constant_bang(t_constant *x) +{ + outlet_float(x->x_obj.ob_outlet, x->x_constant); +} + +static void *constant_new(t_symbol* s) +{ + t_constant *x = (t_constant *)pd_new(constant_class); + + if (s == &s_) + x->x_constant = M_PI; + + if (!strcmp(s->s_name,"PI")) + x->x_constant = M_PI; + + if (!strcmp(s->s_name,"TWOPI")) + x->x_constant = 2*M_PI; + + if (!strcmp(s->s_name,"e")) + x->x_constant = exp(1.0); + + + + outlet_new(&x->x_obj, &s_float); + return (x); +} + +void constant_setup(void) +{ + constant_class = class_new(gensym("constant"), (t_newmethod)constant_new, 0, + sizeof(t_constant), 0,0); + class_addbang(constant_class,constant_bang); +} + + diff --git a/control/inv.c b/control/inv.c index df6c2e2..0cff552 100755 --- a/control/inv.c +++ b/control/inv.c @@ -1,77 +1,77 @@ -/* (C) Guenter Geiger */ - -#include - - -typedef struct inv -{ - t_object x_obj; -} t_inv; - -static t_class *inv_class; - -static void *inv_new(void) -{ - t_inv *x = (t_inv *)pd_new(inv_class); - outlet_new(&x->x_obj, gensym("signal")); - return (x); -} - -static t_int *inv_perform(t_int *w) /* not static; also used in d_fft.c */ -{ - float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2); - t_int n = *(t_int *)(w+3); - while (n--) - { - *out++ = 1/ *in++; - } - return (w + 4); -} - -static void inv_dsp(t_inv *x, t_signal **sp) -{ - dsp_add(inv_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); -} - -void inv_tilde_setup(void) -{ - inv_class = class_new(gensym("inv~"), (t_newmethod)inv_new, 0, - sizeof(t_inv), 0, 0); - - class_addcreator(inv_new,gensym("1/x~"),0); - - class_addmethod(inv_class, nullfn, gensym("signal"), 0); - class_addmethod(inv_class, (t_method)inv_dsp, gensym("dsp"), 0); -} - - - - -typedef struct scalarinv -{ - t_object x_obj; -} t_scalarinv; - -static t_class *scalarinv_class; - -static void *scalarinv_new(void) -{ - t_scalarinv *x = (t_scalarinv *)pd_new(scalarinv_class); - outlet_new(&x->x_obj, gensym("float")); - return (x); -} - -static void scalarinv_float(t_scalarinv *x,t_float val) -{ - outlet_float(x->x_obj.ob_outlet,1.0f/val); - -} - -void inv_setup(void) -{ - scalarinv_class = class_new(gensym("inv"), (t_newmethod)scalarinv_new, 0, - sizeof(t_scalarinv), 0, 0); - class_addcreator(scalarinv_new,gensym("1/x"),0); - - class_addfloat(scalarinv_class, (t_method)scalarinv_float); -} +/* (C) Guenter Geiger */ + +#include + + +typedef struct inv +{ + t_object x_obj; +} t_inv; + +static t_class *inv_class; + +static void *inv_new(void) +{ + t_inv *x = (t_inv *)pd_new(inv_class); + outlet_new(&x->x_obj, gensym("signal")); + return (x); +} + +static t_int *inv_perform(t_int *w) /* not static; also used in d_fft.c */ +{ + float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2); + t_int n = *(t_int *)(w+3); + while (n--) + { + *out++ = 1/ *in++; + } + return (w + 4); +} + +static void inv_dsp(t_inv *x, t_signal **sp) +{ + dsp_add(inv_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void inv_tilde_setup(void) +{ + inv_class = class_new(gensym("inv~"), (t_newmethod)inv_new, 0, + sizeof(t_inv), 0, 0); + + class_addcreator(inv_new,gensym("1/x~"),0); + + class_addmethod(inv_class, nullfn, gensym("signal"), 0); + class_addmethod(inv_class, (t_method)inv_dsp, gensym("dsp"), 0); +} + + + + +typedef struct scalarinv +{ + t_object x_obj; +} t_scalarinv; + +static t_class *scalarinv_class; + +static void *scalarinv_new(void) +{ + t_scalarinv *x = (t_scalarinv *)pd_new(scalarinv_class); + outlet_new(&x->x_obj, gensym("float")); + return (x); +} + +static void scalarinv_float(t_scalarinv *x,t_float val) +{ + outlet_float(x->x_obj.ob_outlet,1.0f/val); + +} + +void inv_setup(void) +{ + scalarinv_class = class_new(gensym("inv"), (t_newmethod)scalarinv_new, 0, + sizeof(t_scalarinv), 0, 0); + class_addcreator(scalarinv_new,gensym("1/x"),0); + + class_addfloat(scalarinv_class, (t_method)scalarinv_float); +} diff --git a/control/prepend.c b/control/prepend.c index 7b5bb0f..f0c6f15 100755 --- a/control/prepend.c +++ b/control/prepend.c @@ -1,76 +1,76 @@ -/* (C) Guenter Geiger */ - - -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -/* ------------------------ prepend ----------------------------- */ - -static t_class *prepend_class; - - -typedef struct _prepend -{ - t_object x_obj; - t_symbol* x_s; -} t_prepend; - - -void prepend_anything(t_prepend *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; - - if (argv->a_type == A_SYMBOL) { - SETSYMBOL(a,s); - a++; - c_out++; - } - - while (i--) { - switch( argv->a_type) { - case A_FLOAT: - SETFLOAT(a,atom_getfloat(argv)); - a++; - c_out++; - break; - case A_SYMBOL: - SETSYMBOL(a,atom_getsymbol(argv)); - a++; - c_out++; - break; - default: - post("unknown type"); - } - argv++; - } - outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out); -} - -static void *prepend_new(t_symbol* s) -{ - t_prepend *x = (t_prepend *)pd_new(prepend_class); - outlet_new(&x->x_obj, &s_float); - if (s != &s_) - x->x_s = s; - else { - x->x_s = gensym("prepend"); - error("prepend needs symbol argument"); - } - return (x); -} - -void prepend_setup(void) -{ - prepend_class = class_new(gensym("prepend"), (t_newmethod)prepend_new, 0, - sizeof(t_prepend), 0,A_DEFSYM,NULL); - class_addanything(prepend_class,prepend_anything); -} - - +/* (C) Guenter Geiger */ + + +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ prepend ----------------------------- */ + +static t_class *prepend_class; + + +typedef struct _prepend +{ + t_object x_obj; + t_symbol* x_s; +} t_prepend; + + +void prepend_anything(t_prepend *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; + + if (argv->a_type == A_SYMBOL) { + SETSYMBOL(a,s); + a++; + c_out++; + } + + while (i--) { + switch( argv->a_type) { + case A_FLOAT: + SETFLOAT(a,atom_getfloat(argv)); + a++; + c_out++; + break; + case A_SYMBOL: + SETSYMBOL(a,atom_getsymbol(argv)); + a++; + c_out++; + break; + default: + post("unknown type"); + } + argv++; + } + outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out); +} + +static void *prepend_new(t_symbol* s) +{ + t_prepend *x = (t_prepend *)pd_new(prepend_class); + outlet_new(&x->x_obj, &s_float); + if (s != &s_) + x->x_s = s; + else { + x->x_s = gensym("prepend"); + error("prepend needs symbol argument"); + } + return (x); +} + +void prepend_setup(void) +{ + prepend_class = class_new(gensym("prepend"), (t_newmethod)prepend_new, 0, + sizeof(t_prepend), 0,A_DEFSYM,NULL); + class_addanything(prepend_class,prepend_anything); +} + + diff --git a/control/qread.c b/control/qread.c index f7c3897..28112df 100755 --- a/control/qread.c +++ b/control/qread.c @@ -1,129 +1,129 @@ -/* (C) Guenter Geiger */ - - -#include - -/* ------------------------ qread ----------------------------- */ - -#include - -static t_class *qread_class; - - -#define MAXLINE 255 - -typedef struct _qread -{ - t_object x_obj; - FILE* x_file; - int x_size; - t_clock* x_clock; - t_glist * x_glist; - int x_num; - t_symbol* x_name; -} t_qread; - - - -static void qread_open(t_qread *x,t_symbol *filename) -{ - char fname[MAXPDSTRING]; - - if (filename == &s_) { - post("sfread: open without filename"); - return; - } - - canvas_makefilename((void*)glist_getcanvas(x->x_glist), filename->s_name, - fname, MAXPDSTRING); - - - /* close the old file */ - - if (x->x_file) fclose(x->x_file); - - if (!(x->x_file = fopen(fname,"r"))) - { - error("can't open %s",fname); - return; - } - - -} - -void qread_next(t_qread *x) -{ - int i; - float delay; - char name[MAXLINE]; - t_atom at[20]; - int ac=0; - t_floatarg ff; - - if (!x->x_file) return; - - fscanf(x->x_file,"%f",&delay); - if (feof(x->x_file)) { - clock_unset(x->x_clock); - return; - } - - fscanf(x->x_file,"%s",name); -#ifdef DEBUG - post("next: name = %s delay = %f",name,delay); -#endif - - for (i=0;i<=x->x_num && !feof(x->x_file);i++) { - fscanf(x->x_file,"%f",&ff); - SETFLOAT(at+i,ff); - } - ac = i-1; - fscanf(x->x_file,";"); - - - clock_delay(x->x_clock,delay); - - outlet_list(x->x_obj.ob_outlet, gensym(name), ac, at); -} - -static void qread_bang(t_qread *x) -{ - if (!x->x_file) return; - - fseek(x->x_file,0,SEEK_SET); - clock_delay(x->x_clock,0); - -#ifdef DEBUG - post("bang"); -#endif -} - -static void qread_stop(t_qread *x) -{ - clock_unset(x->x_clock); -} - -static void *qread_new(t_floatarg n) -{ - t_qread *x = (t_qread *)pd_new(qread_class); - outlet_new(&x->x_obj, &s_float); - - x->x_name = gensym("qread"); - x->x_glist = (t_glist*) canvas_getcurrent(); - x->x_clock = clock_new(x, (t_method)qread_next); - x->x_file = NULL; - x->x_num = n; - return (x); -} - -void qread_setup(void) -{ - qread_class = class_new(gensym("qread"), (t_newmethod)qread_new, 0, - sizeof(t_qread), 0,A_DEFFLOAT,A_NULL); - class_addbang(qread_class,qread_bang); - class_addmethod(qread_class,(t_method)qread_next,gensym("next"),A_NULL); - class_addmethod(qread_class,(t_method)qread_open,gensym("open"),A_SYMBOL,A_NULL); - class_addmethod(qread_class,(t_method)qread_stop,gensym("stop"),A_NULL); -} - - +/* (C) Guenter Geiger */ + + +#include + +/* ------------------------ qread ----------------------------- */ + +#include + +static t_class *qread_class; + + +#define MAXLINE 255 + +typedef struct _qread +{ + t_object x_obj; + FILE* x_file; + int x_size; + t_clock* x_clock; + t_glist * x_glist; + int x_num; + t_symbol* x_name; +} t_qread; + + + +static void qread_open(t_qread *x,t_symbol *filename) +{ + char fname[MAXPDSTRING]; + + if (filename == &s_) { + post("sfread: open without filename"); + return; + } + + canvas_makefilename((void*)glist_getcanvas(x->x_glist), filename->s_name, + fname, MAXPDSTRING); + + + /* close the old file */ + + if (x->x_file) fclose(x->x_file); + + if (!(x->x_file = fopen(fname,"r"))) + { + error("can't open %s",fname); + return; + } + + +} + +void qread_next(t_qread *x) +{ + int i; + float delay; + char name[MAXLINE]; + t_atom at[20]; + int ac=0; + t_floatarg ff; + + if (!x->x_file) return; + + fscanf(x->x_file,"%f",&delay); + if (feof(x->x_file)) { + clock_unset(x->x_clock); + return; + } + + fscanf(x->x_file,"%s",name); +#ifdef DEBUG + post("next: name = %s delay = %f",name,delay); +#endif + + for (i=0;i<=x->x_num && !feof(x->x_file);i++) { + fscanf(x->x_file,"%f",&ff); + SETFLOAT(at+i,ff); + } + ac = i-1; + fscanf(x->x_file,";"); + + + clock_delay(x->x_clock,delay); + + outlet_list(x->x_obj.ob_outlet, gensym(name), ac, at); +} + +static void qread_bang(t_qread *x) +{ + if (!x->x_file) return; + + fseek(x->x_file,0,SEEK_SET); + clock_delay(x->x_clock,0); + +#ifdef DEBUG + post("bang"); +#endif +} + +static void qread_stop(t_qread *x) +{ + clock_unset(x->x_clock); +} + +static void *qread_new(t_floatarg n) +{ + t_qread *x = (t_qread *)pd_new(qread_class); + outlet_new(&x->x_obj, &s_float); + + x->x_name = gensym("qread"); + x->x_glist = (t_glist*) canvas_getcurrent(); + x->x_clock = clock_new(x, (t_method)qread_next); + x->x_file = NULL; + x->x_num = n; + return (x); +} + +void qread_setup(void) +{ + qread_class = class_new(gensym("qread"), (t_newmethod)qread_new, 0, + sizeof(t_qread), 0,A_DEFFLOAT,A_NULL); + class_addbang(qread_class,qread_bang); + class_addmethod(qread_class,(t_method)qread_next,gensym("next"),A_NULL); + class_addmethod(qread_class,(t_method)qread_open,gensym("open"),A_SYMBOL,A_NULL); + class_addmethod(qread_class,(t_method)qread_stop,gensym("stop"),A_NULL); +} + + diff --git a/control/rl.c b/control/rl.c index dba7f78..55bddaf 100755 --- a/control/rl.c +++ b/control/rl.c @@ -1,81 +1,81 @@ -/* (C) Guenter Geiger */ - - -#include -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - - -/* -------------------- lreceive ------------------------------ */ - -static t_class *lreceive_class; - -typedef struct _lreceive -{ - t_object x_obj; - t_symbol *x_sym; -} t_lreceive; - -static void lreceive_bang(t_lreceive *x) -{ - outlet_bang(x->x_obj.ob_outlet); -} - -static void lreceive_float(t_lreceive *x, t_float f) -{ - outlet_float(x->x_obj.ob_outlet, f); -} - -static void lreceive_symbol(t_lreceive *x, t_symbol *s) -{ - outlet_symbol(x->x_obj.ob_outlet, s); -} - -static void lreceive_pointer(t_lreceive *x, t_gpointer *gp) -{ - outlet_pointer(x->x_obj.ob_outlet, gp); -} - -static void lreceive_list(t_lreceive *x, t_symbol *s, int argc, t_atom *argv) -{ - outlet_list(x->x_obj.ob_outlet, s, argc, argv); -} - -static void lreceive_anything(t_lreceive *x, t_symbol *s, int argc, t_atom *argv) -{ - outlet_anything(x->x_obj.ob_outlet, s, argc, argv); -} - -static void *lreceive_new(t_symbol *s) -{ - t_lreceive *x = (t_lreceive *)pd_new(lreceive_class); - char mysym[MAXPDSTRING]; - - sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent()); - x->x_sym = gensym(mysym); - pd_bind(&x->x_obj.ob_pd, x->x_sym); - outlet_new(&x->x_obj, 0); - return (x); -} - -static void lreceive_free(t_lreceive *x) -{ - pd_unbind(&x->x_obj.ob_pd, x->x_sym); -} - -void rl_setup(void) -{ - lreceive_class = class_new(gensym("receivelocal"), (t_newmethod)lreceive_new, - (t_method)lreceive_free, sizeof(t_lreceive), CLASS_NOINLET, A_SYMBOL, 0); - class_addcreator((t_newmethod)lreceive_new, gensym("rl"), A_DEFSYM, 0); - class_addbang(lreceive_class, lreceive_bang); - class_addfloat(lreceive_class, (t_method)lreceive_float); - class_addsymbol(lreceive_class, lreceive_symbol); - class_addpointer(lreceive_class, lreceive_pointer); - class_addlist(lreceive_class, lreceive_list); - class_addanything(lreceive_class, lreceive_anything); - post("Warning: receivelocal (rl) is deprecated, please use \"receive $0-var\" instead"); -} +/* (C) Guenter Geiger */ + + +#include +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + + +/* -------------------- lreceive ------------------------------ */ + +static t_class *lreceive_class; + +typedef struct _lreceive +{ + t_object x_obj; + t_symbol *x_sym; +} t_lreceive; + +static void lreceive_bang(t_lreceive *x) +{ + outlet_bang(x->x_obj.ob_outlet); +} + +static void lreceive_float(t_lreceive *x, t_float f) +{ + outlet_float(x->x_obj.ob_outlet, f); +} + +static void lreceive_symbol(t_lreceive *x, t_symbol *s) +{ + outlet_symbol(x->x_obj.ob_outlet, s); +} + +static void lreceive_pointer(t_lreceive *x, t_gpointer *gp) +{ + outlet_pointer(x->x_obj.ob_outlet, gp); +} + +static void lreceive_list(t_lreceive *x, t_symbol *s, int argc, t_atom *argv) +{ + outlet_list(x->x_obj.ob_outlet, s, argc, argv); +} + +static void lreceive_anything(t_lreceive *x, t_symbol *s, int argc, t_atom *argv) +{ + outlet_anything(x->x_obj.ob_outlet, s, argc, argv); +} + +static void *lreceive_new(t_symbol *s) +{ + t_lreceive *x = (t_lreceive *)pd_new(lreceive_class); + char mysym[MAXPDSTRING]; + + sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent()); + x->x_sym = gensym(mysym); + pd_bind(&x->x_obj.ob_pd, x->x_sym); + outlet_new(&x->x_obj, 0); + return (x); +} + +static void lreceive_free(t_lreceive *x) +{ + pd_unbind(&x->x_obj.ob_pd, x->x_sym); +} + +void rl_setup(void) +{ + lreceive_class = class_new(gensym("receivelocal"), (t_newmethod)lreceive_new, + (t_method)lreceive_free, sizeof(t_lreceive), CLASS_NOINLET, A_SYMBOL, 0); + class_addcreator((t_newmethod)lreceive_new, gensym("rl"), A_DEFSYM, 0); + class_addbang(lreceive_class, lreceive_bang); + class_addfloat(lreceive_class, (t_method)lreceive_float); + class_addsymbol(lreceive_class, lreceive_symbol); + class_addpointer(lreceive_class, lreceive_pointer); + class_addlist(lreceive_class, lreceive_list); + class_addanything(lreceive_class, lreceive_anything); + post("Warning: receivelocal (rl) is deprecated, please use \"receive $0-var\" instead"); +} diff --git a/control/rtout.c b/control/rtout.c index 95df28c..bc211e2 100755 --- a/control/rtout.c +++ b/control/rtout.c @@ -1,41 +1,41 @@ -/* (C) Guenter Geiger */ - - -#include - -/* -------------------------- rtout -------------------------- */ - -void sys_putmidimess(int portno, int a, int b, int c); - -static t_class *rtout_class; - - - -typedef struct _rtout -{ - t_object x_obj; - t_float x_rt; - t_float x_channel; -} t_rtout; - -static void *rtout_new(t_floatarg channel) -{ - t_rtout *x = (t_rtout *)pd_new(rtout_class); - if (channel <= 0) channel = 1; - x->x_channel = channel; - return (x); -} - -static void rtout_float(t_rtout *x, t_float f) -{ - int binchan = (int) x->x_channel - 1; - sys_putmidimess((binchan>>4),(int) f,0,0); -} - -void rtout_setup(void) -{ - rtout_class = class_new(gensym("rtout"), (t_newmethod)rtout_new, 0, - sizeof(t_rtout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); - class_addfloat(rtout_class, rtout_float); -} - +/* (C) Guenter Geiger */ + + +#include + +/* -------------------------- rtout -------------------------- */ + +void sys_putmidimess(int portno, int a, int b, int c); + +static t_class *rtout_class; + + + +typedef struct _rtout +{ + t_object x_obj; + t_float x_rt; + t_float x_channel; +} t_rtout; + +static void *rtout_new(t_floatarg channel) +{ + t_rtout *x = (t_rtout *)pd_new(rtout_class); + if (channel <= 0) channel = 1; + x->x_channel = channel; + return (x); +} + +static void rtout_float(t_rtout *x, t_float f) +{ + int binchan = (int) x->x_channel - 1; + sys_putmidimess((binchan>>4),(int) f,0,0); +} + +void rtout_setup(void) +{ + rtout_class = class_new(gensym("rtout"), (t_newmethod)rtout_new, 0, + sizeof(t_rtout), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addfloat(rtout_class, rtout_float); +} + diff --git a/control/serial_bird.c b/control/serial_bird.c index 410202a..6423dc7 100755 --- a/control/serial_bird.c +++ b/control/serial_bird.c @@ -1,265 +1,265 @@ -/* (C) Guenter Geiger */ - - -#include -#include - -#define DEBUG(x) -/*#define DEBUG(x) x*/ - -static t_class *serial_bird_class; - - -#define BIRD_DATA_START 0x80 - -#define BIRDCMD_MODE_POS 86 -#define BIRD_BYTES_POS 6 - -#define BIRDCMD_MODE_POSANG 89 -#define BIRD_BYTES_POSANG 12 - -#define BIRDCMD_MODE_POSMAT 90 -#define BIRD_BYTES_POSMAT 24 - -#define BIRDCMD_MODE_POSQUAT 93 -#define BIRD_BYTES_POSQUAT 14 - -#define BIRDCMD_MODE_QUAT 92 -#define BIRD_BYTES_QUAT 8 - -#define BIRDCMD_STREAM 64 -#define BIRDCMD_POINT 66 - -#define BIRD_GETDATA(x,y) ((float)((short)(y<<9 | x<<2))) - -#define MAXBUFFER 32 - - - -typedef struct _serial_bird -{ - t_object x_obj; - char x_c[MAXBUFFER]; - t_int x_dataformat; - t_int x_maxcount; - t_int x_count; - t_float x_posx; - t_float x_posy; - t_float x_posz; - t_outlet *x_out2; -} t_serial_bird; - - -static void serial_bird_reset( t_serial_bird* x) -{ - x->x_posx=0; - x->x_posy=0; - x->x_count = 0; - outlet_float(x->x_obj.ob_outlet, x->x_posx); - outlet_float(x->x_out2, x->x_posy); -} - -static void serial_bird_float( t_serial_bird* x,t_floatarg f) -{ - unsigned char c = (unsigned char) f; - t_atom at[BIRD_BYTES_POSMAT]; - t_int ac = 0; - - if (c&BIRD_DATA_START) { - x->x_count=0; - x->x_c[x->x_count] = c & 0x7f; - } - else - x->x_c[x->x_count] = c; - - DEBUG(post("data %d in = %x, start = %d",x->x_count,c,c&BIRD_DATA_START);) - - if (x->x_count == x->x_maxcount-1) { - switch (x->x_dataformat) { - case BIRDCMD_MODE_POS: - ac = 3; - SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1])); - SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3])); - SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5])); - break; - case BIRDCMD_MODE_POSANG: - ac = 6; - SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1])); - SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3])); - SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5])); - SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); - SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); - SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); - break; - case BIRDCMD_MODE_POSMAT: - ac = 12; - SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); - SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); - SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); - SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); - SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); - SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); - SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13])); - SETFLOAT(&at[7], BIRD_GETDATA(x->x_c[14],x->x_c[15])); - SETFLOAT(&at[8], BIRD_GETDATA(x->x_c[16],x->x_c[17])); - SETFLOAT(&at[9], BIRD_GETDATA(x->x_c[18],x->x_c[19])); - SETFLOAT(&at[10], BIRD_GETDATA(x->x_c[20],x->x_c[21])); - SETFLOAT(&at[11], BIRD_GETDATA(x->x_c[22],x->x_c[23])); - break; - case BIRDCMD_MODE_POSQUAT: - ac = 7; - SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); - SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); - SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); - SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); - SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); - SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); - SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13])); - break; - case BIRDCMD_MODE_QUAT: - ac = 4; - SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); - SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); - SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); - SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); - break; - } - -/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ - outlet_list(x->x_obj.ob_outlet,&s_list, ac, at); - } - - x->x_count = (++x->x_count)%(x->x_maxcount); -} - -static void serial_bird_poll( t_serial_bird* x) -{ - post("poll"); - /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ - outlet_float(x->x_out2,(float)BIRDCMD_POINT); -} - -static void serial_bird_mode( t_serial_bird* x,t_symbol* s) -{ - post("mode"); - /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ - - - if (!strcmp(s->s_name,"position")) { - x->x_dataformat = BIRDCMD_MODE_POS; - x->x_maxcount = BIRD_BYTES_POS; - } - - if (!strcmp(s->s_name,"positionangle")) { - x->x_dataformat = BIRDCMD_MODE_POSANG; - x->x_maxcount = BIRD_BYTES_POSANG; - } - - if (!strcmp(s->s_name,"positionmatrix")) { - x->x_dataformat = BIRDCMD_MODE_POSMAT; - x->x_maxcount = BIRD_BYTES_POSMAT; - } - - if (!strcmp(s->s_name,"positionquat")) { - x->x_dataformat = BIRDCMD_MODE_POSQUAT; - x->x_maxcount = BIRD_BYTES_POSQUAT; - } - - if (!strcmp(s->s_name,"quaternion")) { - x->x_dataformat = BIRDCMD_MODE_QUAT; - x->x_maxcount = BIRD_BYTES_QUAT; - } - - outlet_float(x->x_out2,(float)x->x_dataformat); -} - -static void serial_bird_init( t_serial_bird* x) -{ - t_atom cmd[8]; - - SETFLOAT(cmd,14400.); - outlet_anything(x->x_out2,gensym("speed"),1,cmd); - - - SETFLOAT(cmd,0.); - SETSYMBOL(cmd+1,gensym("CLOCAL")); - SETSYMBOL(cmd+2,gensym("CREAD")); - SETSYMBOL(cmd+3,gensym("CS8")); - outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd); - - SETFLOAT(cmd,0.); - SETSYMBOL(cmd+1,gensym("IXOFF")); - outlet_anything(x->x_out2,gensym("setinput"),2,cmd); - - SETFLOAT(cmd,0.); - outlet_anything(x->x_out2,gensym("setlocal"),1,cmd); - - SETFLOAT(cmd,0.); - SETFLOAT(cmd+1,20.); - outlet_anything(x->x_out2,gensym("vtime"),2,cmd); - - - SETSYMBOL(cmd,gensym("RTS")); - SETFLOAT(cmd+1,0.); - outlet_anything(x->x_out2,gensym("setlines"),2,cmd); - - SETSYMBOL(cmd,gensym("DTR")); - SETFLOAT(cmd+1,1.); - outlet_anything(x->x_out2,gensym("setlines"),2,cmd); - - - /* start the polling on the serial device immediately */ - - outlet_anything(x->x_out2,gensym("start"),0,cmd); - -} - -static void serial_bird_start( t_serial_bird* x) -{ - post("start"); - /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ - outlet_float(x->x_out2,(float)BIRDCMD_STREAM); -} - - -static void serial_bird_stop( t_serial_bird* x) -{ - post("stop"); - outlet_float(x->x_out2,(float)BIRDCMD_POINT); -} - -static void *serial_bird_new(t_symbol *s) -{ - t_serial_bird *x = (t_serial_bird *)pd_new(serial_bird_class); - - x->x_count = 0; - x->x_posx = 0; - x->x_posy = 0; - x->x_dataformat = BIRDCMD_MODE_POSANG; - x->x_maxcount = BIRD_BYTES_POSANG; - - - outlet_new(&x->x_obj, &s_float); - x->x_out2 = outlet_new(&x->x_obj, &s_float); - - return x; -} - - -void serial_bird_setup(void) -{ - serial_bird_class = class_new(gensym("serial_bird"), (t_newmethod)serial_bird_new, - NULL, - sizeof(t_serial_bird), 0,A_DEFSYM,0); - class_addfloat(serial_bird_class,serial_bird_float); - class_addmethod(serial_bird_class,(t_method) serial_bird_reset,gensym("reset"),0); - class_addmethod(serial_bird_class,(t_method) serial_bird_init,gensym("init"),0); - - - class_addmethod(serial_bird_class,(t_method) serial_bird_start,gensym("start"),0); - class_addmethod(serial_bird_class,(t_method) serial_bird_stop,gensym("stop"),0); - class_addmethod(serial_bird_class,(t_method) serial_bird_poll,gensym("poll"),0); - class_addmethod(serial_bird_class,(t_method) serial_bird_mode,gensym("mode"),A_SYMBOL,NULL); -} - - +/* (C) Guenter Geiger */ + + +#include +#include + +#define DEBUG(x) +/*#define DEBUG(x) x*/ + +static t_class *serial_bird_class; + + +#define BIRD_DATA_START 0x80 + +#define BIRDCMD_MODE_POS 86 +#define BIRD_BYTES_POS 6 + +#define BIRDCMD_MODE_POSANG 89 +#define BIRD_BYTES_POSANG 12 + +#define BIRDCMD_MODE_POSMAT 90 +#define BIRD_BYTES_POSMAT 24 + +#define BIRDCMD_MODE_POSQUAT 93 +#define BIRD_BYTES_POSQUAT 14 + +#define BIRDCMD_MODE_QUAT 92 +#define BIRD_BYTES_QUAT 8 + +#define BIRDCMD_STREAM 64 +#define BIRDCMD_POINT 66 + +#define BIRD_GETDATA(x,y) ((float)((short)(y<<9 | x<<2))) + +#define MAXBUFFER 32 + + + +typedef struct _serial_bird +{ + t_object x_obj; + char x_c[MAXBUFFER]; + t_int x_dataformat; + t_int x_maxcount; + t_int x_count; + t_float x_posx; + t_float x_posy; + t_float x_posz; + t_outlet *x_out2; +} t_serial_bird; + + +static void serial_bird_reset( t_serial_bird* x) +{ + x->x_posx=0; + x->x_posy=0; + x->x_count = 0; + outlet_float(x->x_obj.ob_outlet, x->x_posx); + outlet_float(x->x_out2, x->x_posy); +} + +static void serial_bird_float( t_serial_bird* x,t_floatarg f) +{ + unsigned char c = (unsigned char) f; + t_atom at[BIRD_BYTES_POSMAT]; + t_int ac = 0; + + if (c&BIRD_DATA_START) { + x->x_count=0; + x->x_c[x->x_count] = c & 0x7f; + } + else + x->x_c[x->x_count] = c; + + DEBUG(post("data %d in = %x, start = %d",x->x_count,c,c&BIRD_DATA_START);) + + if (x->x_count == x->x_maxcount-1) { + switch (x->x_dataformat) { + case BIRDCMD_MODE_POS: + ac = 3; + SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1])); + SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3])); + SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5])); + break; + case BIRDCMD_MODE_POSANG: + ac = 6; + SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1])); + SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3])); + SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5])); + SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); + SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); + SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); + break; + case BIRDCMD_MODE_POSMAT: + ac = 12; + SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); + SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); + SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); + SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); + SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); + SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); + SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13])); + SETFLOAT(&at[7], BIRD_GETDATA(x->x_c[14],x->x_c[15])); + SETFLOAT(&at[8], BIRD_GETDATA(x->x_c[16],x->x_c[17])); + SETFLOAT(&at[9], BIRD_GETDATA(x->x_c[18],x->x_c[19])); + SETFLOAT(&at[10], BIRD_GETDATA(x->x_c[20],x->x_c[21])); + SETFLOAT(&at[11], BIRD_GETDATA(x->x_c[22],x->x_c[23])); + break; + case BIRDCMD_MODE_POSQUAT: + ac = 7; + SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); + SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); + SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); + SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); + SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9])); + SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11])); + SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13])); + break; + case BIRDCMD_MODE_QUAT: + ac = 4; + SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1])); + SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3])); + SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5])); + SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7])); + break; + } + +/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ + outlet_list(x->x_obj.ob_outlet,&s_list, ac, at); + } + + x->x_count = (++x->x_count)%(x->x_maxcount); +} + +static void serial_bird_poll( t_serial_bird* x) +{ + post("poll"); + /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ + outlet_float(x->x_out2,(float)BIRDCMD_POINT); +} + +static void serial_bird_mode( t_serial_bird* x,t_symbol* s) +{ + post("mode"); + /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ + + + if (!strcmp(s->s_name,"position")) { + x->x_dataformat = BIRDCMD_MODE_POS; + x->x_maxcount = BIRD_BYTES_POS; + } + + if (!strcmp(s->s_name,"positionangle")) { + x->x_dataformat = BIRDCMD_MODE_POSANG; + x->x_maxcount = BIRD_BYTES_POSANG; + } + + if (!strcmp(s->s_name,"positionmatrix")) { + x->x_dataformat = BIRDCMD_MODE_POSMAT; + x->x_maxcount = BIRD_BYTES_POSMAT; + } + + if (!strcmp(s->s_name,"positionquat")) { + x->x_dataformat = BIRDCMD_MODE_POSQUAT; + x->x_maxcount = BIRD_BYTES_POSQUAT; + } + + if (!strcmp(s->s_name,"quaternion")) { + x->x_dataformat = BIRDCMD_MODE_QUAT; + x->x_maxcount = BIRD_BYTES_QUAT; + } + + outlet_float(x->x_out2,(float)x->x_dataformat); +} + +static void serial_bird_init( t_serial_bird* x) +{ + t_atom cmd[8]; + + SETFLOAT(cmd,14400.); + outlet_anything(x->x_out2,gensym("speed"),1,cmd); + + + SETFLOAT(cmd,0.); + SETSYMBOL(cmd+1,gensym("CLOCAL")); + SETSYMBOL(cmd+2,gensym("CREAD")); + SETSYMBOL(cmd+3,gensym("CS8")); + outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd); + + SETFLOAT(cmd,0.); + SETSYMBOL(cmd+1,gensym("IXOFF")); + outlet_anything(x->x_out2,gensym("setinput"),2,cmd); + + SETFLOAT(cmd,0.); + outlet_anything(x->x_out2,gensym("setlocal"),1,cmd); + + SETFLOAT(cmd,0.); + SETFLOAT(cmd+1,20.); + outlet_anything(x->x_out2,gensym("vtime"),2,cmd); + + + SETSYMBOL(cmd,gensym("RTS")); + SETFLOAT(cmd+1,0.); + outlet_anything(x->x_out2,gensym("setlines"),2,cmd); + + SETSYMBOL(cmd,gensym("DTR")); + SETFLOAT(cmd+1,1.); + outlet_anything(x->x_out2,gensym("setlines"),2,cmd); + + + /* start the polling on the serial device immediately */ + + outlet_anything(x->x_out2,gensym("start"),0,cmd); + +} + +static void serial_bird_start( t_serial_bird* x) +{ + post("start"); + /* outlet_float(x->x_out2,(float)x->x_dataformat);*/ + outlet_float(x->x_out2,(float)BIRDCMD_STREAM); +} + + +static void serial_bird_stop( t_serial_bird* x) +{ + post("stop"); + outlet_float(x->x_out2,(float)BIRDCMD_POINT); +} + +static void *serial_bird_new(t_symbol *s) +{ + t_serial_bird *x = (t_serial_bird *)pd_new(serial_bird_class); + + x->x_count = 0; + x->x_posx = 0; + x->x_posy = 0; + x->x_dataformat = BIRDCMD_MODE_POSANG; + x->x_maxcount = BIRD_BYTES_POSANG; + + + outlet_new(&x->x_obj, &s_float); + x->x_out2 = outlet_new(&x->x_obj, &s_float); + + return x; +} + + +void serial_bird_setup(void) +{ + serial_bird_class = class_new(gensym("serial_bird"), (t_newmethod)serial_bird_new, + NULL, + sizeof(t_serial_bird), 0,A_DEFSYM,0); + class_addfloat(serial_bird_class,serial_bird_float); + class_addmethod(serial_bird_class,(t_method) serial_bird_reset,gensym("reset"),0); + class_addmethod(serial_bird_class,(t_method) serial_bird_init,gensym("init"),0); + + + class_addmethod(serial_bird_class,(t_method) serial_bird_start,gensym("start"),0); + class_addmethod(serial_bird_class,(t_method) serial_bird_stop,gensym("stop"),0); + class_addmethod(serial_bird_class,(t_method) serial_bird_poll,gensym("poll"),0); + class_addmethod(serial_bird_class,(t_method) serial_bird_mode,gensym("mode"),A_SYMBOL,NULL); +} + + diff --git a/control/serial_ms.c b/control/serial_ms.c index 723b8bf..b012fdf 100755 --- a/control/serial_ms.c +++ b/control/serial_ms.c @@ -1,120 +1,120 @@ -/* (C) Guenter Geiger */ - - -#include - - -static t_class *serial_ms_class; - - -typedef struct _serial_ms -{ - t_object x_obj; - char x_c[4]; - t_int x_count; - t_int x_posx; - t_int x_posy; - t_outlet *x_out2; -} t_serial_ms; - - -static void serial_ms_reset( t_serial_ms* x) -{ - x->x_posx=0; - x->x_posy=0; - x->x_count = 0; - outlet_float(x->x_obj.ob_outlet, x->x_posx); - outlet_float(x->x_out2, x->x_posy); -} - -static void serial_ms_init( t_serial_ms* x) -{ - t_atom cmd[8]; - - SETFLOAT(cmd,0.); - SETSYMBOL(cmd+1,gensym("CLOCAL")); - SETSYMBOL(cmd+2,gensym("CREAD")); - SETSYMBOL(cmd+3,gensym("CS7")); -/* SETSYMBOL(cmd+4,gensym("HUPCL")); */ - outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd); - - SETFLOAT(cmd,0.); - SETSYMBOL(cmd+1,gensym("IGNBRK")); - SETSYMBOL(cmd+2,gensym("IGNPAR")); - outlet_anything(x->x_out2,gensym("setinput"),3,cmd); - - SETFLOAT(cmd,0.); - SETFLOAT(cmd+1,1.); - outlet_anything(x->x_out2,gensym("vtime"),2,cmd); - - SETFLOAT(cmd,1200.); - outlet_anything(x->x_out2,gensym("speed"),1,cmd); - - SETSYMBOL(cmd,gensym("*n")); - outlet_anything(x->x_out2,gensym("send"),1,cmd); - - - SETSYMBOL(cmd,gensym("N")); - outlet_anything(x->x_out2,gensym("send"),1,cmd); - - -} - - - -static void serial_ms_float( t_serial_ms* x,t_floatarg f) -{ - int dx,dy; - t_atom at[2]; - - x->x_c[x->x_count] = (char) f; - - x->x_count = (++x->x_count)%3; - - if (x->x_count==2) { - dx= (signed char)(((x->x_c[0] & 0x03) << 6) | - (x->x_c[1] & 0x3F)); - dy= (signed char)(((x->x_c[0] & 0x0C) << 4) | - (x->x_c[2] & 0x3F)); - x->x_posx += dx; - x->x_posy += dy; -/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ - - SETFLOAT(at,x->x_posx); - SETFLOAT(at+1,x->x_posy); - outlet_list(x->x_obj.ob_outlet,&s_list, 2, at); - } - - -} - - -static void *serial_ms_new(t_symbol *s) -{ - t_serial_ms *x = (t_serial_ms *)pd_new(serial_ms_class); - - x->x_count = 0; - x->x_posx = 0; - x->x_posy = 0; - - - outlet_new(&x->x_obj, &s_float); - x->x_out2 = outlet_new(&x->x_obj, &s_float); - - return x; -} - - -void serial_ms_setup(void) -{ - serial_ms_class = class_new(gensym("serial_ms"), (t_newmethod)serial_ms_new, - NULL, - sizeof(t_serial_ms), 0,A_DEFSYM,0); - class_addfloat(serial_ms_class,serial_ms_float); - class_addmethod(serial_ms_class,(t_method) serial_ms_reset,gensym("reset"),0); - class_addmethod(serial_ms_class, (t_method)serial_ms_init, gensym("init"),0); - - -} - - +/* (C) Guenter Geiger */ + + +#include + + +static t_class *serial_ms_class; + + +typedef struct _serial_ms +{ + t_object x_obj; + char x_c[4]; + t_int x_count; + t_int x_posx; + t_int x_posy; + t_outlet *x_out2; +} t_serial_ms; + + +static void serial_ms_reset( t_serial_ms* x) +{ + x->x_posx=0; + x->x_posy=0; + x->x_count = 0; + outlet_float(x->x_obj.ob_outlet, x->x_posx); + outlet_float(x->x_out2, x->x_posy); +} + +static void serial_ms_init( t_serial_ms* x) +{ + t_atom cmd[8]; + + SETFLOAT(cmd,0.); + SETSYMBOL(cmd+1,gensym("CLOCAL")); + SETSYMBOL(cmd+2,gensym("CREAD")); + SETSYMBOL(cmd+3,gensym("CS7")); +/* SETSYMBOL(cmd+4,gensym("HUPCL")); */ + outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd); + + SETFLOAT(cmd,0.); + SETSYMBOL(cmd+1,gensym("IGNBRK")); + SETSYMBOL(cmd+2,gensym("IGNPAR")); + outlet_anything(x->x_out2,gensym("setinput"),3,cmd); + + SETFLOAT(cmd,0.); + SETFLOAT(cmd+1,1.); + outlet_anything(x->x_out2,gensym("vtime"),2,cmd); + + SETFLOAT(cmd,1200.); + outlet_anything(x->x_out2,gensym("speed"),1,cmd); + + SETSYMBOL(cmd,gensym("*n")); + outlet_anything(x->x_out2,gensym("send"),1,cmd); + + + SETSYMBOL(cmd,gensym("N")); + outlet_anything(x->x_out2,gensym("send"),1,cmd); + + +} + + + +static void serial_ms_float( t_serial_ms* x,t_floatarg f) +{ + int dx,dy; + t_atom at[2]; + + x->x_c[x->x_count] = (char) f; + + x->x_count = (++x->x_count)%3; + + if (x->x_count==2) { + dx= (signed char)(((x->x_c[0] & 0x03) << 6) | + (x->x_c[1] & 0x3F)); + dy= (signed char)(((x->x_c[0] & 0x0C) << 4) | + (x->x_c[2] & 0x3F)); + x->x_posx += dx; + x->x_posy += dy; +/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ + + SETFLOAT(at,x->x_posx); + SETFLOAT(at+1,x->x_posy); + outlet_list(x->x_obj.ob_outlet,&s_list, 2, at); + } + + +} + + +static void *serial_ms_new(t_symbol *s) +{ + t_serial_ms *x = (t_serial_ms *)pd_new(serial_ms_class); + + x->x_count = 0; + x->x_posx = 0; + x->x_posy = 0; + + + outlet_new(&x->x_obj, &s_float); + x->x_out2 = outlet_new(&x->x_obj, &s_float); + + return x; +} + + +void serial_ms_setup(void) +{ + serial_ms_class = class_new(gensym("serial_ms"), (t_newmethod)serial_ms_new, + NULL, + sizeof(t_serial_ms), 0,A_DEFSYM,0); + class_addfloat(serial_ms_class,serial_ms_float); + class_addmethod(serial_ms_class,(t_method) serial_ms_reset,gensym("reset"),0); + class_addmethod(serial_ms_class, (t_method)serial_ms_init, gensym("init"),0); + + +} + + diff --git a/control/serial_mt.c b/control/serial_mt.c index ed8a0ed..02a1aac 100755 --- a/control/serial_mt.c +++ b/control/serial_mt.c @@ -1,77 +1,77 @@ -/* (C) Guenter Geiger */ - - -#include - - -static t_class *serial_mt_class; - - -typedef struct _serial_mt -{ - t_object x_obj; - char x_c[4]; - t_int x_count; - t_int x_posx; - t_int x_posy; - t_outlet *x_out2; -} t_serial_mt; - - -static void serial_mt_reset( t_serial_mt* x) -{ - x->x_posx=0; - x->x_posy=0; - x->x_count = 0; -} - -static void serial_mt_float( t_serial_mt* x,t_floatarg f) -{ - int dx,dy; - - x->x_c[x->x_count] = (char) f; - - x->x_count = (++x->x_count)%3; - - if (x->x_count==2) { - dx= (signed char)(((x->x_c[0] & 0x03) << 6) | - (x->x_c[1] & 0x3F)); - dy= (signed char)(((x->x_c[0] & 0x0C) << 4) | - (x->x_c[2] & 0x3F)); - x->x_posx += dx; - x->x_posy += dy; -/* post("posx %d, posy %d",x->x_posx,x->x_posy); */ - outlet_float(x->x_obj.ob_outlet, x->x_posx); - outlet_float(x->x_out2, x->x_posy); - } - - -} - - -static void *serial_mt_new(t_symbol *s) -{ - t_serial_mt *x = (t_serial_mt *)pd_new(serial_mt_class); - - x->x_count = 0; - x->x_posx = 0; - x->x_posy = 0; - - - outlet_new(&x->x_obj, &s_float); - x->x_out2 = outlet_new(&x->x_obj, &s_float); - - return x; -} - - -void serial_mt_setup(void) -{ - serial_mt_class = class_new(gensym("serial_mt"), (t_newmethod)serial_mt_new, - NULL, - sizeof(t_serial_mt), 0,A_DEFSYM,0); - class_addfloat(serial_mt_class,serial_mt_float); - class_addmethod(serial_mt_class,(t_method) serial_mt_reset,gensym("reset"),0); -} - - +/* (C) Guenter Geiger */ + + +#include + + +static t_class *serial_mt_class; + + +typedef struct _serial_mt +{ + t_object x_obj; + char x_c[4]; + t_int x_count; + t_int x_posx; + t_int x_posy; + t_outlet *x_out2; +} t_serial_mt; + + +static void serial_mt_reset( t_serial_mt* x) +{ + x->x_posx=0; + x->x_posy=0; + x->x_count = 0; +} + +static void serial_mt_float( t_serial_mt* x,t_floatarg f) +{ + int dx,dy; + + x->x_c[x->x_count] = (char) f; + + x->x_count = (++x->x_count)%3; + + if (x->x_count==2) { + dx= (signed char)(((x->x_c[0] & 0x03) << 6) | + (x->x_c[1] & 0x3F)); + dy= (signed char)(((x->x_c[0] & 0x0C) << 4) | + (x->x_c[2] & 0x3F)); + x->x_posx += dx; + x->x_posy += dy; +/* post("posx %d, posy %d",x->x_posx,x->x_posy); */ + outlet_float(x->x_obj.ob_outlet, x->x_posx); + outlet_float(x->x_out2, x->x_posy); + } + + +} + + +static void *serial_mt_new(t_symbol *s) +{ + t_serial_mt *x = (t_serial_mt *)pd_new(serial_mt_class); + + x->x_count = 0; + x->x_posx = 0; + x->x_posy = 0; + + + outlet_new(&x->x_obj, &s_float); + x->x_out2 = outlet_new(&x->x_obj, &s_float); + + return x; +} + + +void serial_mt_setup(void) +{ + serial_mt_class = class_new(gensym("serial_mt"), (t_newmethod)serial_mt_new, + NULL, + sizeof(t_serial_mt), 0,A_DEFSYM,0); + class_addfloat(serial_mt_class,serial_mt_float); + class_addmethod(serial_mt_class,(t_method) serial_mt_reset,gensym("reset"),0); +} + + diff --git a/control/serialize.c b/control/serialize.c index d288ec4..961a32d 100755 --- a/control/serialize.c +++ b/control/serialize.c @@ -1,58 +1,58 @@ -/* (C) Guenter Geiger */ - - -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -/* ------------------------ serialize ----------------------------- */ - -#define MAX_ELEMENTS 256 - -static t_class *serialize_class; - - -typedef struct _serialize -{ - t_object x_obj; - t_atom x_abuf[MAX_ELEMENTS]; - t_int x_count; - t_float x_elements; -} t_serialize; - - -void serialize_float(t_serialize *x,t_floatarg f) -{ - SETFLOAT(&x->x_abuf[x->x_count],f); - x->x_count++; - - if (x->x_count == x->x_elements) { - outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf); - x->x_count = 0; - } -} - - -static void *serialize_new(t_floatarg f) -{ - t_serialize *x = (t_serialize *)pd_new(serialize_class); - outlet_new(&x->x_obj,&s_float); - x->x_elements = f; - x->x_count=0; - if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1; - floatinlet_new(&x->x_obj, &x->x_elements); - return (x); -} - - - -void serialize_setup(void) -{ - serialize_class = class_new(gensym("serialize"), (t_newmethod)serialize_new, 0, - sizeof(t_serialize),0, A_DEFFLOAT,0); - class_addfloat(serialize_class,serialize_float); -} - - +/* (C) Guenter Geiger */ + + +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ serialize ----------------------------- */ + +#define MAX_ELEMENTS 256 + +static t_class *serialize_class; + + +typedef struct _serialize +{ + t_object x_obj; + t_atom x_abuf[MAX_ELEMENTS]; + t_int x_count; + t_float x_elements; +} t_serialize; + + +void serialize_float(t_serialize *x,t_floatarg f) +{ + SETFLOAT(&x->x_abuf[x->x_count],f); + x->x_count++; + + if (x->x_count == x->x_elements) { + outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf); + x->x_count = 0; + } +} + + +static void *serialize_new(t_floatarg f) +{ + t_serialize *x = (t_serialize *)pd_new(serialize_class); + outlet_new(&x->x_obj,&s_float); + x->x_elements = f; + x->x_count=0; + if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1; + floatinlet_new(&x->x_obj, &x->x_elements); + return (x); +} + + + +void serialize_setup(void) +{ + serialize_class = class_new(gensym("serialize"), (t_newmethod)serialize_new, 0, + sizeof(t_serialize),0, A_DEFFLOAT,0); + class_addfloat(serialize_class,serialize_float); +} + + diff --git a/control/shell.c b/control/shell.c index 78e6e03..ad989be 100755 --- a/control/shell.c +++ b/control/shell.c @@ -1,312 +1,312 @@ -/* (C) Guenter Geiger */ - -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -void sys_rmpollfn(int fd); -void sys_addpollfn(int fd, void* fn, void *ptr); - -/* ------------------------ shell ----------------------------- */ - -#define INBUFSIZE 1024 - -static t_class *shell_class; - - -static void drop_priority(void) -{ -#ifdef _POSIX_PRIORITY_SCHEDULING - struct sched_param par; - int p1 ,p2, p3; - par.sched_priority = 0; - sched_setscheduler(0,SCHED_OTHER,&par); -#endif -} - - -typedef struct _shell -{ - t_object x_obj; - int x_echo; - char *sr_inbuf; - int sr_inhead; - int sr_intail; - void* x_binbuf; - int fdpipe[2]; - int fdinpipe[2]; - int pid; - int x_del; - t_outlet* x_done; - t_clock* x_clock; -} t_shell; - -static int shell_pid; - - -void shell_cleanup(t_shell* x) -{ - sys_rmpollfn(x->fdpipe[0]); - - if (x->fdpipe[0]>0) close(x->fdpipe[0]); - if (x->fdpipe[1]>0) close(x->fdpipe[1]); - if (x->fdinpipe[0]>0) close(x->fdinpipe[0]); - if (x->fdinpipe[1]>0) close(x->fdinpipe[1]); - - x->fdpipe[0] = -1; - x->fdpipe[1] = -1; - x->fdinpipe[0] = -1; - x->fdinpipe[1] = -1; - clock_unset(x->x_clock); -} - -void shell_check(t_shell* x) -{ - int ret; - int status; - ret = waitpid(x->pid,&status,WNOHANG); - if (ret == x->pid) { - shell_cleanup(x); - if (WIFEXITED(status)) { - outlet_float(x->x_done,WEXITSTATUS(status)); - } - else outlet_float(x->x_done,0); - } - else { - if (x->x_del < 100) x->x_del+=2; /* increment poll times */ - clock_delay(x->x_clock,x->x_del); - } -} - - -void shell_bang(t_shell *x) -{ - post("bang"); -} - -/* snippet from pd's code */ -static void shell_doit(void *z, t_binbuf *b) -{ - t_shell *x = (t_shell *)z; - int msg, natom = binbuf_getnatom(b); - t_atom *at = binbuf_getvec(b); - - for (msg = 0; msg < natom;) - { - int emsg; - for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA - && at[emsg].a_type != A_SEMI; emsg++) - ; - if (emsg > msg) - { - int i; - for (i = msg; i < emsg; i++) - if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) - { - pd_error(x, "netreceive: got dollar sign in message"); - goto nodice; - } - if (at[msg].a_type == A_FLOAT) - { - if (emsg > msg + 1) - outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg); - else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float); - } - else if (at[msg].a_type == A_SYMBOL) - outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol, - emsg-msg-1, at + msg + 1); - } - nodice: - msg = emsg + 1; - } -} - - -void shell_read(t_shell *x, int fd) -{ - char buf[INBUFSIZE]; - t_binbuf* bbuf = binbuf_new(); - int i; - int readto = - (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1); - int ret; - - ret = read(fd, buf,INBUFSIZE-1); - buf[ret] = '\0'; - - for (i=0;ifdpipe[0] = -1; - close(fd); - return; - } - else if (ret == 0) - { - post("EOF on socket %d\n", fd); - sys_rmpollfn(fd); - x->fdpipe[0] = -1; - close(fd); - return; - } - else - { - int natom; - t_atom *at; - binbuf_text(bbuf, buf, strlen(buf)); - - natom = binbuf_getnatom(bbuf); - at = binbuf_getvec(bbuf); - shell_doit(x,bbuf); - } - binbuf_free(bbuf); -} - - -static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at) -{ - int i; - char tmp[MAXPDSTRING]; - int size = 0; - - if (x->fdinpipe[0] == -1) return; /* nothing to send to */ - - for (i=0;ifdinpipe[0],tmp,strlen(tmp)); -} - -static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at) -{ - int i; - char* argv[20]; - t_symbol* sym; - - if (!strcmp(s->s_name,"send")) { - post("send"); - shell_send(x,s,ac,at); - return; - } - - argv[0] = s->s_name; - - if (x->fdpipe[0] != -1) { - post("shell: old process still running"); - kill(x->pid,SIGKILL); - shell_cleanup(x); - } - - - if (pipe(x->fdpipe) < 0) { - error("unable to create pipe"); - return; - } - - if (pipe(x->fdinpipe) < 0) { - error("unable to create input pipe"); - return; - } - - - sys_addpollfn(x->fdpipe[0],shell_read,x); - - if (!(x->pid = fork())) { - int status; - char* cmd = getbytes(1024); - char* tcmd = getbytes(1024); - strcpy(cmd,s->s_name); - -#if 0 - for (i=1;i<=ac;i++) { - argv[i] = getbytes(255); - atom_string(at,argv[i],255); -/* post("argument %s",argv[i]); */ - at++; - } - argv[i] = 0; -#endif - for (i=1;i<=ac;i++) { - atom_string(at,tcmd,255); - strcat(cmd," "); - strcat(cmd,tcmd); - at++; - } - - - /* reassign stdout */ - dup2(x->fdpipe[1],1); - dup2(x->fdinpipe[1],0); - - /* drop privileges */ - drop_priority(); - seteuid(getuid()); /* lose setuid priveliges */ - - post("executing %s",cmd); - system(cmd); -// execvp(s->s_name,argv); - exit(0); - } - x->x_del = 4; - clock_delay(x->x_clock,x->x_del); - - if (x->x_echo) - outlet_anything(x->x_obj.ob_outlet, s, ac, at); -} - - - -void shell_free(t_shell* x) -{ - binbuf_free(x->x_binbuf); -} - -static void *shell_new(void) -{ - t_shell *x = (t_shell *)pd_new(shell_class); - - x->x_echo = 0; - x->fdpipe[0] = -1; - x->fdpipe[1] = -1; - x->fdinpipe[0] = -1; - x->fdinpipe[1] = -1; - - x->sr_inhead = x->sr_intail = 0; - if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");; - - x->x_binbuf = binbuf_new(); - - outlet_new(&x->x_obj, &s_list); - x->x_done = outlet_new(&x->x_obj, &s_bang); - x->x_clock = clock_new(x, (t_method) shell_check); - return (x); -} - -void shell_setup(void) -{ - shell_class = class_new(gensym("shell"), (t_newmethod)shell_new, - (t_method)shell_free,sizeof(t_shell), 0,0); - class_addbang(shell_class,shell_bang); - class_addanything(shell_class, shell_anything); -} - - +/* (C) Guenter Geiger */ + +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +void sys_rmpollfn(int fd); +void sys_addpollfn(int fd, void* fn, void *ptr); + +/* ------------------------ shell ----------------------------- */ + +#define INBUFSIZE 1024 + +static t_class *shell_class; + + +static void drop_priority(void) +{ +#ifdef _POSIX_PRIORITY_SCHEDULING + struct sched_param par; + int p1 ,p2, p3; + par.sched_priority = 0; + sched_setscheduler(0,SCHED_OTHER,&par); +#endif +} + + +typedef struct _shell +{ + t_object x_obj; + int x_echo; + char *sr_inbuf; + int sr_inhead; + int sr_intail; + void* x_binbuf; + int fdpipe[2]; + int fdinpipe[2]; + int pid; + int x_del; + t_outlet* x_done; + t_clock* x_clock; +} t_shell; + +static int shell_pid; + + +void shell_cleanup(t_shell* x) +{ + sys_rmpollfn(x->fdpipe[0]); + + if (x->fdpipe[0]>0) close(x->fdpipe[0]); + if (x->fdpipe[1]>0) close(x->fdpipe[1]); + if (x->fdinpipe[0]>0) close(x->fdinpipe[0]); + if (x->fdinpipe[1]>0) close(x->fdinpipe[1]); + + x->fdpipe[0] = -1; + x->fdpipe[1] = -1; + x->fdinpipe[0] = -1; + x->fdinpipe[1] = -1; + clock_unset(x->x_clock); +} + +void shell_check(t_shell* x) +{ + int ret; + int status; + ret = waitpid(x->pid,&status,WNOHANG); + if (ret == x->pid) { + shell_cleanup(x); + if (WIFEXITED(status)) { + outlet_float(x->x_done,WEXITSTATUS(status)); + } + else outlet_float(x->x_done,0); + } + else { + if (x->x_del < 100) x->x_del+=2; /* increment poll times */ + clock_delay(x->x_clock,x->x_del); + } +} + + +void shell_bang(t_shell *x) +{ + post("bang"); +} + +/* snippet from pd's code */ +static void shell_doit(void *z, t_binbuf *b) +{ + t_shell *x = (t_shell *)z; + int msg, natom = binbuf_getnatom(b); + t_atom *at = binbuf_getvec(b); + + for (msg = 0; msg < natom;) + { + int emsg; + for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA + && at[emsg].a_type != A_SEMI; emsg++) + ; + if (emsg > msg) + { + int i; + for (i = msg; i < emsg; i++) + if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) + { + pd_error(x, "netreceive: got dollar sign in message"); + goto nodice; + } + if (at[msg].a_type == A_FLOAT) + { + if (emsg > msg + 1) + outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg); + else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float); + } + else if (at[msg].a_type == A_SYMBOL) + outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol, + emsg-msg-1, at + msg + 1); + } + nodice: + msg = emsg + 1; + } +} + + +void shell_read(t_shell *x, int fd) +{ + char buf[INBUFSIZE]; + t_binbuf* bbuf = binbuf_new(); + int i; + int readto = + (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1); + int ret; + + ret = read(fd, buf,INBUFSIZE-1); + buf[ret] = '\0'; + + for (i=0;ifdpipe[0] = -1; + close(fd); + return; + } + else if (ret == 0) + { + post("EOF on socket %d\n", fd); + sys_rmpollfn(fd); + x->fdpipe[0] = -1; + close(fd); + return; + } + else + { + int natom; + t_atom *at; + binbuf_text(bbuf, buf, strlen(buf)); + + natom = binbuf_getnatom(bbuf); + at = binbuf_getvec(bbuf); + shell_doit(x,bbuf); + } + binbuf_free(bbuf); +} + + +static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at) +{ + int i; + char tmp[MAXPDSTRING]; + int size = 0; + + if (x->fdinpipe[0] == -1) return; /* nothing to send to */ + + for (i=0;ifdinpipe[0],tmp,strlen(tmp)); +} + +static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at) +{ + int i; + char* argv[20]; + t_symbol* sym; + + if (!strcmp(s->s_name,"send")) { + post("send"); + shell_send(x,s,ac,at); + return; + } + + argv[0] = s->s_name; + + if (x->fdpipe[0] != -1) { + post("shell: old process still running"); + kill(x->pid,SIGKILL); + shell_cleanup(x); + } + + + if (pipe(x->fdpipe) < 0) { + error("unable to create pipe"); + return; + } + + if (pipe(x->fdinpipe) < 0) { + error("unable to create input pipe"); + return; + } + + + sys_addpollfn(x->fdpipe[0],shell_read,x); + + if (!(x->pid = fork())) { + int status; + char* cmd = getbytes(1024); + char* tcmd = getbytes(1024); + strcpy(cmd,s->s_name); + +#if 0 + for (i=1;i<=ac;i++) { + argv[i] = getbytes(255); + atom_string(at,argv[i],255); +/* post("argument %s",argv[i]); */ + at++; + } + argv[i] = 0; +#endif + for (i=1;i<=ac;i++) { + atom_string(at,tcmd,255); + strcat(cmd," "); + strcat(cmd,tcmd); + at++; + } + + + /* reassign stdout */ + dup2(x->fdpipe[1],1); + dup2(x->fdinpipe[1],0); + + /* drop privileges */ + drop_priority(); + seteuid(getuid()); /* lose setuid priveliges */ + + post("executing %s",cmd); + system(cmd); +// execvp(s->s_name,argv); + exit(0); + } + x->x_del = 4; + clock_delay(x->x_clock,x->x_del); + + if (x->x_echo) + outlet_anything(x->x_obj.ob_outlet, s, ac, at); +} + + + +void shell_free(t_shell* x) +{ + binbuf_free(x->x_binbuf); +} + +static void *shell_new(void) +{ + t_shell *x = (t_shell *)pd_new(shell_class); + + x->x_echo = 0; + x->fdpipe[0] = -1; + x->fdpipe[1] = -1; + x->fdinpipe[0] = -1; + x->fdinpipe[1] = -1; + + x->sr_inhead = x->sr_intail = 0; + if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");; + + x->x_binbuf = binbuf_new(); + + outlet_new(&x->x_obj, &s_list); + x->x_done = outlet_new(&x->x_obj, &s_bang); + x->x_clock = clock_new(x, (t_method) shell_check); + return (x); +} + +void shell_setup(void) +{ + shell_class = class_new(gensym("shell"), (t_newmethod)shell_new, + (t_method)shell_free,sizeof(t_shell), 0,0); + class_addbang(shell_class,shell_bang); + class_addanything(shell_class, shell_anything); +} + + diff --git a/control/sinh.c b/control/sinh.c index 609ef3f..915ee5f 100755 --- a/control/sinh.c +++ b/control/sinh.c @@ -1,54 +1,54 @@ -/* (C) Guenter Geiger */ - - -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -#include - - - -/* ------------------------ sinh ----------------------------- */ - -static t_class *sinh_class; - - -typedef struct _sinh -{ - t_object x_obj; -} t_sinh; - - -void sinh_bang(t_sinh *x) -{ - post("bang"); -} - - -void sinh_float(t_sinh *x,t_floatarg f) -{ - - outlet_float(x->x_obj.ob_outlet,sinh(f)); -} - - -static void *sinh_new() -{ - t_sinh *x = (t_sinh *)pd_new(sinh_class); - - outlet_new(&x->x_obj,&s_float); - return (x); -} - -void sinh_setup(void) -{ - sinh_class = class_new(gensym("sinh"), (t_newmethod)sinh_new, 0, - sizeof(t_sinh), 0,0); - class_addbang(sinh_class,sinh_bang); - class_addfloat(sinh_class,sinh_float); -} - - +/* (C) Guenter Geiger */ + + +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include + + + +/* ------------------------ sinh ----------------------------- */ + +static t_class *sinh_class; + + +typedef struct _sinh +{ + t_object x_obj; +} t_sinh; + + +void sinh_bang(t_sinh *x) +{ + post("bang"); +} + + +void sinh_float(t_sinh *x,t_floatarg f) +{ + + outlet_float(x->x_obj.ob_outlet,sinh(f)); +} + + +static void *sinh_new() +{ + t_sinh *x = (t_sinh *)pd_new(sinh_class); + + outlet_new(&x->x_obj,&s_float); + return (x); +} + +void sinh_setup(void) +{ + sinh_class = class_new(gensym("sinh"), (t_newmethod)sinh_new, 0, + sizeof(t_sinh), 0,0); + class_addbang(sinh_class,sinh_bang); + class_addfloat(sinh_class,sinh_float); +} + + diff --git a/control/sl.c b/control/sl.c index d2284e0..8629947 100755 --- a/control/sl.c +++ b/control/sl.c @@ -1,74 +1,74 @@ -/* (C) Guenter Geiger */ - - -#include -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - - -/* -------------------- lsend ------------------------------ */ - -static t_class *lsend_class; - -typedef struct _lsend -{ - t_object x_obj; - t_symbol *x_sym; -} t_lsend; - -static void lsend_bang(t_lsend *x) -{ - if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing); -} - -static void lsend_float(t_lsend *x, t_float f) -{ - if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f); -} - -static void lsend_symbol(t_lsend *x, t_symbol *s) -{ - if (x->x_sym->s_thing) pd_symbol(x->x_sym->s_thing, s); -} - -static void lsend_pointer(t_lsend *x, t_gpointer *gp) -{ - if (x->x_sym->s_thing) pd_pointer(x->x_sym->s_thing, gp); -} - -static void lsend_list(t_lsend *x, t_symbol *s, int argc, t_atom *argv) -{ - if (x->x_sym->s_thing) pd_list(x->x_sym->s_thing, s, argc, argv); -} - -static void lsend_anything(t_lsend *x, t_symbol *s, int argc, t_atom *argv) -{ - if (x->x_sym->s_thing) typedmess(x->x_sym->s_thing, s, argc, argv); -} - -static void *lsend_new(t_symbol *s) -{ - t_lsend *x = (t_lsend *)pd_new(lsend_class); - char mysym[MAXPDSTRING]; - - sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent()); - x->x_sym = gensym(mysym); - return (x); -} - -void sl_setup(void) -{ - lsend_class = class_new(gensym("sendlocal"), (t_newmethod)lsend_new, 0, - sizeof(t_lsend), 0, A_DEFSYM, 0); - class_addcreator((t_newmethod)lsend_new, gensym("sl"), A_DEFSYM, 0); - class_addbang(lsend_class, lsend_bang); - class_addfloat(lsend_class, lsend_float); - class_addsymbol(lsend_class, lsend_symbol); - class_addpointer(lsend_class, lsend_pointer); - class_addlist(lsend_class, lsend_list); - class_addanything(lsend_class, lsend_anything); - post("Warning: sendlocal (sl) is deprecated, please use \"send $0-var\" instead"); -} +/* (C) Guenter Geiger */ + + +#include +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + + +/* -------------------- lsend ------------------------------ */ + +static t_class *lsend_class; + +typedef struct _lsend +{ + t_object x_obj; + t_symbol *x_sym; +} t_lsend; + +static void lsend_bang(t_lsend *x) +{ + if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing); +} + +static void lsend_float(t_lsend *x, t_float f) +{ + if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f); +} + +static void lsend_symbol(t_lsend *x, t_symbol *s) +{ + if (x->x_sym->s_thing) pd_symbol(x->x_sym->s_thing, s); +} + +static void lsend_pointer(t_lsend *x, t_gpointer *gp) +{ + if (x->x_sym->s_thing) pd_pointer(x->x_sym->s_thing, gp); +} + +static void lsend_list(t_lsend *x, t_symbol *s, int argc, t_atom *argv) +{ + if (x->x_sym->s_thing) pd_list(x->x_sym->s_thing, s, argc, argv); +} + +static void lsend_anything(t_lsend *x, t_symbol *s, int argc, t_atom *argv) +{ + if (x->x_sym->s_thing) typedmess(x->x_sym->s_thing, s, argc, argv); +} + +static void *lsend_new(t_symbol *s) +{ + t_lsend *x = (t_lsend *)pd_new(lsend_class); + char mysym[MAXPDSTRING]; + + sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent()); + x->x_sym = gensym(mysym); + return (x); +} + +void sl_setup(void) +{ + lsend_class = class_new(gensym("sendlocal"), (t_newmethod)lsend_new, 0, + sizeof(t_lsend), 0, A_DEFSYM, 0); + class_addcreator((t_newmethod)lsend_new, gensym("sl"), A_DEFSYM, 0); + class_addbang(lsend_class, lsend_bang); + class_addfloat(lsend_class, lsend_float); + class_addsymbol(lsend_class, lsend_symbol); + class_addpointer(lsend_class, lsend_pointer); + class_addlist(lsend_class, lsend_list); + class_addanything(lsend_class, lsend_anything); + post("Warning: sendlocal (sl) is deprecated, please use \"send $0-var\" instead"); +} diff --git a/control/stripdir.c b/control/stripdir.c index 10ba19b..9202f19 100755 --- a/control/stripdir.c +++ b/control/stripdir.c @@ -1,48 +1,48 @@ -/* (C) Guenter Geiger */ - - -#include -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -/* ------------------------ stripdir ----------------------------- */ - -static t_class *stripdir_class; - - -typedef struct _stripdir -{ - t_object x_obj; -} t_stripdir; - - -void stripdir_symbol(t_stripdir *x,t_symbol* s) -{ - int len = strlen(s->s_name); - - while (len--) - if (*(s->s_name + len) == '/') { - outlet_symbol(x->x_obj.ob_outlet,gensym(s->s_name + len + 1)); - break; - } - -} - -static void *stripdir_new() -{ - t_stripdir *x = (t_stripdir *)pd_new(stripdir_class); - outlet_new(&x->x_obj, &s_float); - return (x); -} - -void stripdir_setup(void) -{ - stripdir_class = class_new(gensym("stripdir"), (t_newmethod)stripdir_new, 0, - sizeof(t_stripdir), 0,0); - class_addsymbol(stripdir_class,stripdir_symbol); -} - - +/* (C) Guenter Geiger */ + + +#include +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ stripdir ----------------------------- */ + +static t_class *stripdir_class; + + +typedef struct _stripdir +{ + t_object x_obj; +} t_stripdir; + + +void stripdir_symbol(t_stripdir *x,t_symbol* s) +{ + int len = strlen(s->s_name); + + while (len--) + if (*(s->s_name + len) == '/') { + outlet_symbol(x->x_obj.ob_outlet,gensym(s->s_name + len + 1)); + break; + } + +} + +static void *stripdir_new() +{ + t_stripdir *x = (t_stripdir *)pd_new(stripdir_class); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +void stripdir_setup(void) +{ + stripdir_class = class_new(gensym("stripdir"), (t_newmethod)stripdir_new, 0, + sizeof(t_stripdir), 0,0); + class_addsymbol(stripdir_class,stripdir_symbol); +} + + diff --git a/control/unserialize.c b/control/unserialize.c index 6133ead..a061a25 100755 --- a/control/unserialize.c +++ b/control/unserialize.c @@ -1,57 +1,57 @@ -/* (C) Guenter Geiger */ - - -#include -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -/* ------------------------ unserialize ----------------------------- */ - -#define MAX_ELEMENTS 256 - -static t_class *unserialize_class; - - -typedef struct _unserialize -{ - t_object x_obj; - t_atom x_abuf[MAX_ELEMENTS]; - t_int x_count; - t_int x_elements; -} t_unserialize; - - -void unserialize_float(t_unserialize *x,t_floatarg f) -{ - SETFLOAT(&x->x_abuf[x->x_count],f); - x->x_count++; - - if (x->x_count == x->x_elements) { - outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf); - x->x_count = 0; - } -} - - -static void *unserialize_new(t_floatarg f) -{ - t_unserialize *x = (t_unserialize *)pd_new(unserialize_class); - outlet_new(&x->x_obj,&s_float); - x->x_elements = f; - x->x_count=0; - if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1; - return (x); -} - - - -void unserialize_setup(void) -{ - unserialize_class = class_new(gensym("unserialize"), (t_newmethod)unserialize_new, - 0,sizeof(t_unserialize),0, A_DEFFLOAT,0); - class_addfloat(unserialize_class,unserialize_float); -} - - +/* (C) Guenter Geiger */ + + +#include +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ unserialize ----------------------------- */ + +#define MAX_ELEMENTS 256 + +static t_class *unserialize_class; + + +typedef struct _unserialize +{ + t_object x_obj; + t_atom x_abuf[MAX_ELEMENTS]; + t_int x_count; + t_int x_elements; +} t_unserialize; + + +void unserialize_float(t_unserialize *x,t_floatarg f) +{ + SETFLOAT(&x->x_abuf[x->x_count],f); + x->x_count++; + + if (x->x_count == x->x_elements) { + outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf); + x->x_count = 0; + } +} + + +static void *unserialize_new(t_floatarg f) +{ + t_unserialize *x = (t_unserialize *)pd_new(unserialize_class); + outlet_new(&x->x_obj,&s_float); + x->x_elements = f; + x->x_count=0; + if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1; + return (x); +} + + + +void unserialize_setup(void) +{ + unserialize_class = class_new(gensym("unserialize"), (t_newmethod)unserialize_new, + 0,sizeof(t_unserialize),0, A_DEFFLOAT,0); + class_addfloat(unserialize_class,unserialize_float); +} + + diff --git a/control/unwonk.c b/control/unwonk.c index e44ef10..2c1fa9e 100755 --- a/control/unwonk.c +++ b/control/unwonk.c @@ -1,119 +1,119 @@ -/* (C) Guenter Geiger */ - - -#include - - -/* -------------------------- unwonk ------------------------------ */ - -static t_class *unwonk_class; - -typedef struct unwonkout -{ - t_atomtype u_type; - t_outlet *u_outlet; -} t_unwonkout; - -typedef struct _unwonk -{ - t_object x_obj; - t_int x_n; - t_unwonkout *x_vec; -} t_unwonk; - -static void *unwonk_new(t_symbol *s, int argc, t_atom *argv) -{ - t_unwonk *x = (t_unwonk *)pd_new(unwonk_class); - t_atom defarg[2], *ap; - t_unwonkout *u; - int i; - if (!argc) - { - argv = defarg; - argc = 2; - SETFLOAT(&defarg[0], 0); - SETFLOAT(&defarg[1], 0); - } - - x->x_n = argc + 1; - x->x_vec = (t_unwonkout *)getbytes(x->x_n * sizeof(*x->x_vec)); - - for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++) - { - t_atomtype type = ap->a_type; - if (type == A_SYMBOL) - { - char c = *ap->a_w.w_symbol->s_name; - if (c == 's') - { - u->u_type = A_SYMBOL; - u->u_outlet = outlet_new(&x->x_obj, &s_symbol); - } - else if (c == 'p') - { - u->u_type = A_POINTER; - u->u_outlet = outlet_new(&x->x_obj, &s_pointer); - } - else - { - if (c != 'f') error("unwonk: %s: bad type", - ap->a_w.w_symbol->s_name); - u->u_type = A_FLOAT; - u->u_outlet = outlet_new(&x->x_obj, &s_float); - } - } - else - { - u->u_type = A_FLOAT; - u->u_outlet = outlet_new(&x->x_obj, &s_float); - } - } - - u->u_type = A_GIMME; - u->u_outlet = outlet_new(&x->x_obj, &s_list); - - return (x); -} - -static void unwonk_list(t_unwonk *x, t_symbol *s, int argc, t_atom *argv) -{ - t_atom *ap; - t_unwonkout *u; - int i; - int margc = argc; - - - if (argc > x->x_n - 1) margc = x->x_n - 1; - - if (argc - margc > 0) { - ap = argv + margc; - u = x->x_vec + margc; - outlet_list(u->u_outlet,0,argc - margc, ap); - } - - for (i = margc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;) - { - t_atomtype type = u->u_type; - if (type != ap->a_type) - error("unwonk: type mismatch"); - else if (type == A_FLOAT) - outlet_float(u->u_outlet, ap->a_w.w_float); - else if (type == A_SYMBOL) - outlet_symbol(u->u_outlet, ap->a_w.w_symbol); - else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer); - } - - -} - -static void unwonk_free(t_unwonk *x) -{ - freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); -} - -void unwonk_setup(void) -{ - unwonk_class = class_new(gensym("unwonk"), (t_newmethod)unwonk_new, - (t_method)unwonk_free, sizeof(t_unwonk), 0, A_GIMME, 0); - class_addlist(unwonk_class, unwonk_list); -} +/* (C) Guenter Geiger */ + + +#include + + +/* -------------------------- unwonk ------------------------------ */ + +static t_class *unwonk_class; + +typedef struct unwonkout +{ + t_atomtype u_type; + t_outlet *u_outlet; +} t_unwonkout; + +typedef struct _unwonk +{ + t_object x_obj; + t_int x_n; + t_unwonkout *x_vec; +} t_unwonk; + +static void *unwonk_new(t_symbol *s, int argc, t_atom *argv) +{ + t_unwonk *x = (t_unwonk *)pd_new(unwonk_class); + t_atom defarg[2], *ap; + t_unwonkout *u; + int i; + if (!argc) + { + argv = defarg; + argc = 2; + SETFLOAT(&defarg[0], 0); + SETFLOAT(&defarg[1], 0); + } + + x->x_n = argc + 1; + x->x_vec = (t_unwonkout *)getbytes(x->x_n * sizeof(*x->x_vec)); + + for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++) + { + t_atomtype type = ap->a_type; + if (type == A_SYMBOL) + { + char c = *ap->a_w.w_symbol->s_name; + if (c == 's') + { + u->u_type = A_SYMBOL; + u->u_outlet = outlet_new(&x->x_obj, &s_symbol); + } + else if (c == 'p') + { + u->u_type = A_POINTER; + u->u_outlet = outlet_new(&x->x_obj, &s_pointer); + } + else + { + if (c != 'f') error("unwonk: %s: bad type", + ap->a_w.w_symbol->s_name); + u->u_type = A_FLOAT; + u->u_outlet = outlet_new(&x->x_obj, &s_float); + } + } + else + { + u->u_type = A_FLOAT; + u->u_outlet = outlet_new(&x->x_obj, &s_float); + } + } + + u->u_type = A_GIMME; + u->u_outlet = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +static void unwonk_list(t_unwonk *x, t_symbol *s, int argc, t_atom *argv) +{ + t_atom *ap; + t_unwonkout *u; + int i; + int margc = argc; + + + if (argc > x->x_n - 1) margc = x->x_n - 1; + + if (argc - margc > 0) { + ap = argv + margc; + u = x->x_vec + margc; + outlet_list(u->u_outlet,0,argc - margc, ap); + } + + for (i = margc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;) + { + t_atomtype type = u->u_type; + if (type != ap->a_type) + error("unwonk: type mismatch"); + else if (type == A_FLOAT) + outlet_float(u->u_outlet, ap->a_w.w_float); + else if (type == A_SYMBOL) + outlet_symbol(u->u_outlet, ap->a_w.w_symbol); + else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer); + } + + +} + +static void unwonk_free(t_unwonk *x) +{ + freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); +} + +void unwonk_setup(void) +{ + unwonk_class = class_new(gensym("unwonk"), (t_newmethod)unwonk_new, + (t_method)unwonk_free, sizeof(t_unwonk), 0, A_GIMME, 0); + class_addlist(unwonk_class, unwonk_list); +} -- cgit v1.2.1