aboutsummaryrefslogtreecommitdiff
path: root/externals
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-12-13 01:37:22 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-12-13 01:37:22 +0000
commit93f64df7a4eee1151d2b70d37ab17f04e58cbc46 (patch)
tree275653dac43fe83c86e31c47c5c5431bdde1cb7a /externals
parenta7af081228de119a07bc18bcb35f0bbf567f9dd8 (diff)
refactored x_misc.c into cputime.c loadband.c namecanvas.c realtime.c random.c
svn path=/trunk/; revision=14600
Diffstat (limited to 'externals')
-rw-r--r--externals/vanilla/Makefile2
-rw-r--r--externals/vanilla/TODO2
-rw-r--r--externals/vanilla/cputime.c114
-rw-r--r--externals/vanilla/lib_x_misc.c5
-rw-r--r--externals/vanilla/loadbang.c50
-rw-r--r--externals/vanilla/namecanvas.c52
-rw-r--r--externals/vanilla/random.c75
-rw-r--r--externals/vanilla/realtime.c69
8 files changed, 363 insertions, 6 deletions
diff --git a/externals/vanilla/Makefile b/externals/vanilla/Makefile
index 010d6a66..cfac6cbc 100644
--- a/externals/vanilla/Makefile
+++ b/externals/vanilla/Makefile
@@ -5,7 +5,7 @@ LIBRARY_NAME = vanilla
# add your .c source files, one object per file, to the SOURCES
# variable, help files will be included automatically
-SOURCES = abs~.c bng.c clip~.c cnv.c dbtopow~.c dbtorms~.c del.c delay.c exp~.c ftom~.c hradio.c hsl.c hslider.c key.c keyname.c keyup.c line.c list.c log~.c metro.c mtof~.c my_canvas.c my_numbox.c nbx.c netsend.c netreceive.c openpanel.c pipe.c powtodb~.c pow~.c print.c qlist.c radiobut.c radiobutton.c rdb.c rmstodb~.c rsqrt~.c savepanel.c sqrt~.c textfile.c tgl.c timer.c toggle.c vradio.c vsl.c vslider.c vu.c wrap~.c
+SOURCES = abs~.c bng.c clip~.c cnv.c dbtopow~.c dbtorms~.c del.c delay.c exp~.c ftom~.c hradio.c hsl.c hslider.c key.c keyname.c keyup.c line.c list.c log~.c metro.c mtof~.c my_canvas.c my_numbox.c nbx.c netsend.c netreceive.c openpanel.c pipe.c powtodb~.c pow~.c print.c qlist.c radiobut.c radiobutton.c rdb.c rmstodb~.c rsqrt~.c savepanel.c sqrt~.c textfile.c tgl.c timer.c toggle.c vradio.c vsl.c vslider.c vu.c wrap~.c random.c loadbang.c namecanvas.c cputime.c realtime.c
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
diff --git a/externals/vanilla/TODO b/externals/vanilla/TODO
index 724c6f1b..f9a86be5 100644
--- a/externals/vanilla/TODO
+++ b/externals/vanilla/TODO
@@ -13,3 +13,5 @@
- move relevent help patches from doc/pddp to here
- fix objects so if instantiated with vanilla/bng they retain the namespace prefix
+
+- x_midi.c is very intertwined with s_midi.c
diff --git a/externals/vanilla/cputime.c b/externals/vanilla/cputime.c
new file mode 100644
index 00000000..ba81b40d
--- /dev/null
+++ b/externals/vanilla/cputime.c
@@ -0,0 +1,114 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* misc. */
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef UNISTD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <wtypes.h>
+#include <time.h>
+#endif
+
+#if defined (__APPLE__) || defined (__FreeBSD__)
+#define CLOCKHZ CLK_TCK
+#endif
+#if defined (__linux__)
+#define CLOCKHZ sysconf(_SC_CLK_TCK)
+#endif
+
+static t_class *cputime_class;
+
+typedef struct _cputime
+{
+ t_object x_obj;
+#ifdef UNISTD
+ struct tms x_setcputime;
+#endif
+#ifdef MSW
+ LARGE_INTEGER x_kerneltime;
+ LARGE_INTEGER x_usertime;
+ int x_warned;
+#endif
+} t_cputime;
+
+static void cputime_bang(t_cputime *x)
+{
+#ifdef UNISTD
+ times(&x->x_setcputime);
+#endif
+#ifdef MSW
+ FILETIME ignorethis, ignorethat;
+ BOOL retval;
+ 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;
+ x->x_usertime.QuadPart = 0;
+ }
+#endif
+}
+
+static void cputime_bang2(t_cputime *x)
+{
+#ifdef UNISTD
+ t_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) / CLOCKHZ;
+ outlet_float(x->x_obj.ob_outlet, elapsedcpu);
+#endif
+#ifdef MSW
+ t_float elapsedcpu;
+ FILETIME ignorethis, ignorethat;
+ LARGE_INTEGER usertime, kerneltime;
+ BOOL retval;
+
+ retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat,
+ (FILETIME *)&kerneltime, (FILETIME *)&usertime);
+ if (retval)
+ elapsedcpu = 0.0001 *
+ ((kerneltime.QuadPart - x->x_kerneltime.QuadPart) +
+ (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);
+}
diff --git a/externals/vanilla/lib_x_misc.c b/externals/vanilla/lib_x_misc.c
deleted file mode 100644
index 6db34248..00000000
--- a/externals/vanilla/lib_x_misc.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "../../pd/src/x_misc.c"
-void lib_x_misc_setup(void)
-{
- x_misc_setup();
-}
diff --git a/externals/vanilla/loadbang.c b/externals/vanilla/loadbang.c
new file mode 100644
index 00000000..d6392beb
--- /dev/null
+++ b/externals/vanilla/loadbang.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* misc. */
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef UNISTD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <wtypes.h>
+#include <time.h>
+#endif
+
+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);
+}
diff --git a/externals/vanilla/namecanvas.c b/externals/vanilla/namecanvas.c
new file mode 100644
index 00000000..a6642dae
--- /dev/null
+++ b/externals/vanilla/namecanvas.c
@@ -0,0 +1,52 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* misc. */
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef UNISTD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <wtypes.h>
+#include <time.h>
+#endif
+
+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,
+ sizeof(t_namecanvas), CLASS_NOINLET, A_DEFSYM, 0);
+}
diff --git a/externals/vanilla/random.c b/externals/vanilla/random.c
new file mode 100644
index 00000000..67e4cf35
--- /dev/null
+++ b/externals/vanilla/random.c
@@ -0,0 +1,75 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* misc. */
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef UNISTD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <wtypes.h>
+#include <time.h>
+#endif
+
+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;
+ return (random_nextseed & 0x7fffffff);
+}
+
+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, t_float f, t_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);
+}
diff --git a/externals/vanilla/realtime.c b/externals/vanilla/realtime.c
new file mode 100644
index 00000000..3621f120
--- /dev/null
+++ b/externals/vanilla/realtime.c
@@ -0,0 +1,69 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* misc. */
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef UNISTD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <wtypes.h>
+#include <time.h>
+#endif
+
+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);
+}
+
+void x_misc_setup(void)
+{
+ random_setup();
+ loadbang_setup();
+ namecanvas_setup();
+ serial_setup();
+ cputime_setup();
+ realtime_setup();
+}