Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27751
Modified Files: Tag: desiredata x_misc.c Log Message: removed [serial] and using PD_PLUSPLUS_FACE
Index: x_misc.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/x_misc.c,v retrieving revision 1.2.8.1.2.3 retrieving revision 1.2.8.1.2.4 diff -C2 -d -r1.2.8.1.2.3 -r1.2.8.1.2.4 *** x_misc.c 20 Dec 2006 09:09:19 -0000 1.2.8.1.2.3 --- x_misc.c 3 Jan 2007 09:23:14 -0000 1.2.8.1.2.4 *************** *** 5,8 **** --- 5,9 ---- /* misc. */
+ #define PD_PLUSPLUS_FACE #include "m_pd.h" #include "s_stuff.h" *************** *** 31,44 **** static t_class *random_class;
! typedef struct _random ! { ! t_object x_obj; t_float x_f; unsigned int x_state; ! } t_random;
! static int makeseed(void) ! { static unsigned int random_nextseed = 1489853723; random_nextseed = random_nextseed * 435898247 + 938284287; --- 32,42 ---- static t_class *random_class;
! struct t_random : t_object { t_float x_f; unsigned int x_state; ! };
! static int makeseed() { static unsigned int random_nextseed = 1489853723; random_nextseed = random_nextseed * 435898247 + 938284287; *************** *** 46,141 **** }
! static void *random_new(t_floatarg f) ! { t_random *x = (t_random *)pd_new(random_class); x->x_f = f; x->x_state = makeseed(); ! floatinlet_new(&x->x_obj, &x->x_f); ! outlet_new(&x->x_obj, &s_float); ! return (x); }
! static void random_bang(t_random *x) ! { ! int n = x->x_f, nval; int range = (n < 1 ? 1 : n); unsigned int randval = x->x_state; x->x_state = randval = randval * 472940017 + 832416023; ! nval = ((double)range) * ((double)randval) ! * (1./4294967296.); ! if (nval >= range) nval = range-1; ! outlet_float(x->x_obj.ob_outlet, nval); }
! static void random_seed(t_random *x, float f, float glob) ! { ! x->x_state = f; ! }
! static void random_setup(void) ! { random_class = class_new(gensym("random"), (t_newmethod)random_new, 0, sizeof(t_random), 0, A_DEFFLOAT, 0); class_addbang(random_class, random_bang); ! class_addmethod(random_class, (t_method)random_seed, ! gensym("seed"), A_FLOAT, 0); }
- /* -------------------------- loadbang ------------------------------ */ static t_class *loadbang_class; ! ! typedef struct _loadbang ! { ! t_object x_obj; ! } t_loadbang; ! ! static void *loadbang_new(void) ! { t_loadbang *x = (t_loadbang *)pd_new(loadbang_class); ! outlet_new(&x->x_obj, &s_bang); ! return (x); } ! ! static void loadbang_loadbang(t_loadbang *x) ! { ! if (!sys_noloadbang) ! outlet_bang(x->x_obj.ob_outlet); } ! ! static void loadbang_setup(void) ! { loadbang_class = class_new(gensym("loadbang"), (t_newmethod)loadbang_new, 0, sizeof(t_loadbang), CLASS_NOINLET, 0); ! class_addmethod(loadbang_class, (t_method)loadbang_loadbang, ! gensym("loadbang"), 0); }
/* ------------- namecanvas (delete this later) --------------------- */ static t_class *namecanvas_class; ! ! typedef struct _namecanvas ! { ! t_object x_obj; t_symbol *x_sym; t_pd *x_owner; ! } t_namecanvas;
! static void *namecanvas_new(t_symbol *s) ! { t_namecanvas *x = (t_namecanvas *)pd_new(namecanvas_class); x->x_owner = (t_pd *)canvas_getcurrent(); x->x_sym = s; if (*s->s_name) pd_bind(x->x_owner, s); ! return (x); }
! static void namecanvas_free(t_namecanvas *x) ! { if (*x->x_sym->s_name) pd_unbind(x->x_owner, x->x_sym); }
! static void namecanvas_setup(void) ! { namecanvas_class = class_new(gensym("namecanvas"), (t_newmethod)namecanvas_new, (t_method)namecanvas_free, --- 44,112 ---- }
! static void *random_new(t_floatarg f) { t_random *x = (t_random *)pd_new(random_class); x->x_f = f; x->x_state = makeseed(); ! floatinlet_new(x,&x->x_f); ! outlet_new(x,&s_float); ! return x; }
! static void random_bang(t_random *x) { ! int n = (int)x->x_f, nval; int range = (n < 1 ? 1 : n); unsigned int randval = x->x_state; x->x_state = randval = randval * 472940017 + 832416023; ! nval = (int)((double)range * (double)randval * (1./4294967296.)); ! if (nval >= range) nval = (int)(range-1); ! outlet_float(x->ob_outlet, nval); }
! static void random_seed(t_random *x, float f, float glob) {x->x_state = (int)f;}
! static void random_setup() { random_class = class_new(gensym("random"), (t_newmethod)random_new, 0, sizeof(t_random), 0, A_DEFFLOAT, 0); class_addbang(random_class, random_bang); ! class_addmethod(random_class, (t_method)random_seed,gensym("seed"), A_FLOAT, 0); }
/* -------------------------- loadbang ------------------------------ */ static t_class *loadbang_class; ! struct t_loadbang : t_object {}; ! static void *loadbang_new() { t_loadbang *x = (t_loadbang *)pd_new(loadbang_class); ! outlet_new(x,&s_bang); ! return x; } ! static void loadbang_loadbang(t_loadbang *x) { ! if (!sys_noloadbang) outlet_bang(x->ob_outlet); } ! static void loadbang_setup() { loadbang_class = class_new(gensym("loadbang"), (t_newmethod)loadbang_new, 0, sizeof(t_loadbang), CLASS_NOINLET, 0); ! class_addmethod(loadbang_class, (t_method)loadbang_loadbang, gensym("loadbang"), 0); }
/* ------------- namecanvas (delete this later) --------------------- */ static t_class *namecanvas_class; ! struct t_namecanvas : t_object { t_symbol *x_sym; t_pd *x_owner; ! };
! static void *namecanvas_new(t_symbol *s) { t_namecanvas *x = (t_namecanvas *)pd_new(namecanvas_class); x->x_owner = (t_pd *)canvas_getcurrent(); x->x_sym = s; if (*s->s_name) pd_bind(x->x_owner, s); ! return x; }
! static void namecanvas_free(t_namecanvas *x) { if (*x->x_sym->s_name) pd_unbind(x->x_owner, x->x_sym); }
! static void namecanvas_setup() { namecanvas_class = class_new(gensym("namecanvas"), (t_newmethod)namecanvas_new, (t_method)namecanvas_free, *************** *** 143,195 **** }
- /* ---------------serial ports (MSW only -- hack) ------------------------- */ - #define MAXSERIAL 100 - - static t_class *serial_class; - - typedef struct _serial - { - t_object x_obj; - int x_portno; - int x_open; - } t_serial; - - static void serial_float(t_serial *x, t_float f) - { - int n = f; - char message[MAXSERIAL * 4 + 100]; - if (!x->x_open) - { - sys_vgui("com%d_open\n", x->x_portno); - x->x_open = 1; - } - sprintf(message, "com%d_send "\%3.3o"\n", x->x_portno, n); - sys_gui(message); - } - - static void *serial_new(t_floatarg fportno) - { - int portno = fportno; - t_serial *x = (t_serial *)pd_new(serial_class); - if (!portno) portno = 1; - x->x_portno = portno; - x->x_open = 0; - return (x); - } - - static void serial_setup(void) - { - serial_class = class_new(gensym("serial"), (t_newmethod)serial_new, 0, - sizeof(t_serial), 0, A_DEFFLOAT, 0); - class_addfloat(serial_class, serial_float); - } - /* -------------------------- cputime ------------------------------ */
static t_class *cputime_class;
! typedef struct _cputime ! { ! t_object x_obj; #ifdef UNISTD struct tms x_setcputime; --- 114,122 ---- }
/* -------------------------- cputime ------------------------------ */
static t_class *cputime_class;
! struct t_cputime : t_object { #ifdef UNISTD struct tms x_setcputime; *************** *** 200,207 **** int x_warned; #endif ! } t_cputime;
! static void cputime_bang(t_cputime *x) ! { #ifdef UNISTD times(&x->x_setcputime); --- 127,133 ---- int x_warned; #endif ! };
! static void cputime_bang(t_cputime *x) { #ifdef UNISTD times(&x->x_setcputime); *************** *** 212,219 **** retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat, (FILETIME *)&x->x_kerneltime, (FILETIME *)&x->x_usertime); ! if (!retval) ! { ! if (!x->x_warned) ! post("cputime is apparently not supported on your platform"); x->x_warned = 1; x->x_kerneltime.QuadPart = 0; --- 138,143 ---- retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat, (FILETIME *)&x->x_kerneltime, (FILETIME *)&x->x_usertime); ! if (!retval) { ! if (!x->x_warned) {error("cputime is apparently not supported on your platform"); return;} x->x_warned = 1; x->x_kerneltime.QuadPart = 0; *************** *** 223,236 **** }
! static void cputime_bang2(t_cputime *x) ! { #ifdef UNISTD float elapsedcpu; struct tms newcputime; times(&newcputime); ! elapsedcpu = 1000 * ( ! newcputime.tms_utime + newcputime.tms_stime - x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / HZ; ! outlet_float(x->x_obj.ob_outlet, elapsedcpu); #endif #ifdef MSW --- 147,158 ---- }
! static void cputime_bang2(t_cputime *x) { #ifdef UNISTD float elapsedcpu; struct tms newcputime; times(&newcputime); ! elapsedcpu = 1000 * (newcputime.tms_utime + newcputime.tms_stime - x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / HZ; ! outlet_float(x->ob_outlet, elapsedcpu); #endif #ifdef MSW *************** *** 239,243 **** LARGE_INTEGER usertime, kerneltime; BOOL retval; - retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat, (FILETIME *)&kerneltime, (FILETIME *)&usertime); --- 161,164 ---- *************** *** 247,271 **** (usertime.QuadPart - x->x_usertime.QuadPart)); else elapsedcpu = 0; ! outlet_float(x->x_obj.ob_outlet, elapsedcpu); #endif }
! static void *cputime_new(void) ! { t_cputime *x = (t_cputime *)pd_new(cputime_class); ! outlet_new(&x->x_obj, gensym("float")); ! ! inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("bang"), gensym("bang2")); #ifdef MSW x->x_warned = 0; #endif cputime_bang(x); ! return (x); }
! static void cputime_setup(void) ! { ! cputime_class = class_new(gensym("cputime"), (t_newmethod)cputime_new, 0, ! sizeof(t_cputime), 0, 0); class_addbang(cputime_class, cputime_bang); class_addmethod(cputime_class, (t_method)cputime_bang2, gensym("bang2"), 0); --- 168,188 ---- (usertime.QuadPart - x->x_usertime.QuadPart)); else elapsedcpu = 0; ! outlet_float(x->ob_outlet, elapsedcpu); #endif }
! static void *cputime_new() { t_cputime *x = (t_cputime *)pd_new(cputime_class); ! outlet_new(x,gensym("float")); ! inlet_new(x,x,gensym("bang"),gensym("bang2")); #ifdef MSW x->x_warned = 0; #endif cputime_bang(x); ! return x; }
! static void cputime_setup() { ! cputime_class = class_new(gensym("cputime"), (t_newmethod)cputime_new, 0, sizeof(t_cputime), 0, 0); class_addbang(cputime_class, cputime_bang); class_addmethod(cputime_class, (t_method)cputime_bang2, gensym("bang2"), 0); *************** *** 276,312 **** static t_class *realtime_class;
! typedef struct _realtime ! { ! t_object x_obj; double x_setrealtime; ! } t_realtime;
! static void realtime_bang(t_realtime *x) ! { x->x_setrealtime = sys_getrealtime(); }
! static void realtime_bang2(t_realtime *x) ! { ! outlet_float(x->x_obj.ob_outlet, ! (sys_getrealtime() - x->x_setrealtime) * 1000.); }
! static void *realtime_new(void) ! { t_realtime *x = (t_realtime *)pd_new(realtime_class); ! outlet_new(&x->x_obj, gensym("float")); ! inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("bang"), gensym("bang2")); realtime_bang(x); ! return (x); }
! static void realtime_setup(void) ! { ! realtime_class = class_new(gensym("realtime"), (t_newmethod)realtime_new, 0, ! sizeof(t_realtime), 0, 0); class_addbang(realtime_class, realtime_bang); ! class_addmethod(realtime_class, (t_method)realtime_bang2, gensym("bang2"), ! 0); }
--- 193,220 ---- static t_class *realtime_class;
! struct t_realtime : t_object { double x_setrealtime; ! };
! static void realtime_bang(t_realtime *x) { x->x_setrealtime = sys_getrealtime(); }
! static void realtime_bang2(t_realtime *x) { ! outlet_float(x->ob_outlet, (sys_getrealtime() - x->x_setrealtime) * 1000.); }
! static void *realtime_new() { t_realtime *x = (t_realtime *)pd_new(realtime_class); ! outlet_new(x,gensym("float")); ! inlet_new(x,x,gensym("bang"),gensym("bang2")); realtime_bang(x); ! return x; }
! static void realtime_setup() { ! realtime_class = class_new(gensym("realtime"), (t_newmethod)realtime_new, 0, sizeof(t_realtime), 0, 0); class_addbang(realtime_class, realtime_bang); ! class_addmethod(realtime_class, (t_method)realtime_bang2, gensym("bang2"), 0); }
*************** *** 314,358 **** static t_class *print_class;
! typedef struct _print ! { ! t_object x_obj; t_symbol *x_sym; ! } t_print;
! static void *print_new(t_symbol *s) ! { t_print *x = (t_print *)pd_new(print_class); if (*s->s_name) x->x_sym = s; else x->x_sym = gensym("print"); ! return (x); }
static void print_bang(t_print *x) ! { ! post("%s: bang", x->x_sym->s_name); ! } ! static void print_pointer(t_print *x, t_gpointer *gp) ! { ! post("%s: (gpointer)", x->x_sym->s_name); ! } ! static void print_float(t_print *x, t_float f) ! { ! post("%s: %g", x->x_sym->s_name, f); ! }
! static void print_list(t_print *x, t_symbol *s, int argc, t_atom *argv) ! { if (argc && argv->a_type != A_SYMBOL) startpost("%s:", x->x_sym->s_name); else startpost("%s: %s", x->x_sym->s_name, ! (argc > 1 ? s_list.s_name : (argc == 1 ? s_symbol.s_name : ! s_bang.s_name))); postatom(argc, argv); endpost(); }
! static void print_anything(t_print *x, t_symbol *s, int argc, t_atom *argv) ! { startpost("%s: %s", x->x_sym->s_name, s->s_name); postatom(argc, argv); --- 222,252 ---- static t_class *print_class;
! struct t_print : t_object { t_symbol *x_sym; ! };
! static void *print_new(t_symbol *s) { t_print *x = (t_print *)pd_new(print_class); if (*s->s_name) x->x_sym = s; else x->x_sym = gensym("print"); ! return x; }
static void print_bang(t_print *x) ! {post("%s: bang", x->x_sym->s_name);} static void print_pointer(t_print *x, t_gpointer *gp) ! {post("%s: (gpointer)", x->x_sym->s_name);} static void print_float(t_print *x, t_float f) ! {post("%s: %g", x->x_sym->s_name, f);}
! static void print_list(t_print *x, t_symbol *s, int argc, t_atom *argv) { if (argc && argv->a_type != A_SYMBOL) startpost("%s:", x->x_sym->s_name); else startpost("%s: %s", x->x_sym->s_name, ! (argc>1 ? s_list : argc==1 ? s_symbol : s_bang).s_name); postatom(argc, argv); endpost(); }
! static void print_anything(t_print *x, t_symbol *s, int argc, t_atom *argv) { startpost("%s: %s", x->x_sym->s_name, s->s_name); postatom(argc, argv); *************** *** 360,367 **** }
! static void print_setup(void) ! { ! print_class = class_new(gensym("print"), (t_newmethod)print_new, 0, ! sizeof(t_print), 0, A_DEFSYM, 0); class_addbang(print_class, print_bang); class_addfloat(print_class, print_float); --- 254,259 ---- }
! static void print_setup() { ! print_class = class_new(gensym("print"), (t_newmethod)print_new, 0, sizeof(t_print), 0, A_DEFSYM, 0); class_addbang(print_class, print_bang); class_addfloat(print_class, print_float); *************** *** 371,381 **** }
! ! void x_misc_setup(void) ! { random_setup(); loadbang_setup(); namecanvas_setup(); - serial_setup(); cputime_setup(); realtime_setup(); --- 263,270 ---- }
! void x_misc_setup() { random_setup(); loadbang_setup(); namecanvas_setup(); cputime_setup(); realtime_setup();